add GitHub contributors integration
This commit is contained in:
parent
2d3f21624d
commit
04d24f6c62
|
@ -715,6 +715,10 @@ Pixel-perfect Retina-ready Fast Consistent Hackable
|
|||
<td><img src='https://img.shields.io/github/issues-pr-raw/cdnjs/cdnjs.svg' alt=''/></td>
|
||||
<td><code>https://img.shields.io/github/issues-pr-raw/cdnjs/cdnjs.svg</code></td>
|
||||
</tr>
|
||||
<tr><th data-keywords='GitHub contributor' data-doc='githubDoc'> GitHub contributors: </th>
|
||||
<td><img src='https://img.shields.io/github/contributors/cdnjs/cdnjs.svg' alt=''/></td>
|
||||
<td><code>https://img.shields.io/github/contributors/cdnjs/cdnjs.svg</code></td>
|
||||
</tr>
|
||||
<tr><th data-keywords='GitHub license' data-doc='githubDoc'> license: </th>
|
||||
<td><img src='https://img.shields.io/github/license/mashape/apistatus.svg?maxAge=2592000' alt=''/></td>
|
||||
<td><code>https://img.shields.io/github/license/mashape/apistatus.svg</code></td>
|
||||
|
|
29
server.js
29
server.js
|
@ -2832,6 +2832,35 @@ cache(function(data, match, sendBadge, request) {
|
|||
});
|
||||
}));
|
||||
|
||||
// GitHub contributors integration.
|
||||
camp.route(/^\/github\/contributors(-anon)?\/([^\/]+)\/([^\/]+)\.(svg|png|gif|jpg|json)$/,
|
||||
cache(function(data, match, sendBadge, request) {
|
||||
var isAnon = match[1];
|
||||
var user = match[2]; // eg, qubyte/rubidium
|
||||
var repo = match[3];
|
||||
var format = match[4];
|
||||
var apiUrl = 'https://api.github.com/repos/' + user + '/' + repo + '/contributors?page=1&per_page=1&anon=' + (0+isAnon);
|
||||
var badgeData = getBadgeData('contributors', data);
|
||||
if (badgeData.template === 'social') {
|
||||
badgeData.logo = badgeData.logo || logos.github;
|
||||
}
|
||||
githubAuth.request(request, apiUrl, {}, function(err, res, buffer) {
|
||||
if (err != null) {
|
||||
badgeData.text[1] = 'inaccessible';
|
||||
sendBadge(format, badgeData);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
var data = JSON.parse(buffer);
|
||||
badgeData.text[1] = metric(data[0].contributions);
|
||||
badgeData.colorscheme = 'blue';
|
||||
} catch(e) {
|
||||
badgeData.text[1] = 'inaccessible';
|
||||
}
|
||||
sendBadge(format, badgeData);
|
||||
});
|
||||
}));
|
||||
|
||||
// GitHub release integration.
|
||||
camp.route(/^\/github\/release\/([^\/]+)\/([^\/]+)\.(svg|png|gif|jpg|json)$/,
|
||||
cache(function(data, match, sendBadge, request) {
|
||||
|
|
4
try.html
4
try.html
|
@ -714,6 +714,10 @@ Pixel-perfect Retina-ready Fast Consistent Hackable
|
|||
<td><img src='/github/issues-pr-raw/cdnjs/cdnjs.svg' alt=''/></td>
|
||||
<td><code>https://img.shields.io/github/issues-pr-raw/cdnjs/cdnjs.svg</code></td>
|
||||
</tr>
|
||||
<tr><th data-keywords='GitHub contributor' data-doc='githubDoc'> GitHub contributors: </th>
|
||||
<td><img src='/github/contributors/cdnjs/cdnjs.svg' alt=''/></td>
|
||||
<td><code>https://img.shields.io/github/contributors/cdnjs/cdnjs.svg</code></td>
|
||||
</tr>
|
||||
<tr><th data-keywords='GitHub license' data-doc='githubDoc'> license: </th>
|
||||
<td><img src='/github/license/mashape/apistatus.svg' alt=''/></td>
|
||||
<td><code>https://img.shields.io/github/license/mashape/apistatus.svg</code></td>
|
||||
|
|
Loading…
Reference in New Issue
Block a user