Skip to content

Commit d6d9807

Browse files
authored
fix(proxy): init HttpsProxyAgent if a proxy should be used (#426)
1 parent b29455a commit d6d9807

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/index.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@ const DEFAULTS = {
1414
userAgent: `octokit-action.js/${VERSION}`,
1515
};
1616

17+
function getProxyAgent() {
18+
const httpProxy = process.env["HTTP_PROXY"] || process.env["http_proxy"];
19+
if (httpProxy) {
20+
return new HttpsProxyAgent(httpProxy);
21+
}
22+
23+
const httpsProxy = process.env["HTTPS_PROXY"] || process.env["https_proxy"];
24+
if (httpsProxy) {
25+
return new HttpsProxyAgent(httpsProxy);
26+
}
27+
28+
return undefined;
29+
}
30+
1731
export const Octokit = Core.plugin(
1832
paginateRest,
1933
legacyRestEndpointMethods
@@ -22,7 +36,7 @@ export const Octokit = Core.plugin(
2236
...DEFAULTS,
2337
...options,
2438
request: {
25-
agent: new HttpsProxyAgent(),
39+
agent: getProxyAgent(),
2640
...options.request,
2741
},
2842
};

test/smoke.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ describe("Smoke test", () => {
178178
expect(data).toStrictEqual({ ok: true });
179179
});
180180

181-
it.each(["HTTPS_PROXY", "https_proxy"])(
181+
it.each(["HTTPS_PROXY", "https_proxy", "HTTP_PROXY", "http_proxy"])(
182182
"Uses https-proxy-agent with %s env var",
183183
async (https_proxy_env) => {
184184
process.env.GITHUB_TOKEN = "secret123";

0 commit comments

Comments
 (0)