forked from EricCrosson/install-github-release-binary
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoctokit.ts
More file actions
29 lines (26 loc) · 920 Bytes
/
octokit.ts
File metadata and controls
29 lines (26 loc) · 920 Bytes
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
import * as core from "@actions/core";
import { Octokit } from "@octokit/rest";
import { throttling } from "@octokit/plugin-throttling";
export type { Octokit } from "@octokit/rest";
const ThrottlingOctokit = Octokit.plugin(throttling);
export function getOctokit(token: string): Octokit {
return new ThrottlingOctokit({
auth: token,
throttle: {
onRateLimit: (retryAfter, options: any) => {
core.warning(
`RateLimit detected for request ${options.method} ${options.url}.`
);
core.info(`Retrying after ${retryAfter} seconds.`);
return true;
},
onSecondaryRateLimit: (retryAfter, options: any) => {
// does not retry, only logs a warning
core.warning(
`SecondaryRateLimit detected for request ${options.method} ${options.url}.`
);
core.info(`Retrying after ${retryAfter} seconds.`);
},
},
});
}