-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- 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.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,33 @@ | ||
import { info, warning } from '@actions/core'; | ||
import { Octokit } from '@octokit/core'; | ||
import { throttling } from '@octokit/plugin-throttling'; | ||
import { config } from '@probot/octokit-plugin-config'; | ||
|
||
const CustomOctokit = Octokit.plugin(config); | ||
const CustomOctokit = Octokit.plugin(config, 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, _octokit) => { | ||
// When a secondary rate limit is hit, don't retry | ||
warning( | ||
`SecondaryRateLimit detected for request ${options.method} ${options.url}` | ||
); | ||
}, | ||
}, | ||
}); | ||
} |