Skip to content

Commit

Permalink
Adds actual build status from docker hub as discussedin issue badges#241
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiewebb committed Jan 14, 2017
1 parent 21ae49a commit 70fb19b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
39 changes: 39 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4960,6 +4960,45 @@ cache(function(data, match, sendBadge, request) {
});
}));

// Docker Hub automated integration, latest status (passed, pending, failed)
camp.route(/^\/docker\/status\/([^\/]+)\/([^\/]+)\.(svg|png|gif|jpg|json)$/,
cache(function(data, match, sendBadge, request) {
var user = match[1]; // eg, jrottenberg
var repo = match[2]; // eg, ffmpeg
var format = match[3];
if (user === '_') {
user = 'library';
}
var path = user + '/' + repo;
var url = 'https://registry.hub.docker.com/v2/repositories/' + path + '/buildhistory';
var badgeData = getBadgeData('docker status', data);
request(url, function(err, res, buffer) {
if (err != null) {
badgeData.text[1] = 'inaccessible';
sendBadge(format, badgeData);
return;
}
try {
var data = JSON.parse(buffer);
var latest_status = data.results[0].status;
if ( latest_status == 10 ) {
badgeData.text[1] = 'passed';
badgeData.colorscheme = 'brightgreen';
} else if ( latest_status < 0 ) {
badgeData.text[1] = 'failed';
badgeData.colorscheme = 'red';
} else {
badgeData.text[1] = 'building..';
badgeData.colorB = '#008bb8';
}
sendBadge(format, badgeData);
} catch(e) {
badgeData.text[1] = 'invalid';
sendBadge(format, badgeData);
}
});
}));

// Twitter integration.
camp.route(/^\/twitter\/url\/([^\/]+)\/(.+)\.(svg|png|gif|jpg|json)$/,
cache(function(data, match, sendBadge, request) {
Expand Down
4 changes: 4 additions & 0 deletions try.html
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,10 @@ <h3 id="miscellaneous"> Miscellaneous </h3>
<td><img src='/docker/automated/jrottenberg/ffmpeg.svg' alt=''/></td>
<td><code>https://img.shields.io/docker/automated/jrottenberg/ffmpeg.svg</code></td>
</tr>
<tr><th data-keywords='docker build status'> Docker Build Status </th>
<td><img src='/docker/status/jrottenberg/ffmpeg.svg' alt=''/></td>
<td><code>https://img.shields.io/docker/status/jrottenberg/ffmpeg.svg</code></td>
</tr>
<tr><th data-keywords='imagelayers'> ImageLayers Size: </th>
<td><img src='/imagelayers/image-size/_/ubuntu/latest.svg' alt=''/></td>
<td><code>https://img.shields.io/imagelayers/image-size/_/ubuntu/latest.svg</code></td>
Expand Down

0 comments on commit 70fb19b

Please sign in to comment.