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 Apr 23, 2024
1 parent 92e9f9e commit c2023eb
Show file tree
Hide file tree
Showing 8 changed files with 1,878 additions and 10 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.

18 changes: 17 additions & 1 deletion dist/octokit.js

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

2 changes: 1 addition & 1 deletion 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.2.0",
"@octokit/rest": "^20.1.0",
"@probot/octokit-plugin-config": "^3.0.2",
"@total-typescript/ts-reset": "^0.5.1",
Expand Down
23 changes: 22 additions & 1 deletion src/octokit.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
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,
baseUrl: process.env.GITHUB_API_URL ?? 'https://api.github.com',
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 @@ -500,6 +500,18 @@ __metadata:
languageName: node
linkType: hard

"@octokit/plugin-throttling@npm:^9.2.0":
version: 9.2.0
resolution: "@octokit/plugin-throttling@npm:9.2.0"
dependencies:
"@octokit/types": "npm:^13.0.0"
bottleneck: "npm:^2.15.3"
peerDependencies:
"@octokit/core": ^6.0.0
checksum: 10c0/05ce22d1032177e692fe583ffecc81a2f492bc5a02528db12ece967143e7e168aa3a8546bddb3a1342f2da3b79fce25007b78258fba3a771b48d0797a733e77c
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 @@ -880,6 +892,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.2.0"
"@octokit/rest": "npm:^20.1.0"
"@probot/octokit-plugin-config": "npm:^3.0.2"
"@total-typescript/ts-reset": "npm:^0.5.1"
Expand Down Expand Up @@ -993,6 +1006,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

0 comments on commit c2023eb

Please sign in to comment.