-
Notifications
You must be signed in to change notification settings - Fork 46
/
index.ts
57 lines (48 loc) · 1.57 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
51
52
53
54
55
56
57
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 { fetch as undiciFetch, ProxyAgent } from "undici";
const DEFAULTS = {
authStrategy: createActionAuth,
baseUrl: getApiBaseUrl(),
userAgent: `octokit-action.js/${VERSION}`,
};
export function getProxyAgent() {
const httpProxy = process.env["HTTP_PROXY"] || process.env["http_proxy"];
if (httpProxy) {
return new ProxyAgent(httpProxy);
}
const httpsProxy = process.env["HTTPS_PROXY"] || process.env["https_proxy"];
if (httpsProxy) {
return new ProxyAgent(httpsProxy);
}
return undefined;
}
export const customFetch = async function (url: string, opts: any) {
return await undiciFetch(url, {
dispatcher: getProxyAgent(),
...opts,
});
};
export const Octokit = Core.plugin(
paginateRest,
legacyRestEndpointMethods,
).defaults(function buildDefaults(options: OctokitOptions): OctokitOptions {
return {
...DEFAULTS,
...options,
request: {
fetch: customFetch,
...options.request,
},
};
});
export type Octokit = InstanceType<typeof Octokit>;
function getApiBaseUrl(): string {
/* istanbul ignore next */
return process.env["GITHUB_API_URL"] || "https://api.github.com";
}