From 9e60130a3c8513ad0a37facf00e6be53c1f398b8 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Tue, 13 Oct 2026 18:11:29 +0100 Subject: [PATCH] Add `getDotcomApiDetails` --- src/api-client.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/api-client.ts b/src/api-client.ts index 4d0a99920..eeb752927 100644 --- a/src/api-client.ts +++ b/src/api-client.ts @@ -18,9 +18,11 @@ import { RegistryProxyVars, getEnv, exportEnvVar, + ActionsEnvVars, } from "./environment"; import { getCurrentInstance, + getDotcomInstance, GITHUB_DOTCOM_URL, parseGitHubUrl, type GitHubApiCombinedDetails, @@ -169,6 +171,28 @@ export function getApiDetails(env: ReadOnlyEnv = getEnv()): GitHubApiDetails { }; } +/** + * Gets a `GitHubApiDetails` object describing the GitHub Dotcom instance. + * + * @param env The environment variables to read. + */ +export function getDotcomApiDetails(env: ReadOnlyEnv): GitHubApiDetails { + // If we are currently running on dotcom, then just call `getApiDetails` which will + // construct the appropriate `GitHubApiDetails` from the environment and include the + // value of the `token` input. The `token` input relates to the GitHub instance that + // we are running on only. Therefore, if we are not currently running on dotcom, + // then we construct `GitHubApiDetails` without the `token` value and using the + // hard-coded instance and API URLs. + if (env.getRequired(ActionsEnvVars.GITHUB_SERVER_URL) === GITHUB_DOTCOM_URL) { + return getApiDetails(env); + } else { + return { + auth: undefined, + ...getDotcomInstance(), + }; + } +} + export function getApiClient(env: ReadOnlyEnv = getEnv()) { return createApiClientWithDetails(getApiDetails(env)); }