Skip to content

Commit 654f5d9

Browse files
committed
Use getCurrentInstance()
1 parent ea91521 commit 654f5d9

5 files changed

Lines changed: 27 additions & 19 deletions

File tree

‎lib/entry-points.js‎

Lines changed: 11 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/api-client.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ import {
1313
import type { ActionState } from "./action-common";
1414
import { getActionVersion, getRequiredInput } from "./actions-util";
1515
import {
16-
ActionsEnvVars,
1716
EnvVar,
1817
ReadOnlyEnv,
1918
RegistryProxyVars,
2019
getEnv,
2120
exportEnvVar,
2221
} from "./environment";
2322
import {
23+
getCurrentInstance,
2424
GITHUB_DOTCOM_URL,
2525
parseGitHubUrl,
2626
type GitHubApiCombinedDetails,
@@ -154,11 +154,15 @@ function createApiClientWithDetails(
154154
return new retryingOctokit(opts);
155155
}
156156

157+
/**
158+
* Gets a `GitHubApiDetails` object describing the GitHub instance we are currently running on.
159+
*
160+
* @param env The environment variables to read.
161+
*/
157162
export function getApiDetails(env: ReadOnlyEnv = getEnv()): GitHubApiDetails {
158163
return {
159164
auth: getRequiredInput("token"),
160-
url: env.getRequired(ActionsEnvVars.GITHUB_SERVER_URL),
161-
apiURL: env.getRequired(ActionsEnvVars.GITHUB_API_URL),
165+
...getCurrentInstance(env),
162166
};
163167
}
164168

‎src/init-action.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import {
5050
loadRepositoryProperties,
5151
RepositoryPropertyName,
5252
} from "./feature-flags/properties";
53+
import * as github from "./github";
5354
import {
5455
checkInstallPython311,
5556
checkPacksForOverlayCompatibility,
@@ -233,8 +234,7 @@ async function run(
233234
apiDetails = {
234235
auth: getRequiredInput("token"),
235236
externalRepoAuth: getOptionalInput("external-repository-token"),
236-
url: actionState.env.getRequired(ActionsEnvVars.GITHUB_SERVER_URL),
237-
apiURL: actionState.env.getRequired(ActionsEnvVars.GITHUB_API_URL),
237+
...github.getCurrentInstance(actionState.env),
238238
};
239239

240240
const gitHubVersion = await getGitHubVersion();

‎src/setup-codeql-action.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ import { getGitHubVersion } from "./api-client";
1717
import { CodeQL } from "./codeql";
1818
import { ComputedInput, getToolsInput } from "./config/inputs";
1919
import { getRawLanguagesNoAutodetect } from "./config-utils";
20-
import { ActionsEnvVars, EnvVar } from "./environment";
20+
import { EnvVar } from "./environment";
2121
import { initFeatures } from "./feature-flags";
2222
import { loadRepositoryProperties } from "./feature-flags/properties";
23+
import * as github from "./github";
2324
import { initCodeQL } from "./init";
2425
import { Logger } from "./logging";
2526
import { getRepositoryNwo } from "./repository";
@@ -112,8 +113,7 @@ async function run(
112113
const apiDetails = {
113114
auth: getRequiredInput("token"),
114115
externalRepoAuth: getOptionalInput("external-repository-token"),
115-
url: actionState.env.getRequired(ActionsEnvVars.GITHUB_SERVER_URL),
116-
apiURL: actionState.env.getRequired(ActionsEnvVars.GITHUB_API_URL),
116+
...github.getCurrentInstance(actionState.env),
117117
};
118118

119119
const gitHubVersion = await getGitHubVersion();

‎src/upload-lib.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { EnvVar, exportEnvVar } from "./environment";
1818
import { FeatureEnablement } from "./feature-flags";
1919
import * as fingerprints from "./fingerprints";
2020
import * as gitUtils from "./git-utils";
21+
import * as github from "./github";
2122
import { initCodeQL } from "./init";
2223
import { Logger } from "./logging";
2324
import { getRepositoryNwo, RepositoryNwo } from "./repository";
@@ -33,7 +34,6 @@ import * as util from "./util";
3334
import {
3435
ConfigurationError,
3536
getErrorMessage,
36-
getRequiredEnvParam,
3737
GitHubVariant,
3838
GitHubVersion,
3939
satisfiesGHESVersion,
@@ -104,6 +104,8 @@ async function combineSarifFilesUsingCLI(
104104
features: FeatureEnablement,
105105
logger: Logger,
106106
): Promise<Partial<sarif.Log>> {
107+
const env = util.getEnv();
108+
107109
logger.info("Combining SARIF files using the CodeQL CLI");
108110

109111
const sarifObjects = sarifFiles.map(sarif.readSarifFile);
@@ -152,8 +154,7 @@ async function combineSarifFilesUsingCLI(
152154
externalRepoAuth: actionsUtil.getOptionalInput(
153155
"external-repository-token",
154156
),
155-
url: getRequiredEnvParam("GITHUB_SERVER_URL"),
156-
apiURL: getRequiredEnvParam("GITHUB_API_URL"),
157+
...github.getCurrentInstance(env),
157158
};
158159

159160
const codeQLDefaultVersionInfo =

0 commit comments

Comments
 (0)