File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -18,9 +18,11 @@ import {
1818 RegistryProxyVars ,
1919 getEnv ,
2020 exportEnvVar ,
21+ ActionsEnvVars ,
2122} from "./environment" ;
2223import {
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+
172196export function getApiClient ( env : ReadOnlyEnv = getEnv ( ) ) {
173197 return createApiClientWithDetails ( getApiDetails ( env ) ) ;
174198}
You can’t perform that action at this time.
0 commit comments