total github downloads for all releases + all tags
This commit is contained in:
parent
03fc437a4f
commit
59e10ddeb0
|
@ -212,6 +212,10 @@ Pixel-perfect Retina-ready Fast Consistent Hackable
|
|||
</tbody></table>
|
||||
<h3 id="downloads"> Downloads </h3>
|
||||
<table class='badge'><tbody>
|
||||
<tr><th data-keywords='github'> Github All Releases: </th>
|
||||
<td><img src='https://img.shields.io/github/downloads/atom/atom.svg' alt=''/></td>
|
||||
<td><code>https://img.shields.io/github/downloads/atom/atom.svg</code></td>
|
||||
</tr>
|
||||
<tr><th data-keywords='github'> Github Releases: </th>
|
||||
<td><img src='https://img.shields.io/github/downloads/atom/atom/latest/total.svg' alt=''/></td>
|
||||
<td><code>https://img.shields.io/github/downloads/atom/atom/latest/total.svg</code></td>
|
||||
|
@ -913,6 +917,10 @@ is where the current server got started.
|
|||
<a class='photo' href='https://github.com/PeterDaveHello'>
|
||||
<img alt='PeterDaveHello' src='https://avatars3.githubusercontent.com/u/3691490?s=80'>
|
||||
</a>
|
||||
<br>
|
||||
<a class='photo' href='https://github.com/sagiegurari'>
|
||||
<img alt='sagiegurari' src='https://avatars.githubusercontent.com/u/8112599?s=80'>
|
||||
</a>
|
||||
<p><small>:wq</small></p>
|
||||
</main>
|
||||
|
||||
|
|
46
server.js
46
server.js
|
@ -2599,6 +2599,52 @@ cache(function(data, match, sendBadge, request) {
|
|||
});
|
||||
}));
|
||||
|
||||
|
||||
// GitHub all releases download count integration.
|
||||
camp.route(/^\/github\/downloads\/([^\/]+)\/([^\/]+)\.(svg|png|gif|jpg|json)$/,
|
||||
cache(function(data, match, sendBadge, request) {
|
||||
var user = match[1]; // eg, atom/atom
|
||||
var repo = match[2];
|
||||
var format = match[3];
|
||||
var apiUrl = 'https://api.github.com/repos/' + user + '/' + repo + '/releases';
|
||||
// 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('downloads', data);
|
||||
if (badgeData.template === 'social') {
|
||||
badgeData.logo = badgeData.logo || logos.github;
|
||||
}
|
||||
// A special User-Agent is required:
|
||||
// http://developer.github.com/v3/#user-agent-required
|
||||
request(apiUrl, { headers: githubHeaders }, function(err, res, buffer) {
|
||||
if (err) {
|
||||
badgeData.text[1] = 'inaccessible';
|
||||
return 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 downloads = 0;
|
||||
data.forEach(function (tagData) {
|
||||
tagData.assets.forEach(function (asset) {
|
||||
downloads += asset.download_count;
|
||||
});
|
||||
});
|
||||
badgeData.text[1] = metric(downloads) + ' total';
|
||||
badgeData.colorscheme = 'brightgreen';
|
||||
sendBadge(format, badgeData);
|
||||
} catch(e) {
|
||||
badgeData.text[1] = 'none';
|
||||
sendBadge(format, badgeData);
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
// GitHub release-download-count integration.
|
||||
camp.route(/^\/github\/downloads\/([^\/]+)\/([^\/]+)\/([^\/]+)\/([^\/]+)\.(svg|png|gif|jpg|json)$/,
|
||||
cache(function(data, match, sendBadge, request) {
|
||||
|
|
8
try.html
8
try.html
|
@ -211,6 +211,10 @@ Pixel-perfect Retina-ready Fast Consistent Hackable
|
|||
</tbody></table>
|
||||
<h3 id="downloads"> Downloads </h3>
|
||||
<table class='badge'><tbody>
|
||||
<tr><th data-keywords='github'> Github All Releases: </th>
|
||||
<td><img src='https://img.shields.io/github/downloads/atom/atom.svg' alt=''/></td>
|
||||
<td><code>https://img.shields.io/github/downloads/atom/atom.svg</code></td>
|
||||
</tr>
|
||||
<tr><th data-keywords='github'> Github Releases: </th>
|
||||
<td><img src='/github/downloads/atom/atom/latest/total.svg' alt=''/></td>
|
||||
<td><code>https://img.shields.io/github/downloads/atom/atom/latest/total.svg</code></td>
|
||||
|
@ -920,6 +924,10 @@ is where the current server got started.
|
|||
<a class='photo' href='https://github.com/PeterDaveHello'>
|
||||
<img alt='PeterDaveHello' src='https://avatars3.githubusercontent.com/u/3691490?s=80'>
|
||||
</a>
|
||||
<br>
|
||||
<a class='photo' href='https://github.com/sagiegurari'>
|
||||
<img alt='sagiegurari' src='https://avatars.githubusercontent.com/u/8112599?s=80'>
|
||||
</a>
|
||||
<p><small>:wq</small></p>
|
||||
</main>
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user