From f728bb6678f5d8cfc5a642125ad6c53e7ec7ae42 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 7aa4d61d7..6dd53e47e 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, @@ -187,6 +189,28 @@ export function getApiClient( return createApiClientWithDetails(apiDetails ?? getApiDetails(env)); } +/* + * 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 getApiClientWithExternalAuth( apiDetails: GitHubApiCombinedDetails, proxy?: ProxyAgent,