Run MRVA against remote DB

This commit is contained in:
Nora
2022-12-05 15:07:48 +01:00
parent c436688eb2
commit dbba6972e1
6 changed files with 59 additions and 12 deletions

View File

@@ -9,6 +9,16 @@ import { DbPanel } from "./ui/db-panel";
import { DbSelectionDecorationProvider } from "./ui/db-selection-decoration-provider";
export class DbModule extends DisposableObject {
public readonly dbManager: DbManager;
private readonly dbConfigStore: DbConfigStore;
constructor(app: App) {
super();
this.dbConfigStore = new DbConfigStore(app);
this.dbManager = new DbManager(app, this.dbConfigStore);
}
public async initialize(app: App): Promise<void> {
if (
app.mode !== AppMode.Development ||
@@ -23,15 +33,13 @@ export class DbModule extends DisposableObject {
void extLogger.log("Initializing database module");
const dbConfigStore = new DbConfigStore(app);
await dbConfigStore.initialize();
await this.dbConfigStore.initialize();
const dbManager = new DbManager(app, dbConfigStore);
const dbPanel = new DbPanel(dbManager);
const dbPanel = new DbPanel(this.dbManager);
await dbPanel.initialize();
this.push(dbPanel);
this.push(dbConfigStore);
this.push(this.dbConfigStore);
const dbSelectionDecorationProvider = new DbSelectionDecorationProvider();
@@ -40,7 +48,7 @@ export class DbModule extends DisposableObject {
}
export async function initializeDbModule(app: App): Promise<DbModule> {
const dbModule = new DbModule();
const dbModule = new DbModule(app);
await dbModule.initialize(app);
return dbModule;
}

View File

@@ -622,6 +622,11 @@ async function activateWithInstalledDistribution(
ctx.subscriptions.push(localQueryResultsView);
void extLogger.log("Initializing variant analysis manager.");
const app = new ExtensionApp(ctx);
const dbModule = await initializeDbModule(app);
ctx.subscriptions.push(dbModule);
const variantAnalysisStorageDir = join(
ctx.globalStorageUri.fsPath,
"variant-analyses",
@@ -636,6 +641,7 @@ async function activateWithInstalledDistribution(
cliServer,
variantAnalysisStorageDir,
variantAnalysisResultsManager,
dbModule.dbManager,
);
ctx.subscriptions.push(variantAnalysisManager);
ctx.subscriptions.push(variantAnalysisResultsManager);
@@ -1580,10 +1586,6 @@ async function activateWithInstalledDistribution(
void extLogger.log("Reading query history");
await qhm.readQueryHistory();
const app = new ExtensionApp(ctx);
const dbModule = await initializeDbModule(app);
ctx.subscriptions.push(dbModule);
void extLogger.log("Successfully finished extension initialization.");
return {

View File

@@ -4,9 +4,12 @@ import { extLogger } from "../common";
import {
getRemoteRepositoryLists,
getRemoteRepositoryListsPath,
isNewQueryRunExperienceEnabled,
} from "../config";
import { OWNER_REGEX, REPO_REGEX } from "../pure/helpers-pure";
import { UserCancellationException } from "../commandRunner";
import { DbManager } from "../databases/db-manager";
import { DbItemKind } from "../databases/db-item";
export interface RepositorySelection {
repositories?: string[];
@@ -30,7 +33,33 @@ interface RepoList {
* Gets the repositories or repository lists to run the query against.
* @returns The user selection.
*/
export async function getRepositorySelection(): Promise<RepositorySelection> {
export async function getRepositorySelection(
dbManager?: DbManager,
): Promise<RepositorySelection> {
if (isNewQueryRunExperienceEnabled()) {
const selectedDbItem = await dbManager?.selectedDbItem();
if (selectedDbItem) {
switch (selectedDbItem.kind) {
case DbItemKind.LocalDatabase || DbItemKind.LocalList:
throw new Error("Local databases and lists are not supported");
case DbItemKind.RemoteSystemDefinedList:
return { repositoryLists: [selectedDbItem.listName] };
case DbItemKind.RemoteUserDefinedList:
return {
repositories: selectedDbItem.repos.map((repo) => repo.repoFullName),
};
case DbItemKind.RemoteOwner:
return { owners: [selectedDbItem.ownerName] };
case DbItemKind.RemoteRepo:
return { repositories: [selectedDbItem.repoFullName] };
}
} else {
throw new Error(
"Please select a remote database item to run the query against.",
);
}
}
const quickPickItems = [
createCustomRepoQuickPickItem(),
createAllReposOfOwnerQuickPickItem(),

View File

@@ -29,6 +29,7 @@ import {
RepositorySelection,
} from "./repository-selection";
import { Repository } from "./shared/repository";
import { DbManager } from "../databases/db-manager";
export interface QlPack {
name: string;
@@ -213,6 +214,7 @@ export async function prepareRemoteQueryRun(
uri: Uri | undefined,
progress: ProgressCallback,
token: CancellationToken,
dbManager?: DbManager, // the dbManager is only needed when the newQueryRunExperience is enabled
): Promise<PreparedRemoteQuery> {
if (!(await cliServer.cliConstraints.supportsRemoteQueries())) {
throw new Error(
@@ -232,7 +234,7 @@ export async function prepareRemoteQueryRun(
message: "Determining query target language",
});
const repoSelection = await getRepositorySelection();
const repoSelection = await getRepositorySelection(dbManager);
if (!isValidSelection(repoSelection)) {
throw new UserCancellationException("No repositories to query.");
}

View File

@@ -59,6 +59,7 @@ import {
RepositoriesFilterSortStateWithIds,
} from "../pure/variant-analysis-filter-sort";
import { URLSearchParams } from "url";
import { DbManager } from "../databases/db-manager";
export class VariantAnalysisManager
extends DisposableObject
@@ -100,6 +101,7 @@ export class VariantAnalysisManager
private readonly cliServer: CodeQLCliServer,
private readonly storagePath: string,
private readonly variantAnalysisResultsManager: VariantAnalysisResultsManager,
private readonly dbManager: DbManager,
) {
super();
this.variantAnalysisMonitor = this.push(
@@ -140,6 +142,7 @@ export class VariantAnalysisManager
uri,
progress,
token,
this.dbManager,
);
const queryName = getQueryName(queryMetadata, queryFile);

View File

@@ -56,6 +56,7 @@ import {
defaultFilterSortState,
SortKey,
} from "../../../pure/variant-analysis-filter-sort";
import { DbManager } from "../../../databases/db-manager";
// up to 3 minutes per test
jest.setTimeout(3 * 60 * 1000);
@@ -69,6 +70,7 @@ describe("Variant Analysis Manager", () => {
let cancellationTokenSource: CancellationTokenSource;
let variantAnalysisManager: VariantAnalysisManager;
let variantAnalysisResultsManager: VariantAnalysisResultsManager;
let dbManager: DbManager;
let variantAnalysis: VariantAnalysis;
let scannedRepos: VariantAnalysisScannedRepository[];
@@ -107,6 +109,7 @@ describe("Variant Analysis Manager", () => {
cli,
storagePath,
variantAnalysisResultsManager,
dbManager,
);
});