Always fall back to anonymous download (#304)

Closes: #268
Closes: #305
This commit is contained in:
Kevin Stillhammer 2025-02-28 17:25:17 +01:00 committed by GitHub
parent 754a7d4c2d
commit 0313224678
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: B5690EEEBB952194
8 changed files with 97239 additions and 42569 deletions

44400
dist/save-cache/index.js generated vendored

File diff suppressed because one or more lines are too long

48581
dist/setup/index.js generated vendored

File diff suppressed because one or more lines are too long

46603
dist/update-known-checksums/index.js generated vendored

File diff suppressed because one or more lines are too long

124
package-lock.json generated
View file

@ -18,7 +18,8 @@
"@octokit/core": "^6.1.3", "@octokit/core": "^6.1.3",
"@octokit/plugin-paginate-rest": "^11.4.0", "@octokit/plugin-paginate-rest": "^11.4.0",
"@octokit/plugin-rest-endpoint-methods": "^13.3.0", "@octokit/plugin-rest-endpoint-methods": "^13.3.0",
"smol-toml": "^1.3.1" "smol-toml": "^1.3.1",
"undici": "^6.19.8"
}, },
"devDependencies": { "devDependencies": {
"@biomejs/biome": "1.9.4", "@biomejs/biome": "1.9.4",
@ -93,6 +94,17 @@
"undici": "^5.25.4" "undici": "^5.25.4"
} }
}, },
"node_modules/@actions/http-client/node_modules/undici": {
"version": "5.28.5",
"resolved": "https://registry.npmjs.org/undici/-/undici-5.28.5.tgz",
"integrity": "sha512-zICwjrDrcrUE0pyyJc1I2QzBkLM8FINsgOrt6WjA+BgajVq9Nxu2PbFFXUrAggLfDXlZGZBVZYw7WNV5KiBiBA==",
"dependencies": {
"@fastify/busboy": "^2.0.0"
},
"engines": {
"node": ">=14.0"
}
},
"node_modules/@actions/io": { "node_modules/@actions/io": {
"version": "1.1.3", "version": "1.1.3",
"resolved": "https://registry.npmjs.org/@actions/io/-/io-1.1.3.tgz", "resolved": "https://registry.npmjs.org/@actions/io/-/io-1.1.3.tgz",
@ -1087,9 +1099,9 @@
} }
}, },
"node_modules/@fastify/busboy": { "node_modules/@fastify/busboy": {
"version": "2.1.0", "version": "2.1.1",
"resolved": "https://registry.npmjs.org/@fastify/busboy/-/busboy-2.1.0.tgz", "resolved": "https://registry.npmjs.org/@fastify/busboy/-/busboy-2.1.1.tgz",
"integrity": "sha512-+KpH+QxZU7O4675t3mnkQKcZZg56u+K/Ct2K+N2AZYNVK8kyeo/bI18tI8aPm3tvNNRyTWfj6s5tnGNlcbQRsA==", "integrity": "sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA==",
"engines": { "engines": {
"node": ">=14" "node": ">=14"
} }
@ -1602,9 +1614,9 @@
} }
}, },
"node_modules/@octokit/endpoint": { "node_modules/@octokit/endpoint": {
"version": "10.1.2", "version": "10.1.3",
"resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-10.1.2.tgz", "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-10.1.3.tgz",
"integrity": "sha512-XybpFv9Ms4hX5OCHMZqyODYqGTZ3H6K6Vva+M9LR7ib/xr1y1ZnlChYv9H680y77Vd/i/k+thXApeRASBQkzhA==", "integrity": "sha512-nBRBMpKPhQUxCsQQeW+rCJ/OPSMcj3g0nfHn01zGYZXuNDvvXudF/TYY6APj5THlurerpFN4a/dQAIAaM6BYhA==",
"dependencies": { "dependencies": {
"@octokit/types": "^13.6.2", "@octokit/types": "^13.6.2",
"universal-user-agent": "^7.0.2" "universal-user-agent": "^7.0.2"
@ -1632,9 +1644,9 @@
"integrity": "sha512-izFjMJ1sir0jn0ldEKhZ7xegCTj/ObmEDlEfpFrx4k/JyZSMRHbO3/rBwgE7f3m2DHt+RrNGIVw4wSmwnm3t/g==" "integrity": "sha512-izFjMJ1sir0jn0ldEKhZ7xegCTj/ObmEDlEfpFrx4k/JyZSMRHbO3/rBwgE7f3m2DHt+RrNGIVw4wSmwnm3t/g=="
}, },
"node_modules/@octokit/plugin-paginate-rest": { "node_modules/@octokit/plugin-paginate-rest": {
"version": "11.4.0", "version": "11.4.3",
"resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-11.4.0.tgz", "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-11.4.3.tgz",
"integrity": "sha512-ttpGck5AYWkwMkMazNCZMqxKqIq1fJBNxBfsFwwfyYKTf914jKkLF0POMS3YkPBwp5g1c2Y4L79gDz01GhSr1g==", "integrity": "sha512-tBXaAbXkqVJlRoA/zQVe9mUdb8rScmivqtpv3ovsC5xhje/a+NOCivs7eUhWBwCApJVsR4G5HMeaLbq7PxqZGA==",
"dependencies": { "dependencies": {
"@octokit/types": "^13.7.0" "@octokit/types": "^13.7.0"
}, },
@ -1660,12 +1672,12 @@
} }
}, },
"node_modules/@octokit/request": { "node_modules/@octokit/request": {
"version": "9.2.0", "version": "9.2.2",
"resolved": "https://registry.npmjs.org/@octokit/request/-/request-9.2.0.tgz", "resolved": "https://registry.npmjs.org/@octokit/request/-/request-9.2.2.tgz",
"integrity": "sha512-kXLfcxhC4ozCnAXy2ff+cSxpcF0A1UqxjvYMqNuPIeOAzJbVWQ+dy5G2fTylofB/gTbObT8O6JORab+5XtA1Kw==", "integrity": "sha512-dZl0ZHx6gOQGcffgm1/Sf6JfEpmh34v3Af2Uci02vzUYz6qEN6zepoRtmybWXIGXFIK8K9ylE3b+duCWqhArtg==",
"dependencies": { "dependencies": {
"@octokit/endpoint": "^10.0.0", "@octokit/endpoint": "^10.1.3",
"@octokit/request-error": "^6.0.1", "@octokit/request-error": "^6.1.7",
"@octokit/types": "^13.6.2", "@octokit/types": "^13.6.2",
"fast-content-type-parse": "^2.0.0", "fast-content-type-parse": "^2.0.0",
"universal-user-agent": "^7.0.2" "universal-user-agent": "^7.0.2"
@ -1675,9 +1687,9 @@
} }
}, },
"node_modules/@octokit/request-error": { "node_modules/@octokit/request-error": {
"version": "6.1.6", "version": "6.1.7",
"resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-6.1.6.tgz", "resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-6.1.7.tgz",
"integrity": "sha512-pqnVKYo/at0NuOjinrgcQYpEbv4snvP3bKMRqHaD9kIsk9u1LCpb2smHZi8/qJfgeNqLo5hNW4Z7FezNdEo0xg==", "integrity": "sha512-69NIppAwaauwZv6aOzb+VVLwt+0havz9GT5YplkeJv7fG7a40qpLt/yZKyiDxAhgz0EtgNdNcb96Z0u+Zyuy2g==",
"dependencies": { "dependencies": {
"@octokit/types": "^13.6.2" "@octokit/types": "^13.6.2"
}, },
@ -1686,9 +1698,9 @@
} }
}, },
"node_modules/@octokit/types": { "node_modules/@octokit/types": {
"version": "13.7.0", "version": "13.8.0",
"resolved": "https://registry.npmjs.org/@octokit/types/-/types-13.7.0.tgz", "resolved": "https://registry.npmjs.org/@octokit/types/-/types-13.8.0.tgz",
"integrity": "sha512-BXfRP+3P3IN6fd4uF3SniaHKOO4UXWBfkdR3vA8mIvaoO/wLjGN5qivUtW0QRitBHHMcfC41SLhNVYIZZE+wkA==", "integrity": "sha512-x7DjTIbEpEWXK99DMd01QfWy0hd5h4EN+Q7shkdKds3otGQP+oWE/y0A76i1OvH9fygo4ddvNf7ZvF0t78P98A==",
"dependencies": { "dependencies": {
"@octokit/openapi-types": "^23.0.1" "@octokit/openapi-types": "^23.0.1"
} }
@ -4659,14 +4671,11 @@
} }
}, },
"node_modules/undici": { "node_modules/undici": {
"version": "5.28.5", "version": "6.21.1",
"resolved": "https://registry.npmjs.org/undici/-/undici-5.28.5.tgz", "resolved": "https://registry.npmjs.org/undici/-/undici-6.21.1.tgz",
"integrity": "sha512-zICwjrDrcrUE0pyyJc1I2QzBkLM8FINsgOrt6WjA+BgajVq9Nxu2PbFFXUrAggLfDXlZGZBVZYw7WNV5KiBiBA==", "integrity": "sha512-q/1rj5D0/zayJB2FraXdaWxbhWiNKDvu8naDT2dl1yTlvJp4BLtOcp2a5BvgGNQpYYJzau7tf1WgKv3b+7mqpQ==",
"dependencies": {
"@fastify/busboy": "^2.0.0"
},
"engines": { "engines": {
"node": ">=14.0" "node": ">=18.17"
} }
}, },
"node_modules/undici-types": { "node_modules/undici-types": {
@ -4944,6 +4953,16 @@
"requires": { "requires": {
"tunnel": "^0.0.6", "tunnel": "^0.0.6",
"undici": "^5.25.4" "undici": "^5.25.4"
},
"dependencies": {
"undici": {
"version": "5.28.5",
"resolved": "https://registry.npmjs.org/undici/-/undici-5.28.5.tgz",
"integrity": "sha512-zICwjrDrcrUE0pyyJc1I2QzBkLM8FINsgOrt6WjA+BgajVq9Nxu2PbFFXUrAggLfDXlZGZBVZYw7WNV5KiBiBA==",
"requires": {
"@fastify/busboy": "^2.0.0"
}
}
} }
}, },
"@actions/io": { "@actions/io": {
@ -5688,9 +5707,9 @@
"optional": true "optional": true
}, },
"@fastify/busboy": { "@fastify/busboy": {
"version": "2.1.0", "version": "2.1.1",
"resolved": "https://registry.npmjs.org/@fastify/busboy/-/busboy-2.1.0.tgz", "resolved": "https://registry.npmjs.org/@fastify/busboy/-/busboy-2.1.1.tgz",
"integrity": "sha512-+KpH+QxZU7O4675t3mnkQKcZZg56u+K/Ct2K+N2AZYNVK8kyeo/bI18tI8aPm3tvNNRyTWfj6s5tnGNlcbQRsA==" "integrity": "sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA=="
}, },
"@istanbuljs/load-nyc-config": { "@istanbuljs/load-nyc-config": {
"version": "1.1.0", "version": "1.1.0",
@ -6089,9 +6108,9 @@
} }
}, },
"@octokit/endpoint": { "@octokit/endpoint": {
"version": "10.1.2", "version": "10.1.3",
"resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-10.1.2.tgz", "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-10.1.3.tgz",
"integrity": "sha512-XybpFv9Ms4hX5OCHMZqyODYqGTZ3H6K6Vva+M9LR7ib/xr1y1ZnlChYv9H680y77Vd/i/k+thXApeRASBQkzhA==", "integrity": "sha512-nBRBMpKPhQUxCsQQeW+rCJ/OPSMcj3g0nfHn01zGYZXuNDvvXudF/TYY6APj5THlurerpFN4a/dQAIAaM6BYhA==",
"requires": { "requires": {
"@octokit/types": "^13.6.2", "@octokit/types": "^13.6.2",
"universal-user-agent": "^7.0.2" "universal-user-agent": "^7.0.2"
@ -6113,9 +6132,9 @@
"integrity": "sha512-izFjMJ1sir0jn0ldEKhZ7xegCTj/ObmEDlEfpFrx4k/JyZSMRHbO3/rBwgE7f3m2DHt+RrNGIVw4wSmwnm3t/g==" "integrity": "sha512-izFjMJ1sir0jn0ldEKhZ7xegCTj/ObmEDlEfpFrx4k/JyZSMRHbO3/rBwgE7f3m2DHt+RrNGIVw4wSmwnm3t/g=="
}, },
"@octokit/plugin-paginate-rest": { "@octokit/plugin-paginate-rest": {
"version": "11.4.0", "version": "11.4.3",
"resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-11.4.0.tgz", "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-11.4.3.tgz",
"integrity": "sha512-ttpGck5AYWkwMkMazNCZMqxKqIq1fJBNxBfsFwwfyYKTf914jKkLF0POMS3YkPBwp5g1c2Y4L79gDz01GhSr1g==", "integrity": "sha512-tBXaAbXkqVJlRoA/zQVe9mUdb8rScmivqtpv3ovsC5xhje/a+NOCivs7eUhWBwCApJVsR4G5HMeaLbq7PxqZGA==",
"requires": { "requires": {
"@octokit/types": "^13.7.0" "@octokit/types": "^13.7.0"
} }
@ -6129,29 +6148,29 @@
} }
}, },
"@octokit/request": { "@octokit/request": {
"version": "9.2.0", "version": "9.2.2",
"resolved": "https://registry.npmjs.org/@octokit/request/-/request-9.2.0.tgz", "resolved": "https://registry.npmjs.org/@octokit/request/-/request-9.2.2.tgz",
"integrity": "sha512-kXLfcxhC4ozCnAXy2ff+cSxpcF0A1UqxjvYMqNuPIeOAzJbVWQ+dy5G2fTylofB/gTbObT8O6JORab+5XtA1Kw==", "integrity": "sha512-dZl0ZHx6gOQGcffgm1/Sf6JfEpmh34v3Af2Uci02vzUYz6qEN6zepoRtmybWXIGXFIK8K9ylE3b+duCWqhArtg==",
"requires": { "requires": {
"@octokit/endpoint": "^10.0.0", "@octokit/endpoint": "^10.1.3",
"@octokit/request-error": "^6.0.1", "@octokit/request-error": "^6.1.7",
"@octokit/types": "^13.6.2", "@octokit/types": "^13.6.2",
"fast-content-type-parse": "^2.0.0", "fast-content-type-parse": "^2.0.0",
"universal-user-agent": "^7.0.2" "universal-user-agent": "^7.0.2"
} }
}, },
"@octokit/request-error": { "@octokit/request-error": {
"version": "6.1.6", "version": "6.1.7",
"resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-6.1.6.tgz", "resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-6.1.7.tgz",
"integrity": "sha512-pqnVKYo/at0NuOjinrgcQYpEbv4snvP3bKMRqHaD9kIsk9u1LCpb2smHZi8/qJfgeNqLo5hNW4Z7FezNdEo0xg==", "integrity": "sha512-69NIppAwaauwZv6aOzb+VVLwt+0havz9GT5YplkeJv7fG7a40qpLt/yZKyiDxAhgz0EtgNdNcb96Z0u+Zyuy2g==",
"requires": { "requires": {
"@octokit/types": "^13.6.2" "@octokit/types": "^13.6.2"
} }
}, },
"@octokit/types": { "@octokit/types": {
"version": "13.7.0", "version": "13.8.0",
"resolved": "https://registry.npmjs.org/@octokit/types/-/types-13.7.0.tgz", "resolved": "https://registry.npmjs.org/@octokit/types/-/types-13.8.0.tgz",
"integrity": "sha512-BXfRP+3P3IN6fd4uF3SniaHKOO4UXWBfkdR3vA8mIvaoO/wLjGN5qivUtW0QRitBHHMcfC41SLhNVYIZZE+wkA==", "integrity": "sha512-x7DjTIbEpEWXK99DMd01QfWy0hd5h4EN+Q7shkdKds3otGQP+oWE/y0A76i1OvH9fygo4ddvNf7ZvF0t78P98A==",
"requires": { "requires": {
"@octokit/openapi-types": "^23.0.1" "@octokit/openapi-types": "^23.0.1"
} }
@ -8365,12 +8384,9 @@
"dev": true "dev": true
}, },
"undici": { "undici": {
"version": "5.28.5", "version": "6.21.1",
"resolved": "https://registry.npmjs.org/undici/-/undici-5.28.5.tgz", "resolved": "https://registry.npmjs.org/undici/-/undici-6.21.1.tgz",
"integrity": "sha512-zICwjrDrcrUE0pyyJc1I2QzBkLM8FINsgOrt6WjA+BgajVq9Nxu2PbFFXUrAggLfDXlZGZBVZYw7WNV5KiBiBA==", "integrity": "sha512-q/1rj5D0/zayJB2FraXdaWxbhWiNKDvu8naDT2dl1yTlvJp4BLtOcp2a5BvgGNQpYYJzau7tf1WgKv3b+7mqpQ=="
"requires": {
"@fastify/busboy": "^2.0.0"
}
}, },
"undici-types": { "undici-types": {
"version": "6.20.0", "version": "6.20.0",

View file

@ -32,6 +32,7 @@
"@octokit/core": "^6.1.3", "@octokit/core": "^6.1.3",
"@octokit/plugin-paginate-rest": "^11.4.0", "@octokit/plugin-paginate-rest": "^11.4.0",
"@octokit/plugin-rest-endpoint-methods": "^13.3.0", "@octokit/plugin-rest-endpoint-methods": "^13.3.0",
"undici": "^6.19.8",
"smol-toml": "^1.3.1" "smol-toml": "^1.3.1"
}, },
"devDependencies": { "devDependencies": {

View file

@ -5,11 +5,7 @@ import { promises as fs } from "node:fs";
import { OWNER, REPO, TOOL_CACHE_NAME } from "../utils/constants"; import { OWNER, REPO, TOOL_CACHE_NAME } from "../utils/constants";
import type { Architecture, Platform } from "../utils/platforms"; import type { Architecture, Platform } from "../utils/platforms";
import { validateChecksum } from "./checksum/checksum"; import { validateChecksum } from "./checksum/checksum";
import { Octokit } from "@octokit/core"; import { Octokit } from "../utils/octokit";
import { paginateRest } from "@octokit/plugin-paginate-rest";
import { restEndpointMethods } from "@octokit/plugin-rest-endpoint-methods";
const PaginatingOctokit = Octokit.plugin(paginateRest, restEndpointMethods);
export function tryGetFromToolCache( export function tryGetFromToolCache(
arch: Architecture, arch: Architecture,
@ -98,7 +94,7 @@ export async function resolveVersion(
async function getAvailableVersions(githubToken: string): Promise<string[]> { async function getAvailableVersions(githubToken: string): Promise<string[]> {
try { try {
const octokit = new PaginatingOctokit({ const octokit = new Octokit({
auth: githubToken, auth: githubToken,
}); });
return await getReleaseTagNames(octokit); return await getReleaseTagNames(octokit);
@ -107,7 +103,7 @@ async function getAvailableVersions(githubToken: string): Promise<string[]> {
core.info( core.info(
"No (valid) GitHub token provided. Falling back to anonymous. Requests might be rate limited.", "No (valid) GitHub token provided. Falling back to anonymous. Requests might be rate limited.",
); );
const octokit = new PaginatingOctokit(); const octokit = new Octokit();
return await getReleaseTagNames(octokit); return await getReleaseTagNames(octokit);
} }
throw err; throw err;
@ -115,7 +111,7 @@ async function getAvailableVersions(githubToken: string): Promise<string[]> {
} }
async function getReleaseTagNames( async function getReleaseTagNames(
octokit: InstanceType<typeof PaginatingOctokit>, octokit: InstanceType<typeof Octokit>,
): Promise<string[]> { ): Promise<string[]> {
const response = await octokit.paginate(octokit.rest.repos.listReleases, { const response = await octokit.paginate(octokit.rest.repos.listReleases, {
owner: OWNER, owner: OWNER,
@ -126,7 +122,7 @@ async function getReleaseTagNames(
async function getLatestVersion(githubToken: string) { async function getLatestVersion(githubToken: string) {
core.debug("Getting latest version..."); core.debug("Getting latest version...");
const octokit = new PaginatingOctokit({ const octokit = new Octokit({
auth: githubToken, auth: githubToken,
}); });
@ -134,15 +130,14 @@ async function getLatestVersion(githubToken: string) {
try { try {
latestRelease = await getLatestRelease(octokit); latestRelease = await getLatestRelease(octokit);
} catch (err) { } catch (err) {
if ((err as Error).message.includes("Bad credentials")) { core.info(
core.info( "No (valid) GitHub token provided. Falling back to anonymous. Requests might be rate limited.",
"No (valid) GitHub token provided. Falling back to anonymous. Requests might be rate limited.", );
); if (err instanceof Error) {
const octokit = new PaginatingOctokit(); core.debug(err.message);
latestRelease = await getLatestRelease(octokit);
} else {
throw err;
} }
const octokit = new Octokit();
latestRelease = await getLatestRelease(octokit);
} }
if (!latestRelease) { if (!latestRelease) {
@ -152,9 +147,7 @@ async function getLatestVersion(githubToken: string) {
return latestRelease.tag_name; return latestRelease.tag_name;
} }
async function getLatestRelease( async function getLatestRelease(octokit: InstanceType<typeof Octokit>) {
octokit: InstanceType<typeof PaginatingOctokit>,
) {
const { data: latestRelease } = await octokit.rest.repos.getLatestRelease({ const { data: latestRelease } = await octokit.rest.repos.getLatestRelease({
owner: OWNER, owner: OWNER,
repo: REPO, repo: REPO,

View file

@ -1,20 +1,16 @@
import * as semver from "semver"; import * as semver from "semver";
import * as core from "@actions/core"; import * as core from "@actions/core";
import { Octokit } from "@octokit/core"; import { Octokit } from "./utils/octokit";
import { paginateRest } from "@octokit/plugin-paginate-rest";
import { restEndpointMethods } from "@octokit/plugin-rest-endpoint-methods";
import { OWNER, REPO } from "./utils/constants"; import { OWNER, REPO } from "./utils/constants";
import { updateChecksums } from "./download/checksum/update-known-checksums"; import { updateChecksums } from "./download/checksum/update-known-checksums";
const PaginatingOctokit = Octokit.plugin(paginateRest, restEndpointMethods);
async function run(): Promise<void> { async function run(): Promise<void> {
const checksumFilePath = process.argv.slice(2)[0]; const checksumFilePath = process.argv.slice(2)[0];
const github_token = process.argv.slice(2)[1]; const github_token = process.argv.slice(2)[1];
const octokit = new PaginatingOctokit({ const octokit = new Octokit({
auth: github_token, auth: github_token,
}); });

58
src/utils/octokit.ts Normal file
View file

@ -0,0 +1,58 @@
import { Octokit as Core } from "@octokit/core";
import type {
Constructor,
OctokitOptions,
} from "@octokit/core/dist-types/types";
import {
paginateRest,
type PaginateInterface,
} from "@octokit/plugin-paginate-rest";
import { legacyRestEndpointMethods } from "@octokit/plugin-rest-endpoint-methods";
import { fetch as undiciFetch, ProxyAgent, type RequestInit } from "undici";
export type { RestEndpointMethodTypes } from "@octokit/plugin-rest-endpoint-methods";
const DEFAULTS = {
baseUrl: "https://api.github.com",
userAgent: "setup-uv",
};
export function getProxyAgent() {
const httpProxy = process.env.HTTP_PROXY || process.env.http_prox;
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 (url: string, opts: RequestInit) =>
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>;