UNPKG

@octokit/action

Version:

GitHub API client for GitHub Actions

51 lines (50 loc) 1.35 kB
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"; import { fetch as undiciFetch, ProxyAgent } from "undici"; import { VERSION } from "./version.js"; const DEFAULTS = { authStrategy: createActionAuth, baseUrl: getApiBaseUrl(), userAgent: `octokit-action.js/${VERSION}` }; 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 void 0; } const customFetch = async function(url, opts) { return await undiciFetch(url, { dispatcher: getProxyAgent(), ...opts }); }; const Octokit = Core.plugin(paginateRest, legacyRestEndpointMethods).defaults( function buildDefaults(options) { return { ...DEFAULTS, ...options, request: { fetch: customFetch, ...options.request } }; } ); function getApiBaseUrl() { return process.env["GITHUB_API_URL"] || "https://api.github.com"; } export { Octokit, customFetch, getProxyAgent };