generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable GitHub API request throttling
- Loading branch information
Showing
8 changed files
with
1,886 additions
and
8 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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'; | ||
|
||
export const CustomOctokit = Octokit.plugin(config); | ||
export const CustomOctokit = Octokit.plugin(config, throttling); | ||
|
||
export type CustomOctokit = InstanceType<typeof CustomOctokit>; | ||
|
||
export function getOctokit(token: string): CustomOctokit { | ||
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}` | ||
); | ||
}, | ||
}, | ||
}); | ||
} |
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