Use instance in DownloadSource and pass it on to getApiClient

This commit is contained in:
Michael B. Gale
2026-10-13 18:39:27 +01:00
parent 39358b5a0d
commit 74a138c285
6 changed files with 95 additions and 54 deletions

49
lib/entry-points.js generated
View File

@@ -170602,6 +170602,7 @@ var import_undici = __toESM(require_undici());
// src/github.ts
var GITHUB_DOTCOM_URL = "https://github.com";
var GITHUB_DOTCOM_API_URL = "https://api.github.com";
function parseGitHubUrl(inputUrl) {
const originalUrl = inputUrl;
if (inputUrl.indexOf("://") === -1) {
@@ -170636,6 +170637,12 @@ function getCurrentInstance(env) {
apiURL: env.getRequired("GITHUB_API_URL" /* GITHUB_API_URL */)
};
}
function getDotcomInstance() {
return {
url: GITHUB_DOTCOM_URL,
apiURL: GITHUB_DOTCOM_API_URL
};
}
// src/repository.ts
function isRepositoryNwoStr(val) {
@@ -170728,8 +170735,18 @@ function getApiDetails(env = getEnv()) {
...getCurrentInstance(env)
};
}
function getApiClient(env = getEnv()) {
return createApiClientWithDetails(getApiDetails(env));
function getDotcomApiDetails(env) {
if (env.getRequired("GITHUB_SERVER_URL" /* GITHUB_SERVER_URL */) === GITHUB_DOTCOM_URL) {
return getApiDetails(env);
} else {
return {
auth: void 0,
...getDotcomInstance()
};
}
}
function getApiClient(env = getEnv(), apiDetails) {
return createApiClientWithDetails(apiDetails ?? getApiDetails(env));
}
function getApiClientWithExternalAuth(apiDetails, proxy) {
return createApiClientWithDetails(apiDetails, { allowExternal: true, proxy });
@@ -175732,35 +175749,35 @@ function getCodeQLActionRepository(action) {
`The value of '${"GITHUB_ACTION_REPOSITORY" /* GITHUB_ACTION_REPOSITORY */}' is '${actionRepository}', which does not match the expected 'owner/repo' format.`
);
}
var DEFAULT_DOWNLOAD_SOURCE = [
GITHUB_DOTCOM_URL,
CODEQL_DEFAULT_ACTION_REPOSITORY
];
var isSameDownloadSource = ([srcUrl, srcRepo], [otherUrl, otherRepo]) => {
return srcUrl === otherUrl && srcRepo === otherRepo;
var isSameDownloadSource = ([srcInstance, srcRepo], [otherInstance, otherRepo]) => {
return srcInstance.url === otherInstance.url && srcRepo === otherRepo;
};
async function getCodeQLAssetDownloadURL(action, apiDetails, tagName, assetName, assetKind = "CodeQL bundle") {
const codeQLActionRepository = getCodeQLActionRepository(action);
const defaultDownloadSource = [
getDotcomApiDetails(action.env),
CODEQL_DEFAULT_ACTION_REPOSITORY
];
const potentialDownloadSources = [
// This GitHub instance, and this Action.
[apiDetails.url, codeQLActionRepository],
[apiDetails, codeQLActionRepository],
// This GitHub instance, and the canonical Action.
[apiDetails.url, CODEQL_DEFAULT_ACTION_REPOSITORY],
[apiDetails, CODEQL_DEFAULT_ACTION_REPOSITORY],
// GitHub.com, and the canonical Action.
DEFAULT_DOWNLOAD_SOURCE
defaultDownloadSource
];
const uniqueDownloadSources = potentialDownloadSources.filter(
(source, index2, self2) => {
return !self2.slice(0, index2).some((other) => isSameDownloadSource(source, other));
}
);
for (const [apiURL, repository] of uniqueDownloadSources) {
if (isSameDownloadSource(DEFAULT_DOWNLOAD_SOURCE, [apiURL, repository])) {
for (const [instance8, repository] of uniqueDownloadSources) {
if (isSameDownloadSource(defaultDownloadSource, [instance8, repository])) {
break;
}
const [repositoryOwner, repositoryName] = repository.split("/");
try {
const release2 = await getApiClient().rest.repos.getReleaseByTag({
const release2 = await getApiClient(action.env, instance8).rest.repos.getReleaseByTag({
owner: repositoryOwner,
repo: repositoryName,
tag: tagName
@@ -175768,14 +175785,14 @@ async function getCodeQLAssetDownloadURL(action, apiDetails, tagName, assetName,
for (const asset of release2.data.assets) {
if (asset.name === assetName) {
action.logger.info(
`Found ${assetKind} ${assetName} in ${repository} on ${apiURL} with URL ${asset.url}.`
`Found ${assetKind} ${assetName} in ${repository} on ${instance8.apiURL} with URL ${asset.url}.`
);
return asset.url;
}
}
} catch (e) {
action.logger.info(
`Looked for ${assetKind} ${assetName} in ${repository} on ${apiURL} but got error ${e}.`
`Looked for ${assetKind} ${assetName} in ${repository} on ${instance8.apiURL} but got error ${e}.`
);
}
}