GitHub auth: rely on cache if no tokens remain

This commit is contained in:
Thaddee Tyl 2016-06-27 19:37:19 +02:00
parent 12b0ded4a3
commit 56746d4a38
4 changed files with 48 additions and 60 deletions

View File

@ -232,19 +232,19 @@ 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>
<tr><th data-keywords='github' data-doc='githubDoc'> Github All Releases: </th>
<td><img src='https://img.shields.io/github/downloads/atom/atom/total.svg?maxAge=2592000' alt=''/></td>
<td><code>https://img.shields.io/github/downloads/atom/atom/total.svg</code></td>
</tr>
<tr><th data-keywords='github'> Github Releases: </th>
<tr><th data-keywords='github' data-doc='githubDoc'> Github Releases: </th>
<td><img src='https://img.shields.io/github/downloads/atom/atom/latest/total.svg?maxAge=2592000' alt=''/></td>
<td><code>https://img.shields.io/github/downloads/atom/atom/latest/total.svg</code></td>
</tr>
<tr><th data-keywords='github'> Github Releases (by Release): </th>
<tr><th data-keywords='github' data-doc='githubDoc'> Github Releases (by Release): </th>
<td><img src='https://img.shields.io/github/downloads/atom/atom/v0.190.0/total.svg?maxAge=2592000' alt=''/></td>
<td><code>https://img.shields.io/github/downloads/atom/atom/v0.190.0/total.svg</code></td>
</tr>
<tr><th data-keywords='github'> Github Releases (by Asset): </th>
<tr><th data-keywords='github' data-doc='githubDoc'> Github Releases (by Asset): </th>
<td><img src='https://img.shields.io/github/downloads/atom/atom/latest/atom-amd64.deb.svg?maxAge=2592000' alt=''/></td>
<td><code>https://img.shields.io/github/downloads/atom/atom/latest/atom-amd64.deb.svg</code></td>
</tr>
@ -467,15 +467,15 @@ Pixel-perfect &nbsp; Retina-ready &nbsp; Fast &nbsp; Consistent &nbsp; Hackable
<td><img src='https://img.shields.io/hexpm/v/plug.svg?maxAge=2592000' alt=''/></td>
<td><code>https://img.shields.io/hexpm/v/plug.svg</code></td>
</tr>
<tr><th> GitHub tag: </th>
<tr><th data-doc='githubDoc'> GitHub tag: </th>
<td><img src='https://img.shields.io/github/tag/strongloop/express.svg?maxAge=2592000' alt=''/></td>
<td><code>https://img.shields.io/github/tag/strongloop/express.svg</code></td>
</tr>
<tr><th> GitHub release: </th>
<tr><th data-doc='githubDoc'> GitHub release: </th>
<td><img src='https://img.shields.io/github/release/qubyte/rubidium.svg?maxAge=2592000' alt=''/></td>
<td><code>https://img.shields.io/github/release/qubyte/rubidium.svg</code></td>
</tr>
<tr><th> GitHub commits: </th>
<tr><th data-doc='githubDoc'> GitHub commits: </th>
<td><img src='https://img.shields.io/github/commits-since/SubtitleEdit/subtitleedit/3.4.7.svg?maxAge=2592000' alt=''/></td>
<td><code>https://img.shields.io/github/commits-since/SubtitleEdit/subtitleedit/3.4.7.svg</code></td>
</tr>
@ -555,19 +555,19 @@ Pixel-perfect &nbsp; Retina-ready &nbsp; Fast &nbsp; Consistent &nbsp; Hackable
<h3 id="social"> Social </h3>
<table class='badge'><tbody>
<tr><th> GitHub forks: </th>
<tr><th data-doc='githubDoc'> GitHub forks: </th>
<td><img src='https://img.shields.io/github/forks/badges/shields.svg?style=social&label=Fork&maxAge=2592000' alt=''/></td>
<td><code>https://img.shields.io/github/forks/badges/shields.svg?style=social&amp;label=Fork</code></td>
</tr>
<tr><th> GitHub stars: </th>
<tr><th data-doc='githubDoc'> GitHub stars: </th>
<td><img src='https://img.shields.io/github/stars/badges/shields.svg?style=social&label=Star&maxAge=2592000' alt=''/></td>
<td><code>https://img.shields.io/github/stars/badges/shields.svg?style=social&amp;label=Star</code></td>
</tr>
<tr><th> GitHub watchers: </th>
<tr><th data-doc='githubDoc'> GitHub watchers: </th>
<td><img src='https://img.shields.io/github/watchers/badges/shields.svg?style=social&label=Watch&maxAge=2592000' alt=''/></td>
<td><code>https://img.shields.io/github/watchers/badges/shields.svg?style=social&amp;label=Watch</code></td>
</tr>
<tr><th> GitHub followers: </th>
<tr><th data-doc='githubDoc'> GitHub followers: </th>
<td><img src='https://img.shields.io/github/followers/espadrine.svg?style=social&label=Follow&maxAge=2592000' alt=''/></td>
<td><code>https://img.shields.io/github/followers/espadrine.svg?style=social&amp;label=Follow</code></td>
</tr>
@ -695,19 +695,19 @@ Pixel-perfect &nbsp; Retina-ready &nbsp; Fast &nbsp; Consistent &nbsp; Hackable
<td><img src='https://img.shields.io/wheelmap/a/2323004600.svg?maxAge=2592000' alt='' /></td>
<td><code>https://img.shields.io/wheelmap/a/2323004600.svg</code></td>
</tr>
<tr><th> GitHub issues: </th>
<tr><th data-doc='githubDoc'> GitHub issues: </th>
<td><img src='https://img.shields.io/github/issues/badges/shields.svg?maxAge=2592000' alt=''/></td>
<td><code>https://img.shields.io/github/issues/badges/shields.svg</code></td>
</tr>
<tr><th data-keywords='GitHub'></th>
<tr><th data-keywords='GitHub' data-doc='githubDoc'></th>
<td><img src='https://img.shields.io/github/issues-raw/badges/shields.svg?maxAge=2592000' alt=''/></td>
<td><code>https://img.shields.io/github/issues-raw/badges/shields.svg</code></td>
</tr>
<tr><th data-keywords='GitHub'> label:</th>
<tr><th data-keywords='GitHub' data-doc='githubDoc'> label:</th>
<td><img src='https://img.shields.io/github/issues-raw/badges/shields/website.svg?maxAge=2592000' alt=''/></td>
<td><code>https://img.shields.io/github/issues-raw/badges/shields/website.svg</code></td>
</tr>
<tr><th data-keywords='GitHub license'> license: </th>
<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>
</tr>
@ -1087,6 +1087,14 @@ is where the current server got started.
</tbody></table>
</p>
</div>
<div id="githubDoc">
<p>If your GitHub badge errors, it might be because you hit GitHub's rate
limits.<br>
You can increase Shield.io's rate limit by
<a href="https://img.shields.io/github-auth">going to this page</a>
to add Shields as a GitHub application on your GitHub account.
</p>
</div>
</div>
<svg style='height:0'>

