-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3c2d3d6
commit 3311a26
Showing
5 changed files
with
161 additions
and
45 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const { Octokit } = require('@octokit/core'); | ||
const { retry } = require('@octokit/plugin-retry'); | ||
const { throttling } = require('@octokit/plugin-throttling'); | ||
|
||
const MyOctokit = Octokit.plugin(retry, throttling); | ||
const octokit = new MyOctokit({ | ||
auth: process.env.GITHUB_TOKEN, | ||
// options for throttling plugin https://github.com/octokit/plugin-throttling.js | ||
throttle: { | ||
onRateLimit: (retryAfter, options, octokitClient) => { | ||
octokitClient.log.warn( | ||
`Request quota exhausted for request ${options.method} ${options.url}` | ||
); | ||
|
||
if (options.request.retryCount === 0) { | ||
// only retries once | ||
octokitClient.log.info(`Retrying after ${retryAfter} seconds!`); | ||
// Return true to automatically retry the request after retryAfter seconds. | ||
return true; | ||
} | ||
|
||
return false; | ||
}, | ||
onAbuseLimit: (retryAfter, options, octokitClient) => { | ||
// does not retry, only logs a warning | ||
octokitClient.log.warn(`Abuse detected for request ${options.method} ${options.url}`); | ||
}, | ||
}, | ||
}); | ||
|
||
module.exports = octokit; |