Skip to content

Commit 79611c1

Browse files
committed
Move GitHubApiDetails to github.ts
1 parent cdb2530 commit 79611c1

2 files changed

Lines changed: 69 additions & 35 deletions

File tree

‎src/api-client.ts‎

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -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";
2328
import { Logger } from "./logging";
2429
import { getRepositoryNwo, RepositoryNwo } from "./repository";
2530
import {
@@ -31,6 +36,8 @@ import {
3136
parseMatrixInput,
3237
} from "./util";
3338

39+
export type { GitHubApiDetails, GitHubApiCombinedDetails } from "./github";
40+
3441
const GITHUB_ENTERPRISE_VERSION_HEADER = "x-github-enterprise-version";
3542

3643
/**
@@ -42,39 +49,6 @@ const GITHUB_ENTERPRISE_VERSION_HEADER = "x-github-enterprise-version";
4249
*/
4350
export 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+
*/
180159
export 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+
188190
export function getApiClient(env: ReadOnlyEnv = getEnv()) {
189191
return createApiClientWithDetails(getApiDetails(env));
190192
}

‎src/github.ts‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { GitHubInstance } from "./api-client";
21
import { ActionsEnvVars, type ReadOnlyEnv } from "./environment";
32
import { ConfigurationError } from "./util";
43

@@ -18,6 +17,39 @@ export type InstanceApiURL = string;
1817
*/
1918
export const GITHUB_DOTCOM_API_URL: InstanceApiURL = "https://api.github.com";
2019

20+
/**
21+
* Represents information about a GitHub instance, how to authenticate to it,
22+
* and how to authenticate to other repos on it.
23+
*/
24+
export type GitHubApiCombinedDetails = GitHubApiDetails &
25+
GitHubApiExternalRepoDetails;
26+
27+
/** Represents information about a GitHub instance. */
28+
export type GitHubInstance = {
29+
/** The base URL of the GitHub instance, such as `https://github.com`. */
30+
url: string;
31+
/**
32+
* The API base URL of the GitHub instance, such as `https://api.github.com`.
33+
* Typically this is the `api.` subdomain of the `url` domain.
34+
*/
35+
apiURL: string | undefined;
36+
};
37+
38+
/** Represents a {@link GitHubInstance} with a token for accessing the API. */
39+
export type GitHubApiDetails = GitHubInstance & {
40+
/** The token to use for accessing the API of the GitHub instance. */
41+
auth: string;
42+
};
43+
44+
/**
45+
* Represents information for accessing a repository on the same GitHub instance as the Action
46+
* is currently running on.
47+
*/
48+
export type GitHubApiExternalRepoDetails = {
49+
/** An optional token for accessing repo(s) on the same GitHub instance. */
50+
externalRepoAuth?: string;
51+
};
52+
2153
/**
2254
* Parses user input of a github.com or GHES URL to a canonical form.
2355
* Removes any API prefix or suffix if one is present.

0 commit comments

Comments
 (0)