Show welcome view when controller repo is not setup

This will add a welcome view to the database panel which is shown when
the controller repository is not setup. This welcome view will show a
button which can be used to set up the controller repository.
This commit is contained in:
Koen Vlaswinkel
2023-01-26 14:16:40 +01:00
parent ddddd2f0b9
commit b3c4979358
6 changed files with 76 additions and 6 deletions

View File

@@ -1310,6 +1310,11 @@
{
"view": "codeQLEvalLogViewer",
"contents": "Run the 'Show Evaluator Log (UI)' command on a CodeQL query run in the Query History view."
},
{
"view": "codeQLVariantAnalysisRepositories",
"contents": "Set up a controller repository to start using variant analysis.\n[Set up controller repository](command:codeQLVariantAnalysisRepositories.setupControllerRepository)",
"when": "!config.codeQL.variantAnalysis.controllerRepo"
}
]
},

View File

@@ -539,6 +539,27 @@ export async function setRemoteControllerRepo(repo: string | undefined) {
await REMOTE_CONTROLLER_REPO.updateValue(repo, ConfigurationTarget.Global);
}
export interface VariantAnalysisConfig {
controllerRepo: string | undefined;
onDidChangeConfiguration?: Event<void>;
}
export class VariantAnalysisConfigListener
extends ConfigListener
implements VariantAnalysisConfig
{
protected handleDidChangeConfiguration(e: ConfigurationChangeEvent): void {
this.handleDidChangeConfigurationForRelevantSettings(
[VARIANT_ANALYSIS_SETTING],
e,
);
}
public get controllerRepo(): string | undefined {
return getRemoteControllerRepo();
}
}
/**
* The branch of "github/codeql-variant-analysis-action" to use with the "Run Variant Analysis" command.
* Default value is "main".

View File

@@ -24,7 +24,7 @@ export class DbModule extends DisposableObject {
const dbModule = new DbModule(app);
app.subscriptions.push(dbModule);
await dbModule.initialize();
await dbModule.initialize(app);
return dbModule;
}
@@ -39,12 +39,12 @@ export class DbModule extends DisposableObject {
return isCanary() && isVariantAnalysisReposPanelEnabled();
}
private async initialize(): Promise<void> {
private async initialize(app: App): Promise<void> {
void extLogger.log("Initializing database module");
await this.dbConfigStore.initialize();
const dbPanel = new DbPanel(this.dbManager);
const dbPanel = new DbPanel(this.dbManager, app.credentials);
await dbPanel.initialize();
this.push(dbPanel);

View File

@@ -29,6 +29,9 @@ import { DbManager } from "../db-manager";
import { DbTreeDataProvider } from "./db-tree-data-provider";
import { DbTreeViewItem } from "./db-tree-view-item";
import { getGitHubUrl } from "./db-tree-view-item-action";
import { getControllerRepo } from "../../remote-queries/run-remote-query";
import { getErrorMessage } from "../../pure/helpers-pure";
import { Credentials } from "../../common/authentication";
export interface RemoteDatabaseQuickPickItem extends QuickPickItem {
kind: string;
@@ -42,7 +45,10 @@ export class DbPanel extends DisposableObject {
private readonly dataProvider: DbTreeDataProvider;
private readonly treeView: TreeView<DbTreeViewItem>;
public constructor(private readonly dbManager: DbManager) {
public constructor(
private readonly dbManager: DbManager,
private readonly credentials: Credentials,
) {
super();
this.dataProvider = new DbTreeDataProvider(dbManager);
@@ -112,6 +118,12 @@ export class DbPanel extends DisposableObject {
(treeViewItem: DbTreeViewItem) => this.removeItem(treeViewItem),
),
);
this.push(
commandRunner(
"codeQLVariantAnalysisRepositories.setupControllerRepository",
() => this.setupControllerRepository(),
),
);
}
private async openConfigFile(): Promise<void> {
@@ -383,4 +395,21 @@ export class DbPanel extends DisposableObject {
await commands.executeCommand("vscode.open", Uri.parse(githubUrl));
}
private async setupControllerRepository(): Promise<void> {
try {
// This will also validate that the controller repository is valid
await getControllerRepo(this.credentials);
} catch (e: unknown) {
if (e instanceof UserCancellationException) {
return;
}
void showAndLogErrorMessage(
`An error occurred while setting up the controller repository: ${getErrorMessage(
e,
)}`,
);
}
}
}

View File

@@ -13,6 +13,7 @@ import {
DbConfigValidationError,
DbConfigValidationErrorKind,
} from "../db-validation-errors";
import { VariantAnalysisConfigListener } from "../../config";
export class DbTreeDataProvider
extends DisposableObject
@@ -27,8 +28,17 @@ export class DbTreeDataProvider
);
private dbTreeItems: DbTreeViewItem[];
private variantAnalysisConfig: VariantAnalysisConfigListener;
public constructor(private readonly dbManager: DbManager) {
super();
this.variantAnalysisConfig = this.push(new VariantAnalysisConfigListener());
this.variantAnalysisConfig.onDidChangeConfiguration(() => {
this.dbTreeItems = this.createTree();
this._onDidChangeTreeData.fire(undefined);
});
this.dbTreeItems = this.createTree();
this.onDidChangeTreeData = this._onDidChangeTreeData.event;
@@ -62,6 +72,11 @@ export class DbTreeDataProvider
}
private createTree(): DbTreeViewItem[] {
// Returning an empty tree here will show the welcome view
if (!this.variantAnalysisConfig.controllerRepo) {
return [];
}
const dbItemsResult = this.dbManager.getDbItems();
if (dbItemsResult.isFailure) {

View File

@@ -376,10 +376,10 @@ export async function getControllerRepo(
);
controllerRepoNwo = await window.showInputBox({
title:
"Controller repository in which to run the GitHub Actions workflow for this variant analysis",
"Controller repository in which to run GitHub Actions workflows for variant analyses",
placeHolder: "<owner>/<repo>",
prompt:
"Enter the name of a GitHub repository in the format <owner>/<repo>",
"Enter the name of a GitHub repository in the format <owner>/<repo>. You can change this in the extension settings.",
ignoreFocusOut: true,
});
if (!controllerRepoNwo) {