From 1c350b15646af18665019ea3b44b422207d684a1 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Fri, 16 Oct 2026 12:36:22 +0100 Subject: [PATCH] Address feedback from previous PR --- lib/entry-points.js | 4 ++-- src/api-client.ts | 4 ++-- src/database-upload.test.ts | 4 ++++ src/database-upload.ts | 10 ++++++---- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/entry-points.js b/lib/entry-points.js index e305218d1..78a477cdf 100644 --- a/lib/entry-points.js +++ b/lib/entry-points.js @@ -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(); diff --git a/src/api-client.ts b/src/api-client.ts index c37414f3e..248858cbc 100644 --- a/src/api-client.ts +++ b/src/api-client.ts @@ -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. * diff --git a/src/database-upload.test.ts b/src/database-upload.test.ts index 908994112..63b982daa 100644 --- a/src/database-upload.test.ts +++ b/src/database-upload.test.ts @@ -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]; diff --git a/src/database-upload.ts b/src/database-upload.ts index 2a24a2e1d..67f0edccc 100644 --- a/src/database-upload.ts +++ b/src/database-upload.ts @@ -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 { - // 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}`;