-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathoctokit.js
40 lines (36 loc) · 1.02 KB
/
octokit.js
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
33
34
35
36
37
38
39
40
const { Octokit } = require("@octokit/rest");
const { retry } = require("@octokit/plugin-retry");
const { throttling } = require("@octokit/plugin-throttling");
const MyOctokit = Octokit.plugin(retry, throttling);
const octokit = new MyOctokit({
auth: process.env.GITHUB_TOKEN,
userAgent: "KLE-bot v1.0.0",
log: {
debug: () => {},
info: () => {},
warn: console.warn,
error: console.error,
},
throttle: {
onRateLimit: (retryAfter, options) => {
octokit.log.warn(
`Request quota exhausted for request ${options.method} ${options.url}`
);
if (options.request.retryCount === 0) {
// only retries once
octokit.log.info(`Retrying after ${retryAfter} seconds!`);
return true;
}
},
onAbuseLimit: (retryAfter, options) => {
// does not retry, only logs a warning
octokit.log.warn(
`Abuse detected for request ${options.method} ${options.url}`
);
},
},
retry: {
doNotRetry: ["429"],
},
});
module.exports = octokit;