/
probot-octokit.ts
63 lines (58 loc) 路 1.82 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
59
60
61
62
63
import { Octokit } from "@octokit/core";
import { enterpriseCompatibility } from "@octokit/plugin-enterprise-compatibility";
import type { RequestOptions } from "@octokit/types";
import { paginateRest } from "@octokit/plugin-paginate-rest";
import { legacyRestEndpointMethods } 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.js";
import { VERSION } from "../version.js";
const defaultOptions = {
authStrategy: createProbotAuth,
throttle: {
enabled: true,
onSecondaryRateLimit: (
retryAfter: number,
options: RequestOptions,
octokit: Octokit,
) => {
octokit.log.warn(
`Secondary Rate 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,
legacyRestEndpointMethods,
enterpriseCompatibility,
probotRequestLogging,
config,
).defaults((instanceOptions: any) => {
// merge throttle options deeply
const options = {
...defaultOptions,
...instanceOptions,
...{
throttle: { ...defaultOptions.throttle, ...instanceOptions?.throttle },
},
};
return options;
});
export type ProbotOctokit = InstanceType<typeof ProbotOctokit>;