-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
It implements best practices for using the GitHub API as described in https://developer.github.com/v3/guides/best-practices-for-integrators/#dealing-with-abuse-rate-limits When the primary rate limit is hit, it will log a warning and wait before trying the API endpoint one more time before failing.
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { info, warning } from '@actions/core'; | ||
import { Octokit } from '@octokit/core'; | ||
import { throttling } from '@octokit/plugin-throttling'; | ||
|
||
const CustomOctokit = Octokit.plugin(throttling); | ||
|
||
export type CustomOctokit = InstanceType<typeof CustomOctokit>; | ||
|
||
export function getOctokit(token: string) { | ||
return new CustomOctokit({ | ||
auth: token, | ||
throttle: { | ||
onRateLimit: (retryAfter, options, _octokit, retryCount) => { | ||
warning( | ||
`Request quota exhausted for request ${options.method} ${options.url}` | ||
); | ||
|
||
// Retry once after hitting a rate limit error, then give up | ||
if (retryCount < 1) { | ||
info(`Retrying after ${retryAfter} seconds!`); | ||
return true; | ||
} | ||
}, | ||
onSecondaryRateLimit: (_retryAfter, options) => { | ||
// When a secondary rate limit is hit, don't retry | ||
warning( | ||
`SecondaryRateLimit detected for request ${options.method} ${options.url}` | ||
); | ||
}, | ||
}, | ||
}); | ||
} |