Move commonly-used field to DatabaseFetcher constructor
This commit is contained in:
@@ -26,7 +26,6 @@ import {
|
||||
getNwoFromGitHubUrl,
|
||||
isValidGitHubNwo,
|
||||
} from "../common/github-url-identifier-helper";
|
||||
import type { AppCommandManager } from "../common/commands";
|
||||
import {
|
||||
addDatabaseSourceToWorkspace,
|
||||
allowHttp,
|
||||
@@ -48,17 +47,23 @@ const DUPLICATE_FILENAMES_TRIES = 10_000;
|
||||
|
||||
export class DatabaseFetcher {
|
||||
/**
|
||||
* Prompts a user to fetch a database from a remote location. Database is assumed to be an archive file.
|
||||
*
|
||||
* @param app the App
|
||||
* @param databaseManager the DatabaseManager
|
||||
* @param storagePath where to store the unzipped database.
|
||||
* @param cli the CodeQL CLI server
|
||||
**/
|
||||
constructor(
|
||||
private readonly app: App,
|
||||
private readonly databaseManager: DatabaseManager,
|
||||
private readonly storagePath: string,
|
||||
private readonly cli: CodeQLCliServer,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Prompts a user to fetch a database from a remote location. Database is assumed to be an archive file.
|
||||
*/
|
||||
public async promptImportInternetDatabase(
|
||||
commandManager: AppCommandManager,
|
||||
databaseManager: DatabaseManager,
|
||||
storagePath: string,
|
||||
progress: ProgressCallback,
|
||||
cli: CodeQLCliServer,
|
||||
): Promise<DatabaseItem | undefined> {
|
||||
const databaseUrl = await window.showInputBox({
|
||||
prompt: "Enter URL of zipfile of database to download",
|
||||
@@ -72,19 +77,16 @@ export class DatabaseFetcher {
|
||||
const item = await this.databaseArchiveFetcher(
|
||||
databaseUrl,
|
||||
{},
|
||||
databaseManager,
|
||||
storagePath,
|
||||
undefined,
|
||||
{
|
||||
type: "url",
|
||||
url: databaseUrl,
|
||||
},
|
||||
progress,
|
||||
cli,
|
||||
);
|
||||
|
||||
if (item) {
|
||||
await commandManager.execute("codeQLDatabases.focus");
|
||||
await this.app.commands.execute("codeQLDatabases.focus");
|
||||
void showAndLogInformationMessage(
|
||||
extLogger,
|
||||
"Database downloaded and imported successfully.",
|
||||
@@ -98,21 +100,13 @@ export class DatabaseFetcher {
|
||||
* 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 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.
|
||||
* @param makeSelected make the new database selected in the databases panel (default: true)
|
||||
* @param addSourceArchiveFolder whether to add a workspace folder containing the source archive to the workspace
|
||||
*/
|
||||
public async promptImportGithubDatabase(
|
||||
app: App,
|
||||
databaseManager: DatabaseManager,
|
||||
storagePath: string,
|
||||
progress: ProgressCallback,
|
||||
cli: CodeQLCliServer,
|
||||
language?: string,
|
||||
makeSelected = true,
|
||||
addSourceArchiveFolder = addDatabaseSourceToWorkspace(),
|
||||
@@ -124,11 +118,7 @@ export class DatabaseFetcher {
|
||||
|
||||
const databaseItem = await this.downloadGitHubDatabase(
|
||||
githubRepo,
|
||||
app,
|
||||
databaseManager,
|
||||
storagePath,
|
||||
progress,
|
||||
cli,
|
||||
language,
|
||||
makeSelected,
|
||||
addSourceArchiveFolder,
|
||||
@@ -136,7 +126,7 @@ export class DatabaseFetcher {
|
||||
|
||||
if (databaseItem) {
|
||||
if (makeSelected) {
|
||||
await app.commands.execute("codeQLDatabases.focus");
|
||||
await this.app.commands.execute("codeQLDatabases.focus");
|
||||
}
|
||||
void showAndLogInformationMessage(
|
||||
extLogger,
|
||||
@@ -176,22 +166,14 @@ export class DatabaseFetcher {
|
||||
* 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 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.
|
||||
* @param makeSelected make the new database selected in the databases panel (default: true)
|
||||
* @param addSourceArchiveFolder whether to add a workspace folder containing the source archive to the workspace
|
||||
**/
|
||||
public async downloadGitHubDatabase(
|
||||
githubRepo: string,
|
||||
app: App,
|
||||
databaseManager: DatabaseManager,
|
||||
storagePath: string,
|
||||
progress: ProgressCallback,
|
||||
cli: CodeQLCliServer,
|
||||
language?: string,
|
||||
makeSelected = true,
|
||||
addSourceArchiveFolder = addDatabaseSourceToWorkspace(),
|
||||
@@ -201,7 +183,7 @@ export class DatabaseFetcher {
|
||||
throw new Error(`Invalid GitHub repository: ${githubRepo}`);
|
||||
}
|
||||
|
||||
const credentials = isCanary() ? app.credentials : undefined;
|
||||
const credentials = isCanary() ? this.app.credentials : undefined;
|
||||
|
||||
const octokit = credentials
|
||||
? await credentials.getOctokit()
|
||||
@@ -235,9 +217,6 @@ export class DatabaseFetcher {
|
||||
name,
|
||||
octokit,
|
||||
progress,
|
||||
databaseManager,
|
||||
storagePath,
|
||||
cli,
|
||||
makeSelected,
|
||||
addSourceArchiveFolder,
|
||||
);
|
||||
@@ -252,9 +231,6 @@ export class DatabaseFetcher {
|
||||
name: string,
|
||||
octokit: Octokit,
|
||||
progress: ProgressCallback,
|
||||
databaseManager: DatabaseManager,
|
||||
storagePath: string,
|
||||
cli: CodeQLCliServer,
|
||||
makeSelected = true,
|
||||
addSourceArchiveFolder = true,
|
||||
): Promise<DatabaseItem | undefined> {
|
||||
@@ -275,8 +251,6 @@ export class DatabaseFetcher {
|
||||
Accept: "application/zip",
|
||||
Authorization: octokitToken ? `Bearer ${octokitToken}` : "",
|
||||
},
|
||||
databaseManager,
|
||||
storagePath,
|
||||
`${owner}/${name}`,
|
||||
{
|
||||
type: "github",
|
||||
@@ -286,7 +260,6 @@ export class DatabaseFetcher {
|
||||
commitOid,
|
||||
},
|
||||
progress,
|
||||
cli,
|
||||
makeSelected,
|
||||
addSourceArchiveFolder,
|
||||
);
|
||||
@@ -296,34 +269,24 @@ export class DatabaseFetcher {
|
||||
* Imports a database from a local archive.
|
||||
*
|
||||
* @param databaseUrl the file url of the archive to import
|
||||
* @param databaseManager the DatabaseManager
|
||||
* @param storagePath where to store the unzipped database.
|
||||
* @param cli the CodeQL CLI server
|
||||
*/
|
||||
public async importArchiveDatabase(
|
||||
commandManager: AppCommandManager,
|
||||
databaseUrl: string,
|
||||
databaseManager: DatabaseManager,
|
||||
storagePath: string,
|
||||
progress: ProgressCallback,
|
||||
cli: CodeQLCliServer,
|
||||
): Promise<DatabaseItem | undefined> {
|
||||
try {
|
||||
const item = await this.databaseArchiveFetcher(
|
||||
databaseUrl,
|
||||
{},
|
||||
databaseManager,
|
||||
storagePath,
|
||||
undefined,
|
||||
{
|
||||
type: "archive",
|
||||
path: databaseUrl,
|
||||
},
|
||||
progress,
|
||||
cli,
|
||||
);
|
||||
if (item) {
|
||||
await commandManager.execute("codeQLDatabases.focus");
|
||||
await this.app.commands.execute("codeQLDatabases.focus");
|
||||
void showAndLogInformationMessage(
|
||||
extLogger,
|
||||
"Database unzipped and imported successfully.",
|
||||
@@ -348,24 +311,18 @@ export class DatabaseFetcher {
|
||||
*
|
||||
* @param databaseUrl URL from which to grab the database
|
||||
* @param requestHeaders Headers to send with the request
|
||||
* @param databaseManager the DatabaseManager
|
||||
* @param storagePath where to store the unzipped database.
|
||||
* @param nameOverride a name for the database that overrides the default
|
||||
* @param origin the origin of the database
|
||||
* @param progress callback to send progress messages to
|
||||
* @param cli the CodeQL CLI server
|
||||
* @param makeSelected make the new database selected in the databases panel (default: true)
|
||||
* @param addSourceArchiveFolder whether to add a workspace folder containing the source archive to the workspace
|
||||
*/
|
||||
private async databaseArchiveFetcher(
|
||||
databaseUrl: string,
|
||||
requestHeaders: { [key: string]: string },
|
||||
databaseManager: DatabaseManager,
|
||||
storagePath: string,
|
||||
nameOverride: string | undefined,
|
||||
origin: DatabaseOrigin,
|
||||
progress: ProgressCallback,
|
||||
cli: CodeQLCliServer,
|
||||
makeSelected = true,
|
||||
addSourceArchiveFolder = addDatabaseSourceToWorkspace(),
|
||||
): Promise<DatabaseItem> {
|
||||
@@ -374,24 +331,19 @@ export class DatabaseFetcher {
|
||||
step: 1,
|
||||
maxStep: 4,
|
||||
});
|
||||
if (!storagePath) {
|
||||
if (!this.storagePath) {
|
||||
throw new Error("No storage path specified.");
|
||||
}
|
||||
await ensureDir(storagePath);
|
||||
const unzipPath = await this.getStorageFolder(
|
||||
storagePath,
|
||||
databaseUrl,
|
||||
nameOverride,
|
||||
);
|
||||
await ensureDir(this.storagePath);
|
||||
const unzipPath = await this.getStorageFolder(databaseUrl, nameOverride);
|
||||
|
||||
if (this.isFile(databaseUrl)) {
|
||||
await this.readAndUnzip(databaseUrl, unzipPath, cli, progress);
|
||||
await this.readAndUnzip(databaseUrl, unzipPath, progress);
|
||||
} else {
|
||||
await this.fetchAndUnzip(
|
||||
databaseUrl,
|
||||
requestHeaders,
|
||||
unzipPath,
|
||||
cli,
|
||||
progress,
|
||||
);
|
||||
}
|
||||
@@ -416,7 +368,7 @@ export class DatabaseFetcher {
|
||||
});
|
||||
await this.ensureZippedSourceLocation(dbPath);
|
||||
|
||||
const item = await databaseManager.openDatabase(
|
||||
const item = await this.databaseManager.openDatabase(
|
||||
Uri.file(dbPath),
|
||||
origin,
|
||||
makeSelected,
|
||||
@@ -432,11 +384,7 @@ export class DatabaseFetcher {
|
||||
}
|
||||
}
|
||||
|
||||
private async getStorageFolder(
|
||||
storagePath: string,
|
||||
urlStr: string,
|
||||
nameOverrride?: string,
|
||||
) {
|
||||
private async getStorageFolder(urlStr: string, nameOverrride?: string) {
|
||||
let lastName: string;
|
||||
|
||||
if (nameOverrride) {
|
||||
@@ -454,7 +402,7 @@ export class DatabaseFetcher {
|
||||
}
|
||||
}
|
||||
|
||||
const realpath = await fs_realpath(storagePath);
|
||||
const realpath = await fs_realpath(this.storagePath);
|
||||
let folderName = lastName;
|
||||
|
||||
// get all existing files instead of calling pathExists on every
|
||||
@@ -500,7 +448,6 @@ export class DatabaseFetcher {
|
||||
private async readAndUnzip(
|
||||
zipUrl: string,
|
||||
unzipPath: string,
|
||||
cli: CodeQLCliServer,
|
||||
progress?: ProgressCallback,
|
||||
) {
|
||||
const zipFile = Uri.parse(zipUrl).fsPath;
|
||||
@@ -510,14 +457,13 @@ export class DatabaseFetcher {
|
||||
message: `Unzipping into ${basename(unzipPath)}`,
|
||||
});
|
||||
|
||||
await cli.databaseUnbundle(zipFile, unzipPath);
|
||||
await this.cli.databaseUnbundle(zipFile, unzipPath);
|
||||
}
|
||||
|
||||
private async fetchAndUnzip(
|
||||
databaseUrl: string,
|
||||
requestHeaders: { [key: string]: string },
|
||||
unzipPath: string,
|
||||
cli: CodeQLCliServer,
|
||||
progress?: ProgressCallback,
|
||||
) {
|
||||
// Although it is possible to download and stream directly to an unzipped directory,
|
||||
@@ -606,7 +552,6 @@ export class DatabaseFetcher {
|
||||
await this.readAndUnzip(
|
||||
Uri.file(archivePath).toString(true),
|
||||
unzipPath,
|
||||
cli,
|
||||
progress,
|
||||
);
|
||||
|
||||
|
||||
@@ -4,8 +4,6 @@ import { showNeverAskAgainDialog } from "../../common/vscode/dialog";
|
||||
import { getLanguageDisplayName } from "../../common/query-language";
|
||||
import type { DatabaseFetcher } from "../database-fetcher";
|
||||
import { withProgress } from "../../common/vscode/progress";
|
||||
import type { DatabaseManager } from "../local-databases";
|
||||
import type { CodeQLCliServer } from "../../codeql-cli/cli";
|
||||
import type { AppCommandManager } from "../../common/commands";
|
||||
import type { GitHubDatabaseConfig } from "../../config";
|
||||
import type { CodeqlDatabase } from "./api";
|
||||
@@ -58,10 +56,7 @@ export async function downloadDatabaseFromGitHub(
|
||||
owner: string,
|
||||
repo: string,
|
||||
databases: CodeqlDatabase[],
|
||||
databaseManager: DatabaseManager,
|
||||
databaseFetcher: DatabaseFetcher,
|
||||
storagePath: string,
|
||||
cliServer: CodeQLCliServer,
|
||||
commandManager: AppCommandManager,
|
||||
): Promise<void> {
|
||||
const selectedDatabases = await promptForDatabases(databases);
|
||||
@@ -82,9 +77,6 @@ export async function downloadDatabaseFromGitHub(
|
||||
repo,
|
||||
octokit,
|
||||
progress,
|
||||
databaseManager,
|
||||
storagePath,
|
||||
cliServer,
|
||||
true,
|
||||
false,
|
||||
);
|
||||
|
||||
@@ -14,7 +14,6 @@ import {
|
||||
} from "./download";
|
||||
import type { GitHubDatabaseConfig } from "../../config";
|
||||
import type { DatabaseManager } from "../local-databases";
|
||||
import type { CodeQLCliServer } from "../../codeql-cli/cli";
|
||||
import type { CodeqlDatabase, ListDatabasesResult } from "./api";
|
||||
import { listDatabases } from "./api";
|
||||
import type { DatabaseUpdate } from "./updates";
|
||||
@@ -35,8 +34,6 @@ export class GitHubDatabasesModule extends DisposableObject {
|
||||
private readonly app: App,
|
||||
private readonly databaseManager: DatabaseManager,
|
||||
private readonly databaseFetcher: DatabaseFetcher,
|
||||
private readonly databaseStoragePath: string,
|
||||
private readonly cliServer: CodeQLCliServer,
|
||||
private readonly config: GitHubDatabaseConfig,
|
||||
) {
|
||||
super();
|
||||
@@ -46,16 +43,12 @@ export class GitHubDatabasesModule extends DisposableObject {
|
||||
app: App,
|
||||
databaseManager: DatabaseManager,
|
||||
databaseFetcher: DatabaseFetcher,
|
||||
databaseStoragePath: string,
|
||||
cliServer: CodeQLCliServer,
|
||||
config: GitHubDatabaseConfig,
|
||||
): Promise<GitHubDatabasesModule> {
|
||||
const githubDatabasesModule = new GitHubDatabasesModule(
|
||||
app,
|
||||
databaseManager,
|
||||
databaseFetcher,
|
||||
databaseStoragePath,
|
||||
cliServer,
|
||||
config,
|
||||
);
|
||||
app.subscriptions.push(githubDatabasesModule);
|
||||
@@ -189,10 +182,7 @@ export class GitHubDatabasesModule extends DisposableObject {
|
||||
owner,
|
||||
repo,
|
||||
databases,
|
||||
this.databaseManager,
|
||||
this.databaseFetcher,
|
||||
this.databaseStoragePath,
|
||||
this.cliServer,
|
||||
this.app.commands,
|
||||
);
|
||||
}
|
||||
@@ -218,8 +208,6 @@ export class GitHubDatabasesModule extends DisposableObject {
|
||||
databaseUpdates,
|
||||
this.databaseManager,
|
||||
this.databaseFetcher,
|
||||
this.databaseStoragePath,
|
||||
this.cliServer,
|
||||
this.app.commands,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { CodeqlDatabase } from "./api";
|
||||
import type { DatabaseItem, DatabaseManager } from "../local-databases";
|
||||
import type { Octokit } from "@octokit/rest";
|
||||
import type { CodeQLCliServer } from "../../codeql-cli/cli";
|
||||
import type { AppCommandManager } from "../../common/commands";
|
||||
import { getLanguageDisplayName } from "../../common/query-language";
|
||||
import { showNeverAskAgainDialog } from "../../common/vscode/dialog";
|
||||
@@ -157,8 +156,6 @@ export async function downloadDatabaseUpdateFromGitHub(
|
||||
updates: DatabaseUpdate[],
|
||||
databaseManager: DatabaseManager,
|
||||
databaseFetcher: DatabaseFetcher,
|
||||
storagePath: string,
|
||||
cliServer: CodeQLCliServer,
|
||||
commandManager: AppCommandManager,
|
||||
): Promise<void> {
|
||||
const selectedDatabases = await promptForDatabases(
|
||||
@@ -190,9 +187,6 @@ export async function downloadDatabaseUpdateFromGitHub(
|
||||
repo,
|
||||
octokit,
|
||||
progress,
|
||||
databaseManager,
|
||||
storagePath,
|
||||
cliServer,
|
||||
databaseManager.currentDatabaseItem === update.databaseItem,
|
||||
update.databaseItem.hasSourceArchiveInExplorer(),
|
||||
);
|
||||
|
||||
@@ -536,13 +536,13 @@ export class DatabaseUI extends DisposableObject {
|
||||
private async handleChooseDatabaseInternet(): Promise<void> {
|
||||
return withProgress(
|
||||
async (progress) => {
|
||||
await new DatabaseFetcher().promptImportInternetDatabase(
|
||||
this.app.commands,
|
||||
const databaseFetcher = new DatabaseFetcher(
|
||||
this.app,
|
||||
this.databaseManager,
|
||||
this.storagePath,
|
||||
progress,
|
||||
this.queryServer.cliServer,
|
||||
);
|
||||
await databaseFetcher.promptImportInternetDatabase(progress);
|
||||
},
|
||||
{
|
||||
title: "Adding database from URL",
|
||||
@@ -553,13 +553,13 @@ export class DatabaseUI extends DisposableObject {
|
||||
private async handleChooseDatabaseGithub(): Promise<void> {
|
||||
return withProgress(
|
||||
async (progress) => {
|
||||
await new DatabaseFetcher().promptImportGithubDatabase(
|
||||
const databaseFetcher = new DatabaseFetcher(
|
||||
this.app,
|
||||
this.databaseManager,
|
||||
this.storagePath,
|
||||
progress,
|
||||
this.queryServer.cliServer,
|
||||
);
|
||||
await databaseFetcher.promptImportGithubDatabase(progress);
|
||||
},
|
||||
{
|
||||
title: "Adding database from GitHub",
|
||||
@@ -708,14 +708,16 @@ export class DatabaseUI extends DisposableObject {
|
||||
try {
|
||||
// Assume user has selected an archive if the file has a .zip extension
|
||||
if (uri.path.endsWith(".zip")) {
|
||||
await new DatabaseFetcher().importArchiveDatabase(
|
||||
this.app.commands,
|
||||
uri.toString(true),
|
||||
const databaseFetcher = new DatabaseFetcher(
|
||||
this.app,
|
||||
this.databaseManager,
|
||||
this.storagePath,
|
||||
progress,
|
||||
this.queryServer.cliServer,
|
||||
);
|
||||
await databaseFetcher.importArchiveDatabase(
|
||||
uri.toString(true),
|
||||
progress,
|
||||
);
|
||||
} else {
|
||||
await this.databaseManager.openDatabase(uri, {
|
||||
type: "folder",
|
||||
@@ -955,14 +957,16 @@ export class DatabaseUI extends DisposableObject {
|
||||
} else {
|
||||
// we are selecting a database archive. Must unzip into a workspace-controlled area
|
||||
// before importing.
|
||||
return await new DatabaseFetcher().importArchiveDatabase(
|
||||
this.app.commands,
|
||||
uri.toString(true),
|
||||
const databaseFetcher = new DatabaseFetcher(
|
||||
this.app,
|
||||
this.databaseManager,
|
||||
this.storagePath,
|
||||
progress,
|
||||
this.queryServer.cliServer,
|
||||
);
|
||||
return await databaseFetcher.importArchiveDatabase(
|
||||
uri.toString(true),
|
||||
progress,
|
||||
);
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@@ -882,9 +882,7 @@ async function activateWithInstalledDistribution(
|
||||
await GitHubDatabasesModule.initialize(
|
||||
app,
|
||||
dbm,
|
||||
new DatabaseFetcher(),
|
||||
getContextStoragePath(ctx),
|
||||
cliServer,
|
||||
new DatabaseFetcher(app, dbm, getContextStoragePath(ctx), cliServer),
|
||||
githubDatabaseConfigListener,
|
||||
);
|
||||
|
||||
|
||||
@@ -326,13 +326,18 @@ export class LocalQueries extends DisposableObject {
|
||||
const contextStoragePath =
|
||||
this.app.workspaceStoragePath || this.app.globalStoragePath;
|
||||
const language = this.languageContextStore.selectedLanguage;
|
||||
const databaseFetcher = new DatabaseFetcher(
|
||||
this.app,
|
||||
this.databaseManager,
|
||||
contextStoragePath,
|
||||
this.cliServer,
|
||||
);
|
||||
const skeletonQueryWizard = new SkeletonQueryWizard(
|
||||
this.cliServer,
|
||||
progress,
|
||||
this.app,
|
||||
this.databaseManager,
|
||||
new DatabaseFetcher(),
|
||||
contextStoragePath,
|
||||
databaseFetcher,
|
||||
this.selectedQueryTreeViewItems,
|
||||
language,
|
||||
);
|
||||
|
||||
@@ -60,7 +60,6 @@ export class SkeletonQueryWizard {
|
||||
private readonly app: App,
|
||||
private readonly databaseManager: DatabaseManager,
|
||||
private readonly databaseFetcher: DatabaseFetcher,
|
||||
private readonly databaseStoragePath: string | undefined,
|
||||
private readonly selectedItems: readonly QueryTreeViewItem[],
|
||||
private language: QueryLanguage | undefined = undefined,
|
||||
) {}
|
||||
@@ -361,10 +360,6 @@ export class SkeletonQueryWizard {
|
||||
}
|
||||
|
||||
private async downloadDatabase(progress: ProgressCallback) {
|
||||
if (this.databaseStoragePath === undefined) {
|
||||
throw new Error("Database storage path is undefined");
|
||||
}
|
||||
|
||||
if (this.language === undefined) {
|
||||
throw new Error("Language is undefined");
|
||||
}
|
||||
@@ -387,11 +382,7 @@ export class SkeletonQueryWizard {
|
||||
|
||||
await this.databaseFetcher.downloadGitHubDatabase(
|
||||
chosenRepo,
|
||||
this.app,
|
||||
this.databaseManager,
|
||||
this.databaseStoragePath,
|
||||
progress,
|
||||
this.cliServer,
|
||||
this.language,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -916,17 +916,18 @@ export class ModelEditorView extends AbstractWebview<
|
||||
// the user to import the library database. We need to have the database
|
||||
// imported to the query server, so we need to register it to our workspace.
|
||||
const makeSelected = false;
|
||||
const addedDatabase =
|
||||
await new DatabaseFetcher().promptImportGithubDatabase(
|
||||
this.app,
|
||||
this.databaseManager,
|
||||
this.app.workspaceStoragePath ?? this.app.globalStoragePath,
|
||||
progress,
|
||||
this.cliServer,
|
||||
this.databaseItem.language,
|
||||
makeSelected,
|
||||
false,
|
||||
);
|
||||
const databaseFetcher = new DatabaseFetcher(
|
||||
this.app,
|
||||
this.databaseManager,
|
||||
this.app.workspaceStoragePath ?? this.app.globalStoragePath,
|
||||
this.cliServer,
|
||||
);
|
||||
const addedDatabase = await databaseFetcher.promptImportGithubDatabase(
|
||||
progress,
|
||||
this.databaseItem.language,
|
||||
makeSelected,
|
||||
false,
|
||||
);
|
||||
if (!addedDatabase) {
|
||||
void this.app.logger.log("No database chosen");
|
||||
return;
|
||||
|
||||
@@ -11,8 +11,8 @@ import {
|
||||
getActivatedExtension,
|
||||
storagePath,
|
||||
} from "../../global.helper";
|
||||
import { createMockCommandManager } from "../../../__mocks__/commandsMock";
|
||||
import { remove } from "fs-extra";
|
||||
import { createMockApp } from "../../../__mocks__/appMock";
|
||||
|
||||
/**
|
||||
* Run various integration tests for databases
|
||||
@@ -46,14 +46,16 @@ describe("database-fetcher", () => {
|
||||
describe("importArchiveDatabase", () => {
|
||||
it("should add a database from a folder", async () => {
|
||||
const uri = Uri.file(dbLoc);
|
||||
let dbItem = await new DatabaseFetcher().importArchiveDatabase(
|
||||
createMockCommandManager(),
|
||||
uri.toString(true),
|
||||
const databaseFetcher = new DatabaseFetcher(
|
||||
createMockApp(),
|
||||
databaseManager,
|
||||
storagePath,
|
||||
progressCallback,
|
||||
cli,
|
||||
);
|
||||
let dbItem = await databaseFetcher.importArchiveDatabase(
|
||||
uri.toString(true),
|
||||
progressCallback,
|
||||
);
|
||||
expect(dbItem).toBe(databaseManager.currentDatabaseItem);
|
||||
expect(dbItem).toBe(databaseManager.databaseItems[0]);
|
||||
expect(dbItem).toBeDefined();
|
||||
@@ -68,13 +70,14 @@ describe("database-fetcher", () => {
|
||||
// Provide a database URL when prompted
|
||||
inputBoxStub.mockResolvedValue(DB_URL);
|
||||
|
||||
let dbItem = await new DatabaseFetcher().promptImportInternetDatabase(
|
||||
createMockCommandManager(),
|
||||
const databaseFetcher = new DatabaseFetcher(
|
||||
createMockApp(),
|
||||
databaseManager,
|
||||
storagePath,
|
||||
progressCallback,
|
||||
cli,
|
||||
);
|
||||
let dbItem =
|
||||
await databaseFetcher.promptImportInternetDatabase(progressCallback);
|
||||
expect(dbItem).toBeDefined();
|
||||
dbItem = dbItem!;
|
||||
expect(dbItem.name).toBe("db");
|
||||
|
||||
@@ -116,7 +116,12 @@ describe("SkeletonQueryWizard", () => {
|
||||
},
|
||||
] as WorkspaceFolder[]);
|
||||
|
||||
databaseFetcher = new DatabaseFetcher();
|
||||
databaseFetcher = new DatabaseFetcher(
|
||||
mockApp,
|
||||
mockDatabaseManager,
|
||||
storagePath,
|
||||
mockCli,
|
||||
);
|
||||
|
||||
quickPickSpy = jest.spyOn(window, "showQuickPick").mockResolvedValueOnce(
|
||||
mockedQuickPickItem({
|
||||
@@ -149,7 +154,6 @@ describe("SkeletonQueryWizard", () => {
|
||||
mockApp,
|
||||
mockDatabaseManager,
|
||||
databaseFetcher,
|
||||
storagePath,
|
||||
selectedItems,
|
||||
);
|
||||
|
||||
@@ -177,7 +181,6 @@ describe("SkeletonQueryWizard", () => {
|
||||
mockApp,
|
||||
mockDatabaseManager,
|
||||
databaseFetcher,
|
||||
storagePath,
|
||||
selectedItems,
|
||||
QueryLanguage.Swift,
|
||||
);
|
||||
@@ -326,7 +329,6 @@ describe("SkeletonQueryWizard", () => {
|
||||
mockApp,
|
||||
mockDatabaseManagerWithItems,
|
||||
databaseFetcher,
|
||||
storagePath,
|
||||
selectedItems,
|
||||
);
|
||||
});
|
||||
@@ -376,7 +378,6 @@ describe("SkeletonQueryWizard", () => {
|
||||
mockApp,
|
||||
mockDatabaseManagerWithItems,
|
||||
databaseFetcher,
|
||||
storagePath,
|
||||
selectedItems,
|
||||
);
|
||||
});
|
||||
@@ -512,7 +513,6 @@ describe("SkeletonQueryWizard", () => {
|
||||
mockApp,
|
||||
mockDatabaseManager,
|
||||
databaseFetcher,
|
||||
storagePath,
|
||||
selectedItems,
|
||||
QueryLanguage.Javascript,
|
||||
);
|
||||
@@ -734,7 +734,6 @@ describe("SkeletonQueryWizard", () => {
|
||||
mockApp,
|
||||
mockDatabaseManager,
|
||||
databaseFetcher,
|
||||
storagePath,
|
||||
selectedItems,
|
||||
);
|
||||
});
|
||||
@@ -764,7 +763,6 @@ describe("SkeletonQueryWizard", () => {
|
||||
mockApp,
|
||||
mockDatabaseManager,
|
||||
databaseFetcher,
|
||||
storagePath,
|
||||
selectedItems,
|
||||
);
|
||||
});
|
||||
@@ -798,7 +796,6 @@ describe("SkeletonQueryWizard", () => {
|
||||
mockApp,
|
||||
mockDatabaseManager,
|
||||
databaseFetcher,
|
||||
storagePath,
|
||||
selectedItems,
|
||||
QueryLanguage.Swift,
|
||||
);
|
||||
@@ -842,7 +839,6 @@ describe("SkeletonQueryWizard", () => {
|
||||
mockApp,
|
||||
mockDatabaseManager,
|
||||
databaseFetcher,
|
||||
storagePath,
|
||||
selectedItems,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -8,7 +8,7 @@ import type {
|
||||
import type { CodeQLCliServer } from "../../src/codeql-cli/cli";
|
||||
import type { CodeQLExtensionInterface } from "../../src/extension";
|
||||
import { DatabaseFetcher } from "../../src/databases/database-fetcher";
|
||||
import { createMockCommandManager } from "../__mocks__/commandsMock";
|
||||
import { createMockApp } from "../__mocks__/appMock";
|
||||
|
||||
// This file contains helpers shared between tests that work with an activated extension.
|
||||
|
||||
@@ -34,15 +34,17 @@ export async function ensureTestDatabase(
|
||||
// Add a database, but make sure the database manager is empty first
|
||||
await cleanDatabases(databaseManager);
|
||||
const uri = Uri.file(dbLoc);
|
||||
const maybeDbItem = await new DatabaseFetcher().importArchiveDatabase(
|
||||
createMockCommandManager(),
|
||||
uri.toString(true),
|
||||
const databaseFetcher = new DatabaseFetcher(
|
||||
createMockApp(),
|
||||
databaseManager,
|
||||
storagePath,
|
||||
cli,
|
||||
);
|
||||
const maybeDbItem = await databaseFetcher.importArchiveDatabase(
|
||||
uri.toString(true),
|
||||
(_p) => {
|
||||
/**/
|
||||
},
|
||||
cli,
|
||||
);
|
||||
|
||||
if (!maybeDbItem) {
|
||||
|
||||
@@ -13,10 +13,10 @@ import {
|
||||
import type { DatabaseManager } from "../../../../../src/databases/local-databases";
|
||||
import type { GitHubDatabaseConfig } from "../../../../../src/config";
|
||||
import type { CodeQLCliServer } from "../../../../../src/codeql-cli/cli";
|
||||
import { createMockCommandManager } from "../../../../__mocks__/commandsMock";
|
||||
import { DatabaseFetcher } from "../../../../../src/databases/database-fetcher";
|
||||
import * as dialog from "../../../../../src/common/vscode/dialog";
|
||||
import type { CodeqlDatabase } from "../../../../../src/databases/github-databases/api";
|
||||
import { createMockApp } from "../../../../__mocks__/appMock";
|
||||
|
||||
describe("askForGitHubDatabaseDownload", () => {
|
||||
const setDownload = jest.fn();
|
||||
@@ -101,7 +101,7 @@ describe("downloadDatabaseFromGitHub", () => {
|
||||
|
||||
const storagePath = "/a/b/c/d";
|
||||
let cliServer: CodeQLCliServer;
|
||||
const commandManager = createMockCommandManager();
|
||||
const app = createMockApp();
|
||||
|
||||
let databases = [
|
||||
mockedObject<CodeqlDatabase>({
|
||||
@@ -124,8 +124,13 @@ describe("downloadDatabaseFromGitHub", () => {
|
||||
beforeEach(() => {
|
||||
octokit = mockedObject<Octokit>({});
|
||||
databaseManager = mockedObject<DatabaseManager>({});
|
||||
databaseFetcher = new DatabaseFetcher();
|
||||
cliServer = mockedObject<CodeQLCliServer>({});
|
||||
databaseFetcher = new DatabaseFetcher(
|
||||
app,
|
||||
databaseManager,
|
||||
storagePath,
|
||||
cliServer,
|
||||
);
|
||||
|
||||
showQuickPickSpy = jest.spyOn(window, "showQuickPick").mockResolvedValue(
|
||||
mockedQuickPickItem([
|
||||
@@ -145,11 +150,8 @@ describe("downloadDatabaseFromGitHub", () => {
|
||||
owner,
|
||||
repo,
|
||||
databases,
|
||||
databaseManager,
|
||||
databaseFetcher,
|
||||
storagePath,
|
||||
cliServer,
|
||||
commandManager,
|
||||
app.commands,
|
||||
);
|
||||
|
||||
expect(downloadGitHubDatabaseFromUrlSpy).toHaveBeenCalledTimes(1);
|
||||
@@ -162,9 +164,6 @@ describe("downloadDatabaseFromGitHub", () => {
|
||||
repo,
|
||||
octokit,
|
||||
expect.anything(),
|
||||
databaseManager,
|
||||
storagePath,
|
||||
cliServer,
|
||||
true,
|
||||
false,
|
||||
);
|
||||
@@ -210,11 +209,8 @@ describe("downloadDatabaseFromGitHub", () => {
|
||||
owner,
|
||||
repo,
|
||||
databases,
|
||||
databaseManager,
|
||||
databaseFetcher,
|
||||
storagePath,
|
||||
cliServer,
|
||||
commandManager,
|
||||
app.commands,
|
||||
);
|
||||
|
||||
expect(downloadGitHubDatabaseFromUrlSpy).toHaveBeenCalledTimes(1);
|
||||
@@ -227,9 +223,6 @@ describe("downloadDatabaseFromGitHub", () => {
|
||||
repo,
|
||||
octokit,
|
||||
expect.anything(),
|
||||
databaseManager,
|
||||
storagePath,
|
||||
cliServer,
|
||||
true,
|
||||
false,
|
||||
);
|
||||
@@ -267,11 +260,8 @@ describe("downloadDatabaseFromGitHub", () => {
|
||||
owner,
|
||||
repo,
|
||||
databases,
|
||||
databaseManager,
|
||||
databaseFetcher,
|
||||
storagePath,
|
||||
cliServer,
|
||||
commandManager,
|
||||
app.commands,
|
||||
);
|
||||
|
||||
expect(downloadGitHubDatabaseFromUrlSpy).toHaveBeenCalledTimes(2);
|
||||
@@ -284,9 +274,6 @@ describe("downloadDatabaseFromGitHub", () => {
|
||||
repo,
|
||||
octokit,
|
||||
expect.anything(),
|
||||
databaseManager,
|
||||
storagePath,
|
||||
cliServer,
|
||||
true,
|
||||
false,
|
||||
);
|
||||
@@ -299,9 +286,6 @@ describe("downloadDatabaseFromGitHub", () => {
|
||||
repo,
|
||||
octokit,
|
||||
expect.anything(),
|
||||
databaseManager,
|
||||
storagePath,
|
||||
cliServer,
|
||||
true,
|
||||
false,
|
||||
);
|
||||
@@ -333,11 +317,8 @@ describe("downloadDatabaseFromGitHub", () => {
|
||||
owner,
|
||||
repo,
|
||||
databases,
|
||||
databaseManager,
|
||||
databaseFetcher,
|
||||
storagePath,
|
||||
cliServer,
|
||||
commandManager,
|
||||
app.commands,
|
||||
);
|
||||
|
||||
expect(downloadGitHubDatabaseFromUrlSpy).not.toHaveBeenCalled();
|
||||
|
||||
@@ -68,7 +68,12 @@ describe("GitHubDatabasesModule", () => {
|
||||
databaseManager = mockEmptyDatabaseManager();
|
||||
databaseStoragePath = "/a/b/some-path";
|
||||
cliServer = mockedObject<CodeQLCliServer>({});
|
||||
databaseFetcher = new DatabaseFetcher();
|
||||
databaseFetcher = new DatabaseFetcher(
|
||||
app,
|
||||
databaseManager,
|
||||
databaseStoragePath,
|
||||
cliServer,
|
||||
);
|
||||
config = mockedObject<GitHubDatabaseConfig>({
|
||||
download: "ask",
|
||||
update: "ask",
|
||||
@@ -78,8 +83,6 @@ describe("GitHubDatabasesModule", () => {
|
||||
app,
|
||||
databaseManager,
|
||||
databaseFetcher,
|
||||
databaseStoragePath,
|
||||
cliServer,
|
||||
config,
|
||||
);
|
||||
|
||||
@@ -129,8 +132,6 @@ describe("GitHubDatabasesModule", () => {
|
||||
app,
|
||||
databaseManager,
|
||||
databaseFetcher,
|
||||
databaseStoragePath,
|
||||
cliServer,
|
||||
config,
|
||||
);
|
||||
|
||||
@@ -211,10 +212,7 @@ describe("GitHubDatabasesModule", () => {
|
||||
owner,
|
||||
repo,
|
||||
databases,
|
||||
databaseManager,
|
||||
databaseFetcher,
|
||||
databaseStoragePath,
|
||||
cliServer,
|
||||
app.commands,
|
||||
);
|
||||
});
|
||||
@@ -257,8 +255,6 @@ describe("GitHubDatabasesModule", () => {
|
||||
databaseUpdates,
|
||||
databaseManager,
|
||||
databaseFetcher,
|
||||
databaseStoragePath,
|
||||
cliServer,
|
||||
app.commands,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -11,7 +11,6 @@ import type { CodeqlDatabase } from "../../../../../src/databases/github-databas
|
||||
import type { DatabaseManager } from "../../../../../src/databases/local-databases";
|
||||
import type { GitHubDatabaseConfig } from "../../../../../src/config";
|
||||
import type { CodeQLCliServer } from "../../../../../src/codeql-cli/cli";
|
||||
import { createMockCommandManager } from "../../../../__mocks__/commandsMock";
|
||||
import { DatabaseFetcher } from "../../../../../src/databases/database-fetcher";
|
||||
import * as dialog from "../../../../../src/common/vscode/dialog";
|
||||
import type { DatabaseUpdate } from "../../../../../src/databases/github-databases/updates";
|
||||
@@ -20,6 +19,7 @@ import {
|
||||
downloadDatabaseUpdateFromGitHub,
|
||||
isNewerDatabaseAvailable,
|
||||
} from "../../../../../src/databases/github-databases/updates";
|
||||
import { createMockApp } from "../../../../__mocks__/appMock";
|
||||
|
||||
describe("isNewerDatabaseAvailable", () => {
|
||||
const owner = "github";
|
||||
@@ -347,7 +347,7 @@ describe("downloadDatabaseUpdateFromGitHub", () => {
|
||||
let databaseFetcher: DatabaseFetcher;
|
||||
const storagePath = "/a/b/c/d";
|
||||
let cliServer: CodeQLCliServer;
|
||||
const commandManager = createMockCommandManager();
|
||||
const app = createMockApp();
|
||||
|
||||
let updates: DatabaseUpdate[] = [
|
||||
{
|
||||
@@ -377,8 +377,13 @@ describe("downloadDatabaseUpdateFromGitHub", () => {
|
||||
databaseManager = mockedObject<DatabaseManager>({
|
||||
currentDatabaseItem: mockDatabaseItem(),
|
||||
});
|
||||
databaseFetcher = new DatabaseFetcher();
|
||||
cliServer = mockedObject<CodeQLCliServer>({});
|
||||
databaseFetcher = new DatabaseFetcher(
|
||||
app,
|
||||
databaseManager,
|
||||
storagePath,
|
||||
cliServer,
|
||||
);
|
||||
|
||||
showQuickPickSpy = jest.spyOn(window, "showQuickPick").mockResolvedValue(
|
||||
mockedQuickPickItem([
|
||||
@@ -400,9 +405,7 @@ describe("downloadDatabaseUpdateFromGitHub", () => {
|
||||
updates,
|
||||
databaseManager,
|
||||
databaseFetcher,
|
||||
storagePath,
|
||||
cliServer,
|
||||
commandManager,
|
||||
app.commands,
|
||||
);
|
||||
|
||||
expect(downloadGitHubDatabaseFromUrlSpy).toHaveBeenCalledTimes(1);
|
||||
@@ -415,9 +418,6 @@ describe("downloadDatabaseUpdateFromGitHub", () => {
|
||||
repo,
|
||||
octokit,
|
||||
expect.anything(),
|
||||
databaseManager,
|
||||
storagePath,
|
||||
cliServer,
|
||||
false,
|
||||
false,
|
||||
);
|
||||
@@ -480,9 +480,7 @@ describe("downloadDatabaseUpdateFromGitHub", () => {
|
||||
updates,
|
||||
databaseManager,
|
||||
databaseFetcher,
|
||||
storagePath,
|
||||
cliServer,
|
||||
commandManager,
|
||||
app.commands,
|
||||
);
|
||||
|
||||
expect(downloadGitHubDatabaseFromUrlSpy).toHaveBeenCalledTimes(1);
|
||||
@@ -495,9 +493,6 @@ describe("downloadDatabaseUpdateFromGitHub", () => {
|
||||
repo,
|
||||
octokit,
|
||||
expect.anything(),
|
||||
databaseManager,
|
||||
storagePath,
|
||||
cliServer,
|
||||
true,
|
||||
true,
|
||||
);
|
||||
@@ -537,9 +532,7 @@ describe("downloadDatabaseUpdateFromGitHub", () => {
|
||||
updates,
|
||||
databaseManager,
|
||||
databaseFetcher,
|
||||
storagePath,
|
||||
cliServer,
|
||||
commandManager,
|
||||
app.commands,
|
||||
);
|
||||
|
||||
expect(downloadGitHubDatabaseFromUrlSpy).toHaveBeenCalledTimes(2);
|
||||
@@ -552,9 +545,6 @@ describe("downloadDatabaseUpdateFromGitHub", () => {
|
||||
repo,
|
||||
octokit,
|
||||
expect.anything(),
|
||||
databaseManager,
|
||||
storagePath,
|
||||
cliServer,
|
||||
false,
|
||||
false,
|
||||
);
|
||||
@@ -567,9 +557,6 @@ describe("downloadDatabaseUpdateFromGitHub", () => {
|
||||
repo,
|
||||
octokit,
|
||||
expect.anything(),
|
||||
databaseManager,
|
||||
storagePath,
|
||||
cliServer,
|
||||
true,
|
||||
true,
|
||||
);
|
||||
@@ -603,9 +590,7 @@ describe("downloadDatabaseUpdateFromGitHub", () => {
|
||||
updates,
|
||||
databaseManager,
|
||||
databaseFetcher,
|
||||
storagePath,
|
||||
cliServer,
|
||||
commandManager,
|
||||
app.commands,
|
||||
);
|
||||
|
||||
expect(downloadGitHubDatabaseFromUrlSpy).not.toHaveBeenCalled();
|
||||
|
||||
Reference in New Issue
Block a user