-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclient.js
49 lines (44 loc) · 1.61 KB
/
client.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
41
42
43
44
45
46
47
48
49
const { Octokit } = require("@octokit/rest");
const { createAppAuth } = require("@octokit/auth-app");
const { readFileSync } = require('fs');
const { retry } = require("@octokit/plugin-retry");
const { throttling } = require("@octokit/plugin-throttling");
const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
const GITHUB_APP_ID = process.env.GITHUB_APP_ID;
const readPrivateKey = () => {
return readFileSync(PRIVATE_KEY_PATH);
};
const AppOctokit = Octokit.plugin(retry, throttling);
const newClient = (installationID) => {
return new AppOctokit({
authStrategy: createAppAuth,
auth: {
id: GITHUB_APP_ID,
privateKey: readPrivateKey(),
installationId: installationID,
},
userAgent: 'fixCache v0.0.1',
throttle: {
onRateLimit: (retryAfter, options) => {
appOctokit.log.warn(
`Request quota exhausted for request ${options.method} ${options.url}`,
);
if (options.request.retryCount == 0){
appOctokit.log.info(`Retrying after ${retryAfter} seconds!`);
return true;
}
},
onAbuseLimit: (retryAfter, options) => {
// does not retry, only logs a warning
myOctokit.log.warn(
`Abuse detected for request ${options.method} ${options.url}`
);
},
},
retry: {
// do not retry on 429 (too many requests) response from api
doNotRetry: ["429"],
},
});
}
module.exports = { newClient };