Skip to content

Commit 1c350b1

Browse files
committed
Address feedback from previous PR
1 parent 1772d44 commit 1c350b1

4 files changed

Lines changed: 14 additions & 8 deletions

File tree

‎lib/entry-points.js‎

Lines changed: 2 additions & 2 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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ export function getApiDetails(env: ReadOnlyEnv = getEnv()): GitHubApiDetails {
229229
/**
230230
* Constructs an {@link ApiClient} using {@link apiDetails}.
231231
*
232-
* If {@link apiDetails} is not specified, then the GitHub instance URLs and auth token
233-
* are taken from {@link env}.
232+
* If {@link apiDetails} is not specified, then the GitHub instance URLs are taken from {@link env}
233+
* and the auth token is taken from the `token` input.
234234
*
235235
* If {@link env} is not specified, then the process environment is used.
236236
*

‎src/database-upload.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,7 @@ test.serial(
599599
const nwo: RepositoryNwo = { owner: "test", repo: "foo" };
600600
const language: BuiltInLanguage = BuiltInLanguage.java;
601601

602+
const env = getTestEnv();
602603
await t.notThrowsAsync(async () => {
603604
await uploadBundledDatabase(
604605
nwo,
@@ -607,11 +608,14 @@ test.serial(
607608
dbPath,
608609
content.length,
609610
SAMPLE_DOTCOM_API_DETAILS,
611+
env,
610612
);
611613
});
612614

613615
// Check that our stubs were called and that they received the expected arguments.
614616
t.is(getApiClient.callCount, 1);
617+
t.deepEqual(getApiClient.args[0], [env, SAMPLE_DOTCOM_API_DETAILS]);
618+
615619
t.is(fetchStub.callCount, 1);
616620

617621
const args = fetchStub.args[0];

‎src/database-upload.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
} from "./api-client";
1111
import { type CodeQL } from "./codeql";
1212
import { Config } from "./config-utils";
13+
import type { ReadOnlyEnv } from "./environment";
1314
import { Feature } from "./feature-flags";
1415
import * as gitUtils from "./git-utils";
1516
import { parseGitHubUrl } from "./github";
@@ -266,11 +267,12 @@ export async function uploadBundledDatabase(
266267
bundledDb: string,
267268
bundledDbSize: number,
268269
apiDetails: GitHubApiDetails,
270+
env: ReadOnlyEnv = util.getEnv(),
269271
): Promise<number> {
270-
// Ensure that the `apiDetails` that `getApiClient` uses match the ones we were given here,
271-
// because we use `apiDetails.auth` below which must be used with the same instance that
272-
// `apiDetails` refers to.
273-
const client = getApiClient(util.getEnv(), apiDetails);
272+
// It is important that the `apiDetails` that `getApiClient` uses match the ones we were given,
273+
// because we use `apiDetails.url` below to construct the URL to upload the database to. That
274+
// URL will be specific to the GitHub instance given by `apiDetails` and so the client must match it.
275+
const client = getApiClient(env, apiDetails);
274276

275277
const uploadsUrl = new URL(parseGitHubUrl(apiDetails.url));
276278
uploadsUrl.hostname = `uploads.${uploadsUrl.hostname}`;

0 commit comments

Comments
 (0)