@@ -19,7 +19,12 @@ import {
1919 getEnv ,
2020 exportEnvVar ,
2121} from "./environment" ;
22- import { GITHUB_DOTCOM_URL , parseGitHubUrl } from "./github" ;
22+ import {
23+ GITHUB_DOTCOM_URL ,
24+ parseGitHubUrl ,
25+ type GitHubApiCombinedDetails ,
26+ type GitHubApiDetails ,
27+ } from "./github" ;
2328import { Logger } from "./logging" ;
2429import { getRepositoryNwo , RepositoryNwo } from "./repository" ;
2530import {
@@ -31,6 +36,8 @@ import {
3136 parseMatrixInput ,
3237} from "./util" ;
3338
39+ export type { GitHubApiDetails , GitHubApiCombinedDetails } from "./github" ;
40+
3441const GITHUB_ENTERPRISE_VERSION_HEADER = "x-github-enterprise-version" ;
3542
3643/**
@@ -42,39 +49,6 @@ const GITHUB_ENTERPRISE_VERSION_HEADER = "x-github-enterprise-version";
4249 */
4350export const DO_NOT_RETRY_STATUSES = [ 400 , 410 , 422 , 451 ] ;
4451
45- /**
46- * Represents information about a GitHub instance, how to authenticate to it,
47- * and how to authenticate to other repos on it.
48- */
49- export type GitHubApiCombinedDetails = GitHubApiDetails &
50- GitHubApiExternalRepoDetails ;
51-
52- /** Represents information about a GitHub instance. */
53- export type GitHubInstance = {
54- /** The base URL of the GitHub instance, such as `https://github.com`. */
55- url : string ;
56- /**
57- * The API base URL of the GitHub instance, such as `https://api.github.com`.
58- * Typically this is the `api.` subdomain of the `url` domain.
59- */
60- apiURL : string | undefined ;
61- } ;
62-
63- /** Represents a {@link GitHubInstance} with a token for accessing the API. */
64- export type GitHubApiDetails = GitHubInstance & {
65- /** The token to use for accessing the API of the GitHub instance. */
66- auth : string ;
67- } ;
68-
69- /**
70- * Represents information for accessing a repository on the same GitHub instance as the Action
71- * is currently running on.
72- */
73- export type GitHubApiExternalRepoDetails = {
74- /** An optional token for accessing repo(s) on the same GitHub instance. */
75- externalRepoAuth ?: string ;
76- } ;
77-
7852/**
7953 * Gets the configuration for the private registry authentication proxy,
8054 * if it is available in the environment.
@@ -177,6 +151,11 @@ function createApiClientWithDetails(
177151 ) ;
178152}
179153
154+ /**
155+ * Gets a `GitHubApiDetails` object describing the GitHub instance we are currently running on.
156+ *
157+ * @param env The environment variables to read.
158+ */
180159export function getApiDetails ( env : ReadOnlyEnv = getEnv ( ) ) : GitHubApiDetails {
181160 return {
182161 auth : getRequiredInput ( "token" ) ,
@@ -185,6 +164,29 @@ export function getApiDetails(env: ReadOnlyEnv = getEnv()): GitHubApiDetails {
185164 } ;
186165}
187166
167+ /**
168+ * Gets a `GitHubApiDetails` object describing the GitHub Dotcom instance.
169+ *
170+ * @param env The environment variables to read.
171+ */
172+ // export function getDotcomApiDetails(env: ReadOnlyEnv): GitHubApiDetails {
173+ // // If we are currently running on dotcom, then just call `getApiDetails` which will
174+ // // construct the appropriate `GitHubApiDetails` from the environment and include the
175+ // // value of the `token` input. The `token` input relates to the GitHub instance that
176+ // // we are running on only. Therefore, if we are not currently running on dotcom,
177+ // // then we construct `GitHubApiDetails` without the `token` value and using the
178+ // // hard-coded instance and API URLs.
179+ // if (env.getRequired(ActionsEnvVars.GITHUB_SERVER_URL) === GITHUB_DOTCOM_URL) {
180+ // return getApiDetails(env);
181+ // } else {
182+ // return {
183+ // auth: "",
184+ // url: GITHUB_DOTCOM_URL,
185+ // apiURL: GITHUB_DOTCOM_API_URL,
186+ // };
187+ // }
188+ // }
189+
188190export function getApiClient ( env : ReadOnlyEnv = getEnv ( ) ) {
189191 return createApiClientWithDetails ( getApiDetails ( env ) ) ;
190192}
0 commit comments