Skip to content

Commit

Permalink
feat: enable GitHub API request throttling
Browse files Browse the repository at this point in the history
  • Loading branch information
jamacku committed May 6, 2024
1 parent 5b50202 commit ad766ea
Show file tree
Hide file tree
Showing 8 changed files with 1,886 additions and 8 deletions.
1,773 changes: 1,767 additions & 6 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions dist/licenses.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions dist/octokit.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/octokit.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@actions/core": "1.10.1",
"@actions/github": "6.0.0",
"@octokit/core": "6.1.2",
"@octokit/plugin-throttling": "^9.3.0",
"@octokit/rest": "20.1.1",
"@probot/octokit-plugin-config": "3.0.2",
"issue-metadata": "0.1.10",
Expand Down
23 changes: 22 additions & 1 deletion src/octokit.ts
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}`
);
},
},
});
}
20 changes: 20 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,18 @@ __metadata:
languageName: node
linkType: hard

"@octokit/plugin-throttling@npm:^9.3.0":
version: 9.3.0
resolution: "@octokit/plugin-throttling@npm:9.3.0"
dependencies:
"@octokit/types": "npm:^13.0.0"
bottleneck: "npm:^2.15.3"
peerDependencies:
"@octokit/core": ^6.0.0
checksum: 10c0/402368a422e6ed4092acf2aa21117ef92e1c4da22aab0fcfa32a1e57c7a021844605551af6c24e5b866cc4c4d601227bba88cea25c40712fc2d79b36ece5bf9d
languageName: node
linkType: hard

"@octokit/request-error@npm:^5.1.0":
version: 5.1.0
resolution: "@octokit/request-error@npm:5.1.0"
Expand Down Expand Up @@ -993,6 +1005,13 @@ __metadata:
languageName: node
linkType: hard

"bottleneck@npm:^2.15.3":
version: 2.19.5
resolution: "bottleneck@npm:2.19.5"
checksum: 10c0/b0f72e45b2e0f56a21ba720183f16bef8e693452fb0495d997fa354e42904353a94bd8fd429868e6751bc85e54b6755190519eed5a0ae0a94a5185209ae7c6d0
languageName: node
linkType: hard

"brace-expansion@npm:^1.1.7":
version: 1.1.11
resolution: "brace-expansion@npm:1.1.11"
Expand Down Expand Up @@ -1160,6 +1179,7 @@ __metadata:
"@actions/core": "npm:1.10.1"
"@actions/github": "npm:6.0.0"
"@octokit/core": "npm:6.1.2"
"@octokit/plugin-throttling": "npm:^9.3.0"
"@octokit/rest": "npm:20.1.1"
"@probot/octokit-plugin-config": "npm:3.0.2"
"@total-typescript/ts-reset": "npm:0.5.1"
Expand Down

0 comments on commit ad766ea

Please sign in to comment.