Address feedback from previous PR

This commit is contained in:
Michael B. Gale
2026-10-16 12:36:22 +01:00
parent 1772d44790
commit 1c350b1564
4 changed files with 14 additions and 8 deletions

4
lib/entry-points.js generated
View File

@@ -178527,8 +178527,8 @@ async function recordClearCleanupSizes(codeql, config, reports, logger2) {
report.clear_cleanup_measurement_duration_ms = durationMs;
}
}
async function uploadBundledDatabase(repositoryNwo, language, commitOid, bundledDb, bundledDbSize, apiDetails) {
const client = getApiClient(getEnv(), apiDetails);
async function uploadBundledDatabase(repositoryNwo, language, commitOid, bundledDb, bundledDbSize, apiDetails, env = getEnv()) {
const client = getApiClient(env, apiDetails);
const uploadsUrl = new URL(parseGitHubUrl(apiDetails.url));
uploadsUrl.hostname = `uploads.${uploadsUrl.hostname}`;
let uploadsBaseUrl = uploadsUrl.toString();

View File

@@ -229,8 +229,8 @@ export function getApiDetails(env: ReadOnlyEnv = getEnv()): GitHubApiDetails {
/**
* Constructs an {@link ApiClient} using {@link apiDetails}.
*
* If {@link apiDetails} is not specified, then the GitHub instance URLs and auth token
* are taken from {@link env}.
* If {@link apiDetails} is not specified, then the GitHub instance URLs are taken from {@link env}
* and the auth token is taken from the `token` input.
*
* If {@link env} is not specified, then the process environment is used.
*

View File

@@ -599,6 +599,7 @@ test.serial(
const nwo: RepositoryNwo = { owner: "test", repo: "foo" };
const language: BuiltInLanguage = BuiltInLanguage.java;
const env = getTestEnv();
await t.notThrowsAsync(async () => {
await uploadBundledDatabase(
nwo,
@@ -607,11 +608,14 @@ test.serial(
dbPath,
content.length,
SAMPLE_DOTCOM_API_DETAILS,
env,
);
});
// Check that our stubs were called and that they received the expected arguments.
t.is(getApiClient.callCount, 1);
t.deepEqual(getApiClient.args[0], [env, SAMPLE_DOTCOM_API_DETAILS]);
t.is(fetchStub.callCount, 1);
const args = fetchStub.args[0];

View File

@@ -10,6 +10,7 @@ import {
} from "./api-client";
import { type CodeQL } from "./codeql";
import { Config } from "./config-utils";
import type { ReadOnlyEnv } from "./environment";
import { Feature } from "./feature-flags";
import * as gitUtils from "./git-utils";
import { parseGitHubUrl } from "./github";
@@ -266,11 +267,12 @@ export async function uploadBundledDatabase(
bundledDb: string,
bundledDbSize: number,
apiDetails: GitHubApiDetails,
env: ReadOnlyEnv = util.getEnv(),
): Promise<number> {
// Ensure that the `apiDetails` that `getApiClient` uses match the ones we were given here,
// because we use `apiDetails.auth` below which must be used with the same instance that
// `apiDetails` refers to.
const client = getApiClient(util.getEnv(), apiDetails);
// It is important that the `apiDetails` that `getApiClient` uses match the ones we were given,
// because we use `apiDetails.url` below to construct the URL to upload the database to. That
// URL will be specific to the GitHub instance given by `apiDetails` and so the client must match it.
const client = getApiClient(env, apiDetails);
const uploadsUrl = new URL(parseGitHubUrl(apiDetails.url));
uploadsUrl.hostname = `uploads.${uploadsUrl.hostname}`;