diff --git a/server.js b/server.js index e27c7c1f9ec0c..7f69581f91134 100644 --- a/server.js +++ b/server.js @@ -3984,6 +3984,39 @@ cache(function(data, match, sendBadge, request) { }); })); +// Snap CI build integration. +// https://snap-ci.com/snap-ci/snap-deploy/branch/master/build_image +camp.route(/^\/snap(-ci?)\/([^\/]+\/[^\/]+)(?:\/(.+))\.(svg|png|gif|jpg|json)$/, +cache(function(data, match, sendBadge, request) { + var userRepo = match[2]; + var branch = match[3]; + var format = match[4]; + var url = 'https://snap-ci.com/' + userRepo + '/branch/' + branch + '/build_image.svg'; + + var badgeData = getBadgeData('build', data); + fetchFromSvg(request, url, function(err, res) { + if (err != null) { + badgeData.text[1] = 'inaccessible'; + sendBadge(format, badgeData); + return; + } + try { + badgeData.text[1] = res.toLowerCase(); + if (res === 'Passed') { + badgeData.colorscheme = 'brightgreen'; + } else if (res === 'Failed') { + badgeData.colorscheme = 'red'; + } + sendBadge(format, badgeData); + + } catch(e) { + badgeData.text[1] = 'invalid'; + sendBadge(format, badgeData); + } + }); +})); + + // Any badge. camp.route(/^\/(:|badge\/)(([^-]|--)*?)-(([^-]|--)*)-(([^-]|--)+)\.(svg|png|gif|jpg)$/, function(data, match, end, ask) { @@ -4195,7 +4228,7 @@ function fetchFromSvg(request, url, cb) { request(url, function(err, res, buffer) { if (err != null) { return cb(err); } try { - var badge = buffer.replace(/(?:\r\n\s|\r\s|\n\s)/g, ''); + var badge = buffer.replace(/(?:\r\n\s*|\r\s*|\n\s*)/g, ''); var match = />([^<>]+)<\/text><\/g>/.exec(badge); cb(null, match[1]); } catch(e) { diff --git a/try.html b/try.html index 01d08ffecf092..02545a0b11b59 100644 --- a/try.html +++ b/try.html @@ -124,6 +124,10 @@

Build

https://img.shields.io/shippable/54d119db5ab6cc13528ab183/master.svg + Snap CI branch: + + https://img.shields.io/snap-ci/ThoughtWorksStudios/eb_deployer/master.svg + Jenkins: https://img.shields.io/jenkins/s/https/jenkins.qa.ubuntu.com/precise-desktop-amd64_default.svg