Add GitHub issues badge
This commit is contained in:
parent
f77c8cdc6b
commit
97e7853d6a
37
server.js
37
server.js
|
@ -1006,6 +1006,43 @@ cache(function(data, match, sendBadge) {
|
|||
});
|
||||
}));
|
||||
|
||||
// GitHub release integration.
|
||||
camp.route(/^\/github\/issues\/(.*)\/(.*)\.(svg|png|gif|jpg)$/,
|
||||
cache(function(data, match, sendBadge) {
|
||||
var user = match[1]; // eg, qubyte/rubidium
|
||||
var repo = match[2];
|
||||
var format = match[3];
|
||||
var apiUrl = 'https://api.github.com/repos/' + user + '/' + repo + '';
|
||||
// Using our OAuth App secret grants us 5000 req/hour
|
||||
// instead of the standard 60 req/hour.
|
||||
if (serverSecrets) {
|
||||
apiUrl += '?client_id=' + serverSecrets.gh_client_id
|
||||
+ '&client_secret=' + serverSecrets.gh_client_secret;
|
||||
}
|
||||
var badgeData = getBadgeData('issues', data);
|
||||
// A special User-Agent is required:
|
||||
// http://developer.github.com/v3/#user-agent-required
|
||||
request(apiUrl, { headers: { 'User-Agent': 'Shields.io' } }, function(err, res, buffer) {
|
||||
if (err != null) {
|
||||
badgeData.text[1] = 'inaccessible';
|
||||
sendBadge(format, badgeData);
|
||||
}
|
||||
try {
|
||||
if ((+res.headers['x-ratelimit-remaining']) === 0) {
|
||||
return; // Hope for the best in the cache.
|
||||
}
|
||||
var data = JSON.parse(buffer);
|
||||
var issues = data.open_issues_count;
|
||||
badgeData.text[1] = issues + ' open';
|
||||
badgeData.colorscheme = issues ? 'yellow' : 'brightgreen';
|
||||
sendBadge(format, badgeData);
|
||||
} catch(e) {
|
||||
badgeData.text[1] = 'invalid';
|
||||
sendBadge(format, badgeData);
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
// Chef cookbook integration.
|
||||
camp.route(/^\/cookbook\/v\/(.*)\.(svg|png|gif|jpg)$/,
|
||||
cache(function(data, match, sendBadge) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user