-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathindex.ts
66 lines (56 loc) · 1.76 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
58
59
60
61
62
63
64
65
66
import { Octokit as Core } from "@octokit/core";
import type { Constructor, OctokitOptions } from "@octokit/core/types";
import { createActionAuth } from "@octokit/auth-action";
import {
paginateRest,
type PaginateInterface,
} from "@octokit/plugin-paginate-rest";
import { legacyRestEndpointMethods } from "@octokit/plugin-rest-endpoint-methods";
import { fetch as undiciFetch, ProxyAgent } from "undici";
import { VERSION } from "./version.js";
export type { RestEndpointMethodTypes } from "@octokit/plugin-rest-endpoint-methods";
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;
}
/* v8 ignore next 6 */
export const customFetch = async function (url: string, opts: any) {
return await undiciFetch(url, {
dispatcher: getProxyAgent(),
...opts,
});
};
export const Octokit: typeof Core &
Constructor<
{
paginate: PaginateInterface;
} & ReturnType<typeof legacyRestEndpointMethods>
> = 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 {
/* v8 ignore next */
return process.env["GITHUB_API_URL"] || "https://api.github.com";
}