From abcd9d6decc44ee3681829817446870d1a680ee9 Mon Sep 17 00:00:00 2001 From: Carlos Perez Date: Fri, 18 Dec 2015 13:21:09 -0500 Subject: [PATCH 1/3] Add bitHound integration. --- logo/bithound.svg | 1 + server.js | 29 +++++++++++++++++++++++++++++ try.html | 12 ++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 logo/bithound.svg diff --git a/logo/bithound.svg b/logo/bithound.svg new file mode 100644 index 0000000..7fb554d --- /dev/null +++ b/logo/bithound.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/server.js b/server.js index e073a04..7283851 100644 --- a/server.js +++ b/server.js @@ -4673,6 +4673,35 @@ cache(function(data, match, sendBadge, request) { })} )); +// bitHound integration +camp.route(/^\/bithound\/(code\/|dependencies\/|devDependencies\/)?(.+?)\.(svg|png|gif|jpg|json)$/, +cache(function(data, match, sendBadge, request) { + var type = match[1]; + var userRepo = match[2]; // eg, `github/rexxars/sse-channel`. + var format = match[3]; + var url = 'https://www.bithound.io/api/' + userRepo + '/badge/' + type; + var badgeData = getBadgeData(type === 'devDependencies' ? 'dev dependencies' : type, data); + + request(url, function(err, res) { + if (err != null) { + badgeData.text[1] = 'inaccessible'; + sendBadge(format, badgeData); + return; + } + try { + badgeData.text[1] = res.label; + badgeData.logo = logos['bithound']; + badgeData.logoWidth = 15; + badgeData.colorscheme = res.color; + 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) { diff --git a/try.html b/try.html index 4015452..4365c11 100644 --- a/try.html +++ b/try.html @@ -558,6 +558,10 @@ Pixel-perfect   Retina-ready   Fast   Consistent   Hackable https://img.shields.io/codeclimate/coverage/github/triAGENS/ashikawa-core.svg + bitHound Code: + + https://img.shields.io/bithound/code/github/rexxars/sse-channel.svg + Gemnasium: https://img.shields.io/gemnasium/mathiasbynens/he.svg @@ -746,6 +750,14 @@ Pixel-perfect   Retina-ready   Fast   Consistent   Hackable https://img.shields.io/david/peer/webcomponents/generator-element.svg + bitHound: + + https://img.shields.io/bithound/dependencies/github/rexxars/sse-channel.svg + + bitHound: + + https://img.shields.io/bithound/devDependencies/github/rexxars/sse-channel.svg + CocoaPods: https://img.shields.io/cocoapods/p/AFNetworking.svg From 40740b925ac07997791c04f0f561a95f1a21c8bc Mon Sep 17 00:00:00 2001 From: Carlos Perez Date: Fri, 18 Dec 2015 21:10:19 -0600 Subject: [PATCH 2/3] Proper handling of request to bithound badge api. --- server.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/server.js b/server.js index 7283851..fdd36e1 100644 --- a/server.js +++ b/server.js @@ -4676,23 +4676,20 @@ cache(function(data, match, sendBadge, request) { // bitHound integration camp.route(/^\/bithound\/(code\/|dependencies\/|devDependencies\/)?(.+?)\.(svg|png|gif|jpg|json)$/, cache(function(data, match, sendBadge, request) { - var type = match[1]; + var type = match[1].slice(0, -1); var userRepo = match[2]; // eg, `github/rexxars/sse-channel`. var format = match[3]; - var url = 'https://www.bithound.io/api/' + userRepo + '/badge/' + type; + var apiUrl = 'https://www.bithound.io/api/' + userRepo + '/badge/' + type; var badgeData = getBadgeData(type === 'devDependencies' ? 'dev dependencies' : type, data); - request(url, function(err, res) { - if (err != null) { - badgeData.text[1] = 'inaccessible'; - sendBadge(format, badgeData); - return; - } + request(apiUrl, { headers: { 'Accept': 'application/json' } }, function(err, res, buffer) { try { - badgeData.text[1] = res.label; + var data = JSON.parse(buffer); + badgeData.text[1] = data.label; badgeData.logo = logos['bithound']; badgeData.logoWidth = 15; - badgeData.colorscheme = res.color; + badgeData.colorscheme = null; + badgeData.colorB = '#' + data.color; sendBadge(format, badgeData); } catch(e) { From 33e56749c0be50e6c4d3d792955a883412aab2ba Mon Sep 17 00:00:00 2001 From: Carlos Perez Date: Fri, 18 Dec 2015 21:11:54 -0600 Subject: [PATCH 3/3] Simplify name of bitHound label on examples. --- try.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/try.html b/try.html index 4365c11..b620068 100644 --- a/try.html +++ b/try.html @@ -558,7 +558,7 @@ Pixel-perfect   Retina-ready   Fast   Consistent   Hackable https://img.shields.io/codeclimate/coverage/github/triAGENS/ashikawa-core.svg - bitHound Code: + bitHound: https://img.shields.io/bithound/code/github/rexxars/sse-channel.svg