View File

@ -221,6 +221,7 @@ function githubRequest(request, url, query, cb) {
console.log('GitHub auth: token', githubToken, 'rate limit', remaining,
'reset', reset, 'now', utcEpochSeconds());
setReqRemaining(githubToken, remaining, reset);
if (remaining === 0) { return; } // Hope for the best in the cache.
}
}
cb(err, res, buffer);

View File

@ -2818,9 +2818,6 @@ cache(function(data, match, sendBadge, request) {
return;
}
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(e) { return e.name; });
var tag = latestVersion(versions);
@ -2853,9 +2850,6 @@ cache(function(data, match, sendBadge, request) {
return;
}
try {
if ((+res.headers['x-ratelimit-remaining']) === 0) {
return; // Hope for the best in the cache.
}
var data = JSON.parse(buffer);
var version = data.tag_name;
var prerelease = data.prerelease;
@ -2889,9 +2883,6 @@ cache(function(data, match, sendBadge, request) {
return;
}
try {
if ((+res.headers['x-ratelimit-remaining']) === 0) {
return; // Hope for the best in the cache.
}
var data = JSON.parse(buffer);
badgeData.text[1] = data.ahead_by;
badgeData.colorscheme = 'blue';
@ -2935,9 +2926,6 @@ cache(function(data, match, sendBadge, request) {
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;
@ -3005,9 +2993,6 @@ cache(function(data, match, sendBadge, request) {
return;
}
try {
if ((+res.headers['x-ratelimit-remaining']) === 0) {
return; // Hope for the best in the cache.
}
var data = JSON.parse(buffer);
var modifier = '';
if (issuesApi) {
@ -3049,9 +3034,6 @@ cache(function(data, match, sendBadge, request) {
return;
}
try {
if ((+res.headers['x-ratelimit-remaining']) === 0) {
return; // Hope for the best in the cache.
}
var data = JSON.parse(buffer);
var forks = data.forks_count;
badgeData.text[1] = forks;
@ -3087,9 +3069,6 @@ cache(function(data, match, sendBadge, request) {
return;
}
try {
if ((+res.headers['x-ratelimit-remaining']) === 0) {
return; // Hope for the best in the cache.
}
badgeData.text[1] = JSON.parse(buffer).stargazers_count;
badgeData.colorscheme = null;
badgeData.colorB = '#4183C4';
@ -3123,9 +3102,6 @@ cache(function(data, match, sendBadge, request) {
return;
}
try {
if ((+res.headers['x-ratelimit-remaining']) === 0) {
return; // Hope for the best in the cache.
}
badgeData.text[1] = JSON.parse(buffer).subscribers_count;
badgeData.colorscheme = null;
badgeData.colorB = '#4183C4';
@ -3154,9 +3130,6 @@ cache(function(data, match, sendBadge, request) {
return;
}
try {
if ((+res.headers['x-ratelimit-remaining']) === 0) {
return; // Hope for the best in the cache.
}
badgeData.text[1] = JSON.parse(buffer).followers;
badgeData.colorscheme = null;
badgeData.colorB = '#4183C4';
@ -3199,9 +3172,7 @@ cache(function(data, match, sendBadge, request) {
return;
}
try {
if ((+res.headers['x-ratelimit-remaining']) === 0) {
return; // Hope for the best in the cache.
} else if (res.statusCode === 404) {
if (res.statusCode === 404) {
badgeData.text[1] = 'repo not found';
sendBadge(format, badgeData);
return;

View File

@ -231,19 +231,19 @@ Pixel-perfect &nbsp; Retina-ready &nbsp; Fast &nbsp; Consistent &nbsp; Hackable
</tbody></table>
<h3 id="downloads"> Downloads </h3>
<table class='badge'><tbody>
<tr><th data-keywords='github'> Github All Releases: </th>
<tr><th data-keywords='github' data-doc='githubDoc'> Github All Releases: </th>
<td><img src='/github/downloads/atom/atom/total.svg' alt=''/></td>
<td><code>https://img.shields.io/github/downloads/atom/atom/total.svg</code></td>
</tr>
<tr><th data-keywords='github'> Github Releases: </th>
<tr><th data-keywords='github' data-doc='githubDoc'> 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>
</tr>
<tr><th data-keywords='github'> Github Releases (by Release): </th>
<tr><th data-keywords='github' data-doc='githubDoc'> Github Releases (by Release): </th>
<td><img src='/github/downloads/atom/atom/v0.190.0/total.svg' alt=''/></td>
<td><code>https://img.shields.io/github/downloads/atom/atom/v0.190.0/total.svg</code></td>
</tr>
<tr><th data-keywords='github'> Github Releases (by Asset): </th>
<tr><th data-keywords='github' data-doc='githubDoc'> Github Releases (by Asset): </th>
<td><img src='/github/downloads/atom/atom/latest/atom-amd64.deb.svg' alt=''/></td>
<td><code>https://img.shields.io/github/downloads/atom/atom/latest/atom-amd64.deb.svg</code></td>
</tr>
@ -466,15 +466,15 @@ Pixel-perfect &nbsp; Retina-ready &nbsp; Fast &nbsp; Consistent &nbsp; Hackable
<td><img src='/hexpm/v/plug.svg' alt=''/></td>
<td><code>https://img.shields.io/hexpm/v/plug.svg</code></td>
</tr>
<tr><th> GitHub tag: </th>
<tr><th data-doc='githubDoc'> GitHub tag: </th>
<td><img src='/github/tag/strongloop/express.svg' alt=''/></td>
<td><code>https://img.shields.io/github/tag/strongloop/express.svg</code></td>
</tr>
<tr><th> GitHub release: </th>
<tr><th data-doc='githubDoc'> GitHub release: </th>
<td><img src='/github/release/qubyte/rubidium.svg' alt=''/></td>
<td><code>https://img.shields.io/github/release/qubyte/rubidium.svg</code></td>
</tr>
<tr><th> GitHub commits: </th>
<tr><th data-doc='githubDoc'> GitHub commits: </th>
<td><img src='/github/commits-since/SubtitleEdit/subtitleedit/3.4.7.svg' alt=''/></td>
<td><code>https://img.shields.io/github/commits-since/SubtitleEdit/subtitleedit/3.4.7.svg</code></td>
</tr>
@ -554,19 +554,19 @@ Pixel-perfect &nbsp; Retina-ready &nbsp; Fast &nbsp; Consistent &nbsp; Hackable
<h3 id="social"> Social </h3>
<table class='badge'><tbody>
<tr><th> GitHub forks: </th>
<tr><th data-doc='githubDoc'> GitHub forks: </th>
<td><img src='/github/forks/badges/shields.svg?style=social&label=Fork' alt=''/></td>
<td><code>https://img.shields.io/github/forks/badges/shields.svg?style=social&amp;label=Fork</code></td>
</tr>
<tr><th> GitHub stars: </th>
<tr><th data-doc='githubDoc'> GitHub stars: </th>
<td><img src='/github/stars/badges/shields.svg?style=social&label=Star' alt=''/></td>
<td><code>https://img.shields.io/github/stars/badges/shields.svg?style=social&amp;label=Star</code></td>
</tr>
<tr><th> GitHub watchers: </th>
<tr><th data-doc='githubDoc'> GitHub watchers: </th>
<td><img src='/github/watchers/badges/shields.svg?style=social&label=Watch' alt=''/></td>
<td><code>https://img.shields.io/github/watchers/badges/shields.svg?style=social&amp;label=Watch</code></td>
</tr>
<tr><th> GitHub followers: </th>
<tr><th data-doc='githubDoc'> GitHub followers: </th>
<td><img src='/github/followers/espadrine.svg?style=social&label=Follow' alt=''/></td>
<td><code>https://img.shields.io/github/followers/espadrine.svg?style=social&amp;label=Follow</code></td>
</tr>
@ -694,19 +694,19 @@ Pixel-perfect &nbsp; Retina-ready &nbsp; Fast &nbsp; Consistent &nbsp; Hackable
<td><img src='/wheelmap/a/2323004600.svg' alt='' /></td>
<td><code>https://img.shields.io/wheelmap/a/2323004600.svg</code></td>
</tr>
<tr><th> GitHub issues: </th>
<tr><th data-doc='githubDoc'> GitHub issues: </th>
<td><img src='/github/issues/badges/shields.svg' alt=''/></td>
<td><code>https://img.shields.io/github/issues/badges/shields.svg</code></td>
</tr>
<tr><th data-keywords='GitHub'></th>
<tr><th data-keywords='GitHub' data-doc='githubDoc'></th>
<td><img src='/github/issues-raw/badges/shields.svg' alt=''/></td>
<td><code>https://img.shields.io/github/issues-raw/badges/shields.svg</code></td>
</tr>
<tr><th data-keywords='GitHub'> label:</th>
<tr><th data-keywords='GitHub' data-doc='githubDoc'> label:</th>
<td><img src='/github/issues-raw/badges/shields/website.svg' alt=''/></td>
<td><code>https://img.shields.io/github/issues-raw/badges/shields/website.svg</code></td>
</tr>
<tr><th data-keywords='GitHub license'> license: </th>
<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>
</tr>
@ -1086,6 +1086,14 @@ is where the current server got started.
</tbody></table>
</p>
</div>
<div id="githubDoc">
<p>If your GitHub badge errors, it might be because you hit GitHub's rate
limits.<br>
You can increase Shield.io's rate limit by
<a href="https://img.shields.io/github-auth">going to this page</a>
to add Shields as a GitHub application on your GitHub account.
</p>
</div>
</div>
<svg style='height:0'>