Skip to content

Commit b3c4979

Browse files
committed
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.
1 parent ddddd2f commit b3c4979

File tree

6 files changed

+76
-6
lines changed

6 files changed

+76
-6
lines changed

extensions/ql-vscode/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,11 @@
13101310
{
13111311
"view": "codeQLEvalLogViewer",
13121312
"contents": "Run the 'Show Evaluator Log (UI)' command on a CodeQL query run in the Query History view."
1313+
},
1314+
{
1315+
"view": "codeQLVariantAnalysisRepositories",
1316+
"contents": "Set up a controller repository to start using variant analysis.\n[Set up controller repository](command:codeQLVariantAnalysisRepositories.setupControllerRepository)",
1317+
"when": "!config.codeQL.variantAnalysis.controllerRepo"
13131318
}
13141319
]
13151320
},

extensions/ql-vscode/src/config.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,27 @@ export async function setRemoteControllerRepo(repo: string | undefined) {
539539
await REMOTE_CONTROLLER_REPO.updateValue(repo, ConfigurationTarget.Global);
540540
}
541541

542+
export interface VariantAnalysisConfig {
543+
controllerRepo: string | undefined;
544+
onDidChangeConfiguration?: Event<void>;
545+
}
546+
547+
export class VariantAnalysisConfigListener
548+
extends ConfigListener
549+
implements VariantAnalysisConfig
550+
{
551+
protected handleDidChangeConfiguration(e: ConfigurationChangeEvent): void {
552+
this.handleDidChangeConfigurationForRelevantSettings(
553+
[VARIANT_ANALYSIS_SETTING],
554+
e,
555+
);
556+
}
557+
558+
public get controllerRepo(): string | undefined {
559+
return getRemoteControllerRepo();
560+
}
561+
}
562+
542563
/**
543564
* The branch of "github/codeql-variant-analysis-action" to use with the "Run Variant Analysis" command.
544565
* Default value is "main".

extensions/ql-vscode/src/databases/db-module.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class DbModule extends DisposableObject {
2424
const dbModule = new DbModule(app);
2525
app.subscriptions.push(dbModule);
2626

27-
await dbModule.initialize();
27+
await dbModule.initialize(app);
2828
return dbModule;
2929
}
3030

@@ -39,12 +39,12 @@ export class DbModule extends DisposableObject {
3939
return isCanary() && isVariantAnalysisReposPanelEnabled();
4040
}
4141

42-
private async initialize(): Promise<void> {
42+
private async initialize(app: App): Promise<void> {
4343
void extLogger.log("Initializing database module");
4444

4545
await this.dbConfigStore.initialize();
4646

47-
const dbPanel = new DbPanel(this.dbManager);
47+
const dbPanel = new DbPanel(this.dbManager, app.credentials);
4848
await dbPanel.initialize();
4949

5050
this.push(dbPanel);

extensions/ql-vscode/src/databases/ui/db-panel.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ import { DbManager } from "../db-manager";
2929
import { DbTreeDataProvider } from "./db-tree-data-provider";
3030
import { DbTreeViewItem } from "./db-tree-view-item";
3131
import { getGitHubUrl } from "./db-tree-view-item-action";
32+
import { getControllerRepo } from "../../remote-queries/run-remote-query";
33+
import { getErrorMessage } from "../../pure/helpers-pure";
34+
import { Credentials } from "../../common/authentication";
3235

3336
export interface RemoteDatabaseQuickPickItem extends QuickPickItem {
3437
kind: string;
@@ -42,7 +45,10 @@ export class DbPanel extends DisposableObject {
4245
private readonly dataProvider: DbTreeDataProvider;
4346
private readonly treeView: TreeView<DbTreeViewItem>;
4447

45-
public constructor(private readonly dbManager: DbManager) {
48+
public constructor(
49+
private readonly dbManager: DbManager,
50+
private readonly credentials: Credentials,
51+
) {
4652
super();
4753

4854
this.dataProvider = new DbTreeDataProvider(dbManager);
@@ -112,6 +118,12 @@ export class DbPanel extends DisposableObject {
112118
(treeViewItem: DbTreeViewItem) => this.removeItem(treeViewItem),
113119
),
114120
);
121+
this.push(
122+
commandRunner(
123+
"codeQLVariantAnalysisRepositories.setupControllerRepository",
124+
() => this.setupControllerRepository(),
125+
),
126+
);
115127
}
116128

117129
private async openConfigFile(): Promise<void> {
@@ -383,4 +395,21 @@ export class DbPanel extends DisposableObject {
383395

384396
await commands.executeCommand("vscode.open", Uri.parse(githubUrl));
385397
}
398+
399+
private async setupControllerRepository(): Promise<void> {
400+
try {
401+
// This will also validate that the controller repository is valid
402+
await getControllerRepo(this.credentials);
403+
} catch (e: unknown) {
404+
if (e instanceof UserCancellationException) {
405+
return;
406+
}
407+
408+
void showAndLogErrorMessage(
409+
`An error occurred while setting up the controller repository: ${getErrorMessage(
410+
e,
411+
)}`,
412+
);
413+
}
414+
}
386415
}

extensions/ql-vscode/src/databases/ui/db-tree-data-provider.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
DbConfigValidationError,
1414
DbConfigValidationErrorKind,
1515
} from "../db-validation-errors";
16+
import { VariantAnalysisConfigListener } from "../../config";
1617

1718
export class DbTreeDataProvider
1819
extends DisposableObject
@@ -27,8 +28,17 @@ export class DbTreeDataProvider
2728
);
2829
private dbTreeItems: DbTreeViewItem[];
2930

31+
private variantAnalysisConfig: VariantAnalysisConfigListener;
32+
3033
public constructor(private readonly dbManager: DbManager) {
3134
super();
35+
36+
this.variantAnalysisConfig = this.push(new VariantAnalysisConfigListener());
37+
this.variantAnalysisConfig.onDidChangeConfiguration(() => {
38+
this.dbTreeItems = this.createTree();
39+
this._onDidChangeTreeData.fire(undefined);
40+
});
41+
3242
this.dbTreeItems = this.createTree();
3343
this.onDidChangeTreeData = this._onDidChangeTreeData.event;
3444

@@ -62,6 +72,11 @@ export class DbTreeDataProvider
6272
}
6373

6474
private createTree(): DbTreeViewItem[] {
75+
// Returning an empty tree here will show the welcome view
76+
if (!this.variantAnalysisConfig.controllerRepo) {
77+
return [];
78+
}
79+
6580
const dbItemsResult = this.dbManager.getDbItems();
6681

6782
if (dbItemsResult.isFailure) {

extensions/ql-vscode/src/remote-queries/run-remote-query.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,10 @@ export async function getControllerRepo(
376376
);
377377
controllerRepoNwo = await window.showInputBox({
378378
title:
379-
"Controller repository in which to run the GitHub Actions workflow for this variant analysis",
379+
"Controller repository in which to run GitHub Actions workflows for variant analyses",
380380
placeHolder: "<owner>/<repo>",
381381
prompt:
382-
"Enter the name of a GitHub repository in the format <owner>/<repo>",
382+
"Enter the name of a GitHub repository in the format <owner>/<repo>. You can change this in the extension settings.",
383383
ignoreFocusOut: true,
384384
});
385385
if (!controllerRepoNwo) {

0 commit comments

Comments
 (0)