diff --git a/extensions/ql-vscode/package.json b/extensions/ql-vscode/package.json index 2af45ba19..650f19780 100644 --- a/extensions/ql-vscode/package.json +++ b/extensions/ql-vscode/package.json @@ -878,6 +878,10 @@ } ], "commandPalette": [ + { + "command": "codeQL.authenticateToGitHub", + "when": "config.codeQL.canary" + }, { "command": "codeQL.runQuery", "when": "resourceLangId == ql && resourceExtname == .ql" diff --git a/extensions/ql-vscode/src/databaseFetcher.ts b/extensions/ql-vscode/src/databaseFetcher.ts index a78ba34cd..322d09b3a 100644 --- a/extensions/ql-vscode/src/databaseFetcher.ts +++ b/extensions/ql-vscode/src/databaseFetcher.ts @@ -11,6 +11,7 @@ import { CodeQLCliServer } from './cli'; import * as fs from 'fs-extra'; import * as path from 'path'; import * as Octokit from '@octokit/rest'; +import { retry } from '@octokit/plugin-retry'; import { DatabaseManager, DatabaseItem } from './databases'; import { @@ -24,7 +25,6 @@ import { logger } from './logging'; import { tmpDir } from './helpers'; import { Credentials } from './authentication'; import { REPO_REGEX, getErrorMessage } from './pure/helpers-pure'; -import { isCanary } from './config'; /** * Prompts a user to fetch a database from a remote location. Database is assumed to be an archive file. @@ -78,7 +78,7 @@ export async function promptImportInternetDatabase( export async function promptImportGithubDatabase( databaseManager: DatabaseManager, storagePath: string, - credentials: Credentials, + credentials: Credentials | undefined, progress: ProgressCallback, token: CancellationToken, cli?: CodeQLCliServer @@ -101,8 +101,7 @@ export async function promptImportGithubDatabase( throw new Error(`Invalid GitHub repository: ${githubRepo}`); } - // Only require authentication if we are running with the canary flag enabled - const octokit = await credentials.getOctokit(isCanary()); + const octokit = credentials ? await credentials.getOctokit(true) : new Octokit.Octokit({ retry }); const result = await convertGithubNwoToDatabaseUrl(githubRepo, octokit, progress); if (!result) { diff --git a/extensions/ql-vscode/src/databases-ui.ts b/extensions/ql-vscode/src/databases-ui.ts index cf474bfc5..bea2bc425 100644 --- a/extensions/ql-vscode/src/databases-ui.ts +++ b/extensions/ql-vscode/src/databases-ui.ts @@ -40,6 +40,7 @@ import { import { CancellationToken } from 'vscode'; import { asyncFilter, getErrorMessage } from './pure/helpers-pure'; import { Credentials } from './authentication'; +import { isCanary } from './config'; type ThemableIconPath = { light: string; dark: string } | string; @@ -301,7 +302,7 @@ export class DatabaseUI extends DisposableObject { progress: ProgressCallback, token: CancellationToken ) => { - const credentials = await this.getCredentials(); + const credentials = isCanary() ? await this.getCredentials() : undefined; await this.handleChooseDatabaseGithub(credentials, progress, token); }, { @@ -480,7 +481,7 @@ export class DatabaseUI extends DisposableObject { }; handleChooseDatabaseGithub = async ( - credentials: Credentials, + credentials: Credentials | undefined, progress: ProgressCallback, token: CancellationToken ): Promise => { diff --git a/extensions/ql-vscode/src/extension.ts b/extensions/ql-vscode/src/extension.ts index 43109b93b..80c04dbbc 100644 --- a/extensions/ql-vscode/src/extension.ts +++ b/extensions/ql-vscode/src/extension.ts @@ -970,7 +970,7 @@ async function activateWithInstalledDistribution( progress: ProgressCallback, token: CancellationToken ) => { - const credentials = await Credentials.initialize(ctx); + const credentials = isCanary() ? await Credentials.initialize(ctx) : undefined; await databaseUI.handleChooseDatabaseGithub(credentials, progress, token); }, {