Permalink
Browse files

Change feed status handling to check for latest status of all jobs in…

… the feed. #14
  • Loading branch information...
1 parent 2d3617b commit 8ec495b1e082db89f81aeb3fe99d1b6e7c1d0eb3 @cliffano committed May 9, 2013
Showing with 69 additions and 3 deletions.
  1. +1 −0 CHANGELOG.md
  2. +28 −1 lib/jenkins.js
  3. +40 −2 test/jenkins.js
View
@@ -2,6 +2,7 @@
* Change buildlight status colour mapping, unknown displays blue, warn displays all colours to simulate yellow
* Add view monitoring support
* Change feed jobName and viewName passing to use flags instead of args
+* Change feed status handling to check for latest status of all jobs in the feed
### 0.1.4
* Add buildlight command
View
@@ -390,7 +390,7 @@ Jenkins.prototype.monitor = function (opts, cb) {
function _notify() {
self.feed(opts, function (err, result) {
- cb(err, !_.isEmpty(result) ? self._titleStatus(result[0].title) : null);
+ cb(err, self._feedStatus(result));
});
}
@@ -416,6 +416,33 @@ Jenkins.prototype._colorStatus = function (color) {
return (STATUS[color]) || color.toUpperCase();
};
+Jenkins.prototype._feedStatus = function (feed) {
+ const STATUS = ['FAIL', 'WARN', 'ABORTED', 'OK'];
+ var feedStatus = null,
+ self = this;
+
+ // check for the latest status of all jobs
+ // any non-OK status will be used as feed status in STATUS const order
+ if (!_.isEmpty(feed)) {
+ var titlesStatus = {};
+ feed.forEach(function (result) {
+ var jobName = result.title.split(' #')[0];
+ if (!titlesStatus[jobName]) {
+ titlesStatus[jobName] = self._titleStatus(result.title);
+ }
+ });
+ var uniq = _.uniq(_.values(titlesStatus));
+ for (var i = 0, ln = STATUS.length; i < ln; i += 1) {
+ if (uniq.indexOf(STATUS[i]) !== -1) {
+ feedStatus = STATUS[i];
+ break;
+ }
+ }
+ }
+
+ return feedStatus;
+};
+
Jenkins.prototype._titleStatus = function (title) {
title = String(title.match('[(].+[)]$')).replace(/[(]/, '').replace(/[)]/, '').toLowerCase();
View
@@ -708,11 +708,11 @@ buster.testCase('jenkins - monitor', {
var jenkins = new Jenkins('http://localhost:8080');
jenkins.feed = function (opts, cb) {
assert.equals(opts.jobName, 'somejob');
- cb(null, [{ title: 'somejob 1 (stable)' }, { title: 'somejob 2 (aborted)' }]);
+ cb(null, [{ title: 'somejob 1 #100 (stable)' }, { title: 'somejob 2 #100 (aborted)' }]);
};
jenkins.monitor({ jobName: 'somejob', schedule: '*/30 * * * * *' }, function (err, result) {
assert.isNull(err);
- assert.equals(result, 'OK');
+ assert.equals(result, 'ABORTED');
});
},
'should call notify callback when there is no article but there is no monitoring error as well': function (done) {
@@ -764,6 +764,44 @@ buster.testCase('jenkins - _colorStatus', {
}
});
+buster.testCase('jenkins - _feedStatus', {
+ setUp: function () {
+ this.jenkins = new Jenkins();
+ },
+ 'should return ok status when there is a fail but not on the latest build on any of the jobs': function () {
+ var feed = [
+ { title: 'somejob1 #123 (back to normal)' },
+ { title: 'somejob2 #333 (stable)' },
+ { title: 'somejob1 #122 (broken for a long time)' }
+ ];
+ assert.equals(this.jenkins._feedStatus(feed), 'OK');
+ },
+ 'should return fail status when there is a fail on the latest build of one of the jobs': function () {
+ var feed = [
+ { title: 'somejob1 #123 (broken since this build)' },
+ { title: 'somejob2 #333 (stable)' },
+ { title: 'somejob1 #122 (stable)' }
+ ];
+ assert.equals(this.jenkins._feedStatus(feed), 'FAIL');
+ },
+ 'should return warn status when there is a warn on the latest build of one of the jobs but there is no fail': function () {
+ var feed = [
+ { title: 'somejob1 #123 (23 tests are still failing)' },
+ { title: 'somejob2 #333 (stable)' },
+ { title: 'somejob1 #122 (11 tests are still failing)' }
+ ];
+ assert.equals(this.jenkins._feedStatus(feed), 'WARN');
+ },
+ 'should return null status when latest build status of all jobs are neither ok, fail, or warn': function () {
+ var feed = [
+ { title: 'somejob1 #123 (foobar)' },
+ { title: 'somejob2 #333 (foobar)' },
+ { title: 'somejob1 #122 (foobar)' }
+ ];
+ assert.isNull(this.jenkins._feedStatus(feed));
+ }
+});
+
buster.testCase('jenkins - _titleStatus', {
'should show correct status based on title info': function () {
var jenkins = new Jenkins();

0 comments on commit 8ec495b

Please sign in to comment.