Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds actual build status from docker hub as discussed in issue #241 #856

Merged
merged 7 commits into from
Apr 7, 2017
44 changes: 44 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5101,6 +5101,50 @@ cache(function(data, match, sendBadge, request) {
});
}));

// Docker Hub automated integration, latest status (passed, pending, failed)
camp.route(/^\/docker\/build\/([^\/]+)\/([^\/]+)\.(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 build', data);
request(url, function(err, res, buffer) {
if (err != null) {
badgeData.text[1] = 'inaccessible';
sendBadge(format, badgeData);
return;
}
try {
if (res.statusCode == 404) {
badgeData.text[1] = 'repo not found';
sendBadge(format, badgeData);
return;
}
var data = JSON.parse(buffer);
var latest_status = data.results[0].status;
if (latest_status == 10) {
badgeData.text[1] = 'passing';
badgeData.colorscheme = 'brightgreen';
} else if (latest_status < 0) {
badgeData.text[1] = 'failing';
badgeData.colorscheme = 'red';
} else {
badgeData.text[1] = 'building';
badgeData.colorB = '#008bb8';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that color!

}
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 @@ -855,6 +855,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/build/jrottenberg/ffmpeg.svg' alt=''/></td>
<td><code>https://img.shields.io/docker/build/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