Skip to content

Commit 997bb18

Browse files
committed
Add getDotcomApiDetails
1 parent 4037ae0 commit 997bb18

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

‎src/api-client.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ import {
1818
RegistryProxyVars,
1919
getEnv,
2020
exportEnvVar,
21+
ActionsEnvVars,
2122
} from "./environment";
2223
import {
2324
getCurrentInstance,
25+
getDotcomInstance,
2426
GITHUB_DOTCOM_URL,
2527
parseGitHubUrl,
2628
type GitHubApiCombinedDetails,
@@ -169,6 +171,28 @@ export function getApiDetails(env: ReadOnlyEnv = getEnv()): GitHubApiDetails {
169171
};
170172
}
171173

174+
/**
175+
* Gets a `GitHubApiDetails` object describing the GitHub Dotcom instance.
176+
*
177+
* @param env The environment variables to read.
178+
*/
179+
export function getDotcomApiDetails(env: ReadOnlyEnv): GitHubApiDetails {
180+
// If we are currently running on dotcom, then just call `getApiDetails` which will
181+
// construct the appropriate `GitHubApiDetails` from the environment and include the
182+
// value of the `token` input. The `token` input relates to the GitHub instance that
183+
// we are running on only. Therefore, if we are not currently running on dotcom,
184+
// then we construct `GitHubApiDetails` without the `token` value and using the
185+
// hard-coded instance and API URLs.
186+
if (env.getRequired(ActionsEnvVars.GITHUB_SERVER_URL) === GITHUB_DOTCOM_URL) {
187+
return getApiDetails(env);
188+
} else {
189+
return {
190+
auth: undefined,
191+
...getDotcomInstance(),
192+
};
193+
}
194+
}
195+
172196
export function getApiClient(env: ReadOnlyEnv = getEnv()) {
173197
return createApiClientWithDetails(getApiDetails(env));
174198
}

0 commit comments

Comments
 (0)