Skip to content

Commit

Permalink
GitHub release: avoid rate-limiting at 60 req/hour
Browse files Browse the repository at this point in the history
Part of issue #161.
  • Loading branch information
espadrine committed Jun 10, 2014
1 parent e7a4d93 commit 1e41c24
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -878,8 +878,8 @@ cache(function(data, match, sendBadge) {
var repo = match[2];
var format = match[3];
var apiUrl = 'https://api.github.com/repos/' + user + '/' + repo + '/tags';
// Using our OAuth App secret grants us 5000 req/min
// instead of the standard 60 req/min.
// 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;
Expand Down Expand Up @@ -924,6 +924,12 @@ cache(function(data, match, sendBadge) {
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('release', data);
// A special User-Agent is required:
// http://developer.github.com/v3/#user-agent-required
Expand All @@ -933,6 +939,9 @@ cache(function(data, match, sendBadge) {
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 versions = data.map(function(version) { return version.tag_name; });
var version = latestVersion(versions);
Expand Down

0 comments on commit 1e41c24

Please sign in to comment.