generated from redhat-plumbers-in-action/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 1
/
octokit.ts
32 lines (28 loc) · 1006 Bytes
/
octokit.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { info, warning } from '@actions/core';
import { Octokit } from '@octokit/core';
import { throttling } from '@octokit/plugin-throttling';
const CustomOctokit = Octokit.plugin(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}`
);
},
},
});
}