-
Notifications
You must be signed in to change notification settings - Fork 46
/
index.ts
50 lines (42 loc) · 1.41 KB
/
index.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
import { Octokit as Core } from "@octokit/core";
import { createActionAuth } from "@octokit/auth-action";
import { paginateRest } from "@octokit/plugin-paginate-rest";
import { legacyRestEndpointMethods } from "@octokit/plugin-rest-endpoint-methods";
export type { RestEndpointMethodTypes } from "@octokit/plugin-rest-endpoint-methods";
import { VERSION } from "./version";
import type { OctokitOptions } from "@octokit/core/dist-types/types";
import { HttpsProxyAgent } from "https-proxy-agent";
const DEFAULTS = {
authStrategy: createActionAuth,
baseUrl: getApiBaseUrl(),
userAgent: `octokit-action.js/${VERSION}`,
};
function getProxyAgent() {
const httpProxy = process.env["HTTP_PROXY"] || process.env["http_proxy"];
if (httpProxy) {
return new HttpsProxyAgent(httpProxy);
}
const httpsProxy = process.env["HTTPS_PROXY"] || process.env["https_proxy"];
if (httpsProxy) {
return new HttpsProxyAgent(httpsProxy);
}
return undefined;
}
export const Octokit = Core.plugin(
paginateRest,
legacyRestEndpointMethods,
).defaults(function buildDefaults(options: OctokitOptions): OctokitOptions {
return {
...DEFAULTS,
...options,
request: {
agent: getProxyAgent(),
...options.request,
},
};
});
export type Octokit = InstanceType<typeof Octokit>;
function getApiBaseUrl(): string {
/* istanbul ignore next */
return process.env["GITHUB_API_URL"] || "https://api.github.com";
}