|
1 | 1 | import * as core from "@actions/core"; |
2 | 2 | import { request } from "@octokit/request"; |
3 | | -import { ProxyAgent, fetch as undiciFetch } from "undici"; |
4 | 3 |
|
| 4 | +// Get the GitHub API URL from the action input and remove any trailing slash |
5 | 5 | const baseUrl = core.getInput("github-api-url").replace(/\/$/, ""); |
6 | 6 |
|
7 | | -// https://docs.github.com/actions/hosting-your-own-runners/managing-self-hosted-runners/using-a-proxy-server-with-self-hosted-runners |
8 | | -const proxyUrl = |
9 | | - process.env.https_proxy || |
10 | | - process.env.HTTPS_PROXY || |
11 | | - process.env.http_proxy || |
12 | | - process.env.HTTP_PROXY; |
13 | | - |
14 | | -/* c8 ignore start */ |
15 | | -// Native support for proxies in Undici is under consideration: https://github.com/nodejs/undici/issues/1650 |
16 | | -// Until then, we need to use a custom fetch function to add proxy support. |
17 | | -const proxyFetch = (url, options) => { |
18 | | - const urlHost = new URL(url).hostname; |
19 | | - const noProxy = (process.env.no_proxy || process.env.NO_PROXY || "").split( |
20 | | - ",", |
21 | | - ); |
22 | | - |
23 | | - if (!noProxy.includes(urlHost)) { |
24 | | - options = { |
25 | | - ...options, |
26 | | - dispatcher: new ProxyAgent(String(proxyUrl)), |
27 | | - }; |
28 | | - } |
29 | | - |
30 | | - return undiciFetch(url, options); |
31 | | -}; |
32 | | -/* c8 ignore stop */ |
33 | | - |
| 7 | +// Configure the default settings for GitHub API requests |
34 | 8 | export default request.defaults({ |
35 | | - headers: { |
36 | | - "user-agent": "actions/create-github-app-token", |
37 | | - }, |
| 9 | + headers: { "user-agent": "actions/create-github-app-token" }, |
38 | 10 | baseUrl, |
39 | | - /* c8 ignore next */ |
40 | | - request: proxyUrl ? { fetch: proxyFetch } : {}, |
41 | 11 | }); |
0 commit comments