/
probot-octokit.ts
58 lines (54 loc) 路 1.75 KB
/
probot-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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { Octokit } from "@octokit/core";
import { enterpriseCompatibility } from "@octokit/plugin-enterprise-compatibility";
import { RequestOptions } from "@octokit/types";
import { paginateRest } from "@octokit/plugin-paginate-rest";
import { restEndpointMethods } from "@octokit/plugin-rest-endpoint-methods";
import { retry } from "@octokit/plugin-retry";
import { throttling } from "@octokit/plugin-throttling";
import { config } from "@probot/octokit-plugin-config";
import { createProbotAuth } from "octokit-auth-probot";
import { probotRequestLogging } from "./octokit-plugin-probot-request-logging";
import { VERSION } from "../version";
const defaultOptions = {
authStrategy: createProbotAuth,
throttle: {
onAbuseLimit: (
retryAfter: number,
options: RequestOptions,
octokit: Octokit
) => {
octokit.log.warn(
`Abuse limit hit with "${options.method} ${options.url}", retrying in ${retryAfter} seconds.`
);
return true;
},
onRateLimit: (
retryAfter: number,
options: RequestOptions,
octokit: Octokit
) => {
octokit.log.warn(
`Rate limit hit with "${options.method} ${options.url}", retrying in ${retryAfter} seconds.`
);
return true;
},
},
userAgent: `probot/${VERSION}`,
};
export const ProbotOctokit = Octokit.plugin(
throttling,
retry,
paginateRest,
restEndpointMethods,
enterpriseCompatibility,
probotRequestLogging,
config
).defaults((instanceOptions: any) => {
// merge throttle options deeply
const options = Object.assign({}, defaultOptions, instanceOptions, {
throttle: instanceOptions.throttle
? Object.assign({}, defaultOptions.throttle, instanceOptions.throttle)
: defaultOptions.throttle,
});
return options;
});