Skip to content

Commit

Permalink
Wercker: try / catch and URL change to /wercker/ci/
Browse files Browse the repository at this point in the history
Closes #290 and closes #265.
  • Loading branch information
espadrine committed Oct 26, 2014
1 parent a63c366 commit 66ad367
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 36 deletions.
78 changes: 44 additions & 34 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,39 +277,44 @@ cache(function(data, match, sendBadge, request) {
branch = branch || 'master';
var badgeData = getBadgeData('build', data);
request(options, function(err, res, json) {
if (err != null || json == null
|| (json.length !== undefined && json.length === 0)) {
if (err != null) {
badgeData.text[1] = 'inaccessible';
sendBadge(format, badgeData);
return;
}
// Find the latest push on this branch.
var build = null;
for (var i = 0; i < json.length; i++) {
if (json[i].state === 'finished' && json[i].event_type === 'push'
&& json[i].branch === branch) {
build = json[i];
break;
try {
// Find the latest push on this branch.
var build = null;
for (var i = 0; i < json.length; i++) {
if (json[i].state === 'finished' && json[i].event_type === 'push'
&& json[i].branch === branch) {
build = json[i];
break;
}
}
badgeData.text[1] = 'pending';
if (build === null) {
sendBadge(format, badgeData);
return;
}
if (build.result === 0) {
badgeData.colorscheme = 'brightgreen';
badgeData.text[1] = 'passing';
} else if (build.result === 1) {
badgeData.colorscheme = 'red';
badgeData.text[1] = 'failing';
}
}
badgeData.text[1] = 'pending';
if (build === null) {
sendBadge(format, badgeData);
return;
}
if (build.result === 0) {
badgeData.colorscheme = 'brightgreen';
badgeData.text[1] = 'passing';
} else if (build.result === 1) {
badgeData.colorscheme = 'red';
badgeData.text[1] = 'failing';

} catch(e) {
badgeData.text[1] = 'invalid';
sendBadge(format, badgeData);
}
sendBadge(format, badgeData);
});
}));

// Wercker integration
camp.route(/^\/wercker\/(.+)\.(svg|png|gif|jpg|json)$/,
camp.route(/^\/wercker\/ci\/(.+)\.(svg|png|gif|jpg|json)$/,
cache(function(data, match, sendBadge, request) {
var projectId = match[1]; // eg, `54330318b4ce963d50020750`
var format = match[2];
Expand All @@ -320,26 +325,31 @@ cache(function(data, match, sendBadge, request) {
};
var badgeData = getBadgeData('build', data);
request(options, function(err, res, json) {
if (err != null || json == null
|| (json.length !== undefined && json.length === 0)) {
if (err != null) {
badgeData.text[1] = 'inaccessible';
sendBadge(format, badgeData);
return;
}
var build = json[0];
try {
var build = json[0];

if (build.status === 'finished') {
if (build.result === 'passed') {
badgeData.colorscheme = 'brightgreen';
badgeData.text[1] = build.result;
if (build.status === 'finished') {
if (build.result === 'passed') {
badgeData.colorscheme = 'brightgreen';
badgeData.text[1] = build.result;
} else {
badgeData.colorscheme = 'red';
badgeData.text[1] = build.result;
}
} else {
badgeData.colorscheme = 'red';
badgeData.text[1] = build.result;
badgeData.text[1] = build.status;
}
} else {
badgeData.text[1] = build.status;
sendBadge(format, badgeData);

} catch(e) {
badgeData.text[1] = 'invalid';
sendBadge(format, badgeData);
}
sendBadge(format, badgeData);
});
}));

Expand Down
4 changes: 2 additions & 2 deletions try.html
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ <h3> Build </h3>
<td><code>http://img.shields.io/travis/joyent/node/v0.6.svg</code></td>
</tr>
<tr><th> Wercker: </th>
<td><img src='/wercker/54330318b4ce963d50020750.svg' alt=''/></td>
<td><code>http://img.shields.io/wercker/54330318b4ce963d50020750.svg</code></td>
<td><img src='/wercker/ci/54330318b4ce963d50020750.svg' alt=''/></td>
<td><code>http://img.shields.io/wercker/ci/54330318b4ce963d50020750.svg</code></td>
</tr>
<tr><th> TeamCity CodeBetter: </th>
<td><img src='/teamcity/codebetter/bt428.svg' alt=''/></td>
Expand Down

0 comments on commit 66ad367

Please sign in to comment.