From 70fb19bc8ca829346f8db665d16d5fe93694c77d Mon Sep 17 00:00:00 2001 From: Eddie Webb Date: Sat, 14 Jan 2017 08:47:50 -0500 Subject: [PATCH] Adds actual build status from docker hub as discussedin issue #241 --- server.js | 39 +++++++++++++++++++++++++++++++++++++++ try.html | 4 ++++ 2 files changed, 43 insertions(+) diff --git a/server.js b/server.js index e5c4e47279539..fb705f544dc3e 100644 --- a/server.js +++ b/server.js @@ -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) { diff --git a/try.html b/try.html index f4c6c875e7d82..82ad582a1f395 100644 --- a/try.html +++ b/try.html @@ -830,6 +830,10 @@

Miscellaneous

https://img.shields.io/docker/automated/jrottenberg/ffmpeg.svg + Docker Build Status + + https://img.shields.io/docker/status/jrottenberg/ffmpeg.svg + ImageLayers Size: https://img.shields.io/imagelayers/image-size/_/ubuntu/latest.svg