diff --git a/index.html b/index.html
index 5601df2..07afae8 100644
--- a/index.html
+++ b/index.html
@@ -212,6 +212,10 @@ Pixel-perfect Retina-ready Fast Consistent Hackable
Downloads
+ Github All Releases: |
+  |
+ https://img.shields.io/github/downloads/atom/atom.svg |
+
Github Releases: |
 |
https://img.shields.io/github/downloads/atom/atom/latest/total.svg |
@@ -913,6 +917,10 @@ is where the current server got started.
+
+
+
+
:wq
diff --git a/server.js b/server.js
index 7ebab7c..0ad8d05 100644
--- a/server.js
+++ b/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) {
diff --git a/try.html b/try.html
index 919d7f0..4663040 100644
--- a/try.html
+++ b/try.html
@@ -211,6 +211,10 @@ Pixel-perfect Retina-ready Fast Consistent Hackable
---|
Downloads