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 Jan 3, 2024
1 parent b2b47c7 commit fe0c276
Show file tree
Hide file tree
Showing 10 changed files with 1,941 additions and 12 deletions.
1,816 changes: 1,811 additions & 5 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.

2 changes: 1 addition & 1 deletion dist/octokit.d.ts

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.

4 changes: 2 additions & 2 deletions dist/schema/input.d.ts

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 @@ -28,6 +28,7 @@
"dependencies": {
"@actions/core": "^1.10.1",
"@octokit/core": "^5.0.1",
"@octokit/plugin-throttling": "^8.1.3",
"@octokit/rest": "^20.0.2",
"@octokit/types": "^12.1.1",
"@probot/octokit-plugin-config": "^2.0.0",
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';

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}`
);
},
},
});
}
36 changes: 36 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,13 @@ __metadata:
languageName: node
linkType: hard

"@octokit/openapi-types@npm:^19.1.0":
version: 19.1.0
resolution: "@octokit/openapi-types@npm:19.1.0"
checksum: 9d1b188741609a9832b964df2bc337ee77c1fc89d5f686faebb743c7cb27721e214180d623ee28227427b4c43719b79ee4890e338a709b78a9f249a7c369ac3e
languageName: node
linkType: hard

"@octokit/plugin-paginate-rest@npm:^9.0.0":
version: 9.1.2
resolution: "@octokit/plugin-paginate-rest@npm:9.1.2"
Expand Down Expand Up @@ -511,6 +518,18 @@ __metadata:
languageName: node
linkType: hard

"@octokit/plugin-throttling@npm:^8.1.3":
version: 8.1.3
resolution: "@octokit/plugin-throttling@npm:8.1.3"
dependencies:
"@octokit/types": ^12.2.0
bottleneck: ^2.15.3
peerDependencies:
"@octokit/core": ^5.0.0
checksum: 98963ef2eab825015702b1ca1ef4ccbda0c009242e93001144e51014d3b53d3ecb1282b67488680c7f5f4e805d0c3af4020ad673079fff92c6353f04903a9a64
languageName: node
linkType: hard

"@octokit/request-error@npm:^5.0.0":
version: 5.0.1
resolution: "@octokit/request-error@npm:5.0.1"
Expand Down Expand Up @@ -556,6 +575,15 @@ __metadata:
languageName: node
linkType: hard

"@octokit/types@npm:^12.2.0":
version: 12.4.0
resolution: "@octokit/types@npm:12.4.0"
dependencies:
"@octokit/openapi-types": ^19.1.0
checksum: 17bca450efc5433f14e1f93a24232316a0fb490aec8d886c3a430e853f10a74e6664751a44e0e199336b23c20658c4afcb3590e422ba7c155c2cb31f433ebbb7
languageName: node
linkType: hard

"@pkgjs/parseargs@npm:^0.11.0":
version: 0.11.0
resolution: "@pkgjs/parseargs@npm:0.11.0"
Expand Down Expand Up @@ -1125,6 +1153,7 @@ __metadata:
"@actions/core": ^1.10.1
"@actions/github": ^6.0.0
"@octokit/core": ^5.0.1
"@octokit/plugin-throttling": ^8.1.3
"@octokit/rest": ^20.0.2
"@octokit/types": ^12.1.1
"@probot/octokit-plugin-config": ^2.0.0
Expand Down Expand Up @@ -1179,6 +1208,13 @@ __metadata:
languageName: node
linkType: hard

"bottleneck@npm:^2.15.3":
version: 2.19.5
resolution: "bottleneck@npm:2.19.5"
checksum: c5eef1bbea12cef1f1405e7306e7d24860568b0f7ac5eeab706a86762b3fc65ef6d1c641c8a166e4db90f412fc5c948fc5ce8008a8cd3d28c7212ef9c3482bda
languageName: node
linkType: hard

"bplist-parser@npm:^0.2.0":
version: 0.2.0
resolution: "bplist-parser@npm:0.2.0"
Expand Down

0 comments on commit fe0c276

Please sign in to comment.