diff --git a/extensions/ql-vscode/CHANGELOG.md b/extensions/ql-vscode/CHANGELOG.md index 8db43478011..dc089c86ca0 100644 --- a/extensions/ql-vscode/CHANGELOG.md +++ b/extensions/ql-vscode/CHANGELOG.md @@ -7,6 +7,7 @@ - Update variant analysis view to show when cancelation is in progress. [#3405](https://github.com/github/vscode-codeql/pull/3405) - Remove support for CodeQL CLI versions older than 2.13.5. [#3371](https://github.com/github/vscode-codeql/pull/3371) - Add a timeout to downloading databases and the CodeQL CLI. These can be changed using the `codeQL.addingDatabases.downloadTimeout` and `codeQL.cli.downloadTimeout` settings respectively. [#3373](https://github.com/github/vscode-codeql/pull/3373) +- When downloading a CodeQL database through the model editor, only use credentials when in canary mode. [#3440](https://github.com/github/vscode-codeql/pull/3440) ## 1.12.2 - 14 February 2024 diff --git a/extensions/ql-vscode/src/databases/database-fetcher.ts b/extensions/ql-vscode/src/databases/database-fetcher.ts index c9ccbdf09ae..7b66071c912 100644 --- a/extensions/ql-vscode/src/databases/database-fetcher.ts +++ b/extensions/ql-vscode/src/databases/database-fetcher.ts @@ -26,18 +26,19 @@ import { getNwoFromGitHubUrl, isValidGitHubNwo, } from "../common/github-url-identifier-helper"; -import type { Credentials } from "../common/authentication"; import type { AppCommandManager } from "../common/commands"; import { addDatabaseSourceToWorkspace, allowHttp, downloadTimeout, + isCanary, } from "../config"; import { showAndLogInformationMessage } from "../common/logging"; import { AppOctokit } from "../common/octokit"; import { getLanguageDisplayName } from "../common/query-language"; import type { DatabaseOrigin } from "./local-databases/database-origin"; import { createTimeoutSignal } from "../common/fetch-stream"; +import type { App } from "../common/app"; /** * Prompts a user to fetch a database from a remote location. Database is assumed to be an archive file. @@ -90,9 +91,9 @@ export async function promptImportInternetDatabase( * User enters a GitHub repository and then the user is asked which language * to download (if there is more than one) * + * @param app the App * @param databaseManager the DatabaseManager * @param storagePath where to store the unzipped database. - * @param credentials the credentials to use to authenticate with GitHub * @param progress the progress callback * @param cli the CodeQL CLI server * @param language the language to download. If undefined, the user will be prompted to choose a language. @@ -100,10 +101,9 @@ export async function promptImportInternetDatabase( * @param addSourceArchiveFolder whether to add a workspace folder containing the source archive to the workspace */ export async function promptImportGithubDatabase( - commandManager: AppCommandManager, + app: App, databaseManager: DatabaseManager, storagePath: string, - credentials: Credentials | undefined, progress: ProgressCallback, cli: CodeQLCliServer, language?: string, @@ -117,9 +117,9 @@ export async function promptImportGithubDatabase( const databaseItem = await downloadGitHubDatabase( githubRepo, + app, databaseManager, storagePath, - credentials, progress, cli, language, @@ -129,7 +129,7 @@ export async function promptImportGithubDatabase( if (databaseItem) { if (makeSelected) { - await commandManager.execute("codeQLDatabases.focus"); + await app.commands.execute("codeQLDatabases.focus"); } void showAndLogInformationMessage( extLogger, @@ -169,9 +169,9 @@ export async function askForGitHubRepo( * Downloads a database from GitHub * * @param githubRepo the GitHub repository to download the database from + * @param app the App * @param databaseManager the DatabaseManager * @param storagePath where to store the unzipped database. - * @param credentials the credentials to use to authenticate with GitHub * @param progress the progress callback * @param cli the CodeQL CLI server * @param language the language to download. If undefined, the user will be prompted to choose a language. @@ -180,9 +180,9 @@ export async function askForGitHubRepo( **/ export async function downloadGitHubDatabase( githubRepo: string, + app: App, databaseManager: DatabaseManager, storagePath: string, - credentials: Credentials | undefined, progress: ProgressCallback, cli: CodeQLCliServer, language?: string, @@ -194,6 +194,8 @@ export async function downloadGitHubDatabase( throw new Error(`Invalid GitHub repository: ${githubRepo}`); } + const credentials = isCanary() ? app.credentials : undefined; + const octokit = credentials ? await credentials.getOctokit() : new AppOctokit(); diff --git a/extensions/ql-vscode/src/databases/local-databases-ui.ts b/extensions/ql-vscode/src/databases/local-databases-ui.ts index 70f4c6eefcf..c5230ce72cb 100644 --- a/extensions/ql-vscode/src/databases/local-databases-ui.ts +++ b/extensions/ql-vscode/src/databases/local-databases-ui.ts @@ -49,7 +49,6 @@ import { } from "./database-fetcher"; import { asError, asyncFilter, getErrorMessage } from "../common/helpers-pure"; import type { QueryRunner } from "../query-server"; -import { isCanary } from "../config"; import type { App } from "../common/app"; import { redactableError } from "../common/errors"; import type { LocalDatabasesCommands } from "../common/commands"; @@ -558,13 +557,10 @@ export class DatabaseUI extends DisposableObject { private async handleChooseDatabaseGithub(): Promise { return withProgress( async (progress) => { - const credentials = isCanary() ? this.app.credentials : undefined; - await promptImportGithubDatabase( - this.app.commands, + this.app, this.databaseManager, this.storagePath, - credentials, progress, this.queryServer.cliServer, ); diff --git a/extensions/ql-vscode/src/local-queries/local-queries.ts b/extensions/ql-vscode/src/local-queries/local-queries.ts index 5387c9e21df..ddc29db949b 100644 --- a/extensions/ql-vscode/src/local-queries/local-queries.ts +++ b/extensions/ql-vscode/src/local-queries/local-queries.ts @@ -10,7 +10,7 @@ import { showAndLogErrorMessage, showAndLogWarningMessage, } from "../common/logging"; -import { isCanary, MAX_QUERIES } from "../config"; +import { MAX_QUERIES } from "../config"; import { gatherQlFiles } from "../common/files"; import { basename } from "path"; import { showBinaryChoiceDialog } from "../common/vscode/dialog"; @@ -322,14 +322,12 @@ export class LocalQueries extends DisposableObject { private async createSkeletonQuery(): Promise { await withProgress( async (progress: ProgressCallback) => { - const credentials = isCanary() ? this.app.credentials : undefined; const contextStoragePath = this.app.workspaceStoragePath || this.app.globalStoragePath; const language = this.languageContextStore.selectedLanguage; const skeletonQueryWizard = new SkeletonQueryWizard( this.cliServer, progress, - credentials, this.app, this.databaseManager, contextStoragePath, diff --git a/extensions/ql-vscode/src/local-queries/skeleton-query-wizard.ts b/extensions/ql-vscode/src/local-queries/skeleton-query-wizard.ts index 61a7de920a6..0079709bbf6 100644 --- a/extensions/ql-vscode/src/local-queries/skeleton-query-wizard.ts +++ b/extensions/ql-vscode/src/local-queries/skeleton-query-wizard.ts @@ -2,7 +2,6 @@ import { dirname, join } from "path"; import { Uri, window, window as Window, workspace } from "vscode"; import type { CodeQLCliServer } from "../codeql-cli/cli"; import { showAndLogExceptionWithTelemetry } from "../common/logging"; -import type { Credentials } from "../common/authentication"; import type { QueryLanguage } from "../common/query-language"; import { getLanguageDisplayName } from "../common/query-language"; import { @@ -61,7 +60,6 @@ export class SkeletonQueryWizard { constructor( private readonly cliServer: CodeQLCliServer, private readonly progress: ProgressCallback, - private readonly credentials: Credentials | undefined, private readonly app: App, private readonly databaseManager: DatabaseManager, private readonly databaseStoragePath: string | undefined, @@ -388,9 +386,9 @@ export class SkeletonQueryWizard { await downloadGitHubDatabase( chosenRepo, + this.app, this.databaseManager, this.databaseStoragePath, - this.credentials, progress, this.cliServer, this.language, diff --git a/extensions/ql-vscode/src/model-editor/model-editor-view.ts b/extensions/ql-vscode/src/model-editor/model-editor-view.ts index 2328e3cb44a..0ad90435813 100644 --- a/extensions/ql-vscode/src/model-editor/model-editor-view.ts +++ b/extensions/ql-vscode/src/model-editor/model-editor-view.ts @@ -917,10 +917,9 @@ export class ModelEditorView extends AbstractWebview< // imported to the query server, so we need to register it to our workspace. const makeSelected = false; const addedDatabase = await promptImportGithubDatabase( - this.app.commands, + this.app, this.databaseManager, this.app.workspaceStoragePath ?? this.app.globalStoragePath, - this.app.credentials, progress, this.cliServer, this.databaseItem.language, diff --git a/extensions/ql-vscode/test/vscode-tests/cli-integration/local-queries/skeleton-query-wizard.test.ts b/extensions/ql-vscode/test/vscode-tests/cli-integration/local-queries/skeleton-query-wizard.test.ts index d976a008e95..7f4c6d8e2b3 100644 --- a/extensions/ql-vscode/test/vscode-tests/cli-integration/local-queries/skeleton-query-wizard.test.ts +++ b/extensions/ql-vscode/test/vscode-tests/cli-integration/local-queries/skeleton-query-wizard.test.ts @@ -18,7 +18,6 @@ import { removeSync, } from "fs-extra"; import { dirname, join } from "path"; -import { testCredentialsWithStub } from "../../../factories/authentication"; import type { DatabaseItem, DatabaseManager, @@ -69,7 +68,6 @@ describe("SkeletonQueryWizard", () => { typeof CodeQLCliServer.prototype.resolveQlpacks >; - const credentials = testCredentialsWithStub(); const chosenLanguage = "ruby"; const selectedItems: QueryTreeViewItem[] = []; @@ -145,7 +143,6 @@ describe("SkeletonQueryWizard", () => { wizard = new SkeletonQueryWizard( mockCli, jest.fn(), - credentials, mockApp, mockDatabaseManager, storagePath, @@ -173,7 +170,6 @@ describe("SkeletonQueryWizard", () => { wizard = new SkeletonQueryWizard( mockCli, jest.fn(), - credentials, mockApp, mockDatabaseManager, storagePath, @@ -322,7 +318,6 @@ describe("SkeletonQueryWizard", () => { wizard = new SkeletonQueryWizard( mockCli, jest.fn(), - credentials, mockApp, mockDatabaseManagerWithItems, storagePath, @@ -372,7 +367,6 @@ describe("SkeletonQueryWizard", () => { wizard = new SkeletonQueryWizard( mockCli, jest.fn(), - credentials, mockApp, mockDatabaseManagerWithItems, storagePath, @@ -508,7 +502,6 @@ describe("SkeletonQueryWizard", () => { wizard = new SkeletonQueryWizard( mockCli, jest.fn(), - credentials, mockApp, mockDatabaseManager, storagePath, @@ -730,7 +723,6 @@ describe("SkeletonQueryWizard", () => { wizard = new SkeletonQueryWizard( mockCli, jest.fn(), - credentials, mockApp, mockDatabaseManager, storagePath, @@ -760,7 +752,6 @@ describe("SkeletonQueryWizard", () => { wizard = new SkeletonQueryWizard( mockCli, jest.fn(), - credentials, mockApp, mockDatabaseManager, storagePath, @@ -794,7 +785,6 @@ describe("SkeletonQueryWizard", () => { wizard = new SkeletonQueryWizard( mockCli, jest.fn(), - credentials, mockApp, mockDatabaseManager, storagePath, @@ -838,7 +828,6 @@ describe("SkeletonQueryWizard", () => { wizard = new SkeletonQueryWizard( mockCli, jest.fn(), - credentials, mockApp, mockDatabaseManager, storagePath,