Skip to content

Commit 403e893

Browse files
authored
Remove isVariantAnalysisReposPanelEnabled feature flag and old flows (#2096)
1 parent 61f4ce2 commit 403e893

File tree

8 files changed

+158
-824
lines changed

8 files changed

+158
-824
lines changed

extensions/ql-vscode/src/config.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -579,10 +579,6 @@ export function isVariantAnalysisLiveResultsEnabled(): boolean {
579579
return true;
580580
}
581581

582-
export function isVariantAnalysisReposPanelEnabled(): boolean {
583-
return true;
584-
}
585-
586582
// Settings for mocking the GitHub API.
587583
const MOCK_GH_API_SERVER = new Setting("mockGitHubApiServer", ROOT_SETTING);
588584

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { DbConfigStore } from "./config/db-config-store";
66
import { DbManager } from "./db-manager";
77
import { DbPanel } from "./ui/db-panel";
88
import { DbSelectionDecorationProvider } from "./ui/db-selection-decoration-provider";
9-
import { isCanary, isVariantAnalysisReposPanelEnabled } from "../config";
9+
import { isCanary } from "../config";
1010

1111
export class DbModule extends DisposableObject {
1212
public readonly dbManager: DbManager;
@@ -36,7 +36,7 @@ export class DbModule extends DisposableObject {
3636
return true;
3737
}
3838

39-
return isCanary() && isVariantAnalysisReposPanelEnabled();
39+
return isCanary();
4040
}
4141

4242
private async initialize(app: App): Promise<void> {

extensions/ql-vscode/src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ async function activateWithInstalledDistribution(
638638
cliServer,
639639
variantAnalysisStorageDir,
640640
variantAnalysisResultsManager,
641-
dbModule?.dbManager, // the dbModule is only needed when variantAnalysisReposPanel is enabled
641+
dbModule?.dbManager,
642642
);
643643
ctx.subscriptions.push(variantAnalysisManager);
644644
ctx.subscriptions.push(variantAnalysisResultsManager);
Lines changed: 23 additions & 240 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
import { pathExists as fs_pathExists, stat, readFile } from "fs-extra";
2-
import { QuickPickItem, window } from "vscode";
3-
import { extLogger } from "../common";
4-
import {
5-
getRemoteRepositoryLists,
6-
getRemoteRepositoryListsPath,
7-
isVariantAnalysisReposPanelEnabled,
8-
} from "../config";
9-
import { OWNER_REGEX, REPO_REGEX } from "../pure/helpers-pure";
101
import { UserCancellationException } from "../commandRunner";
112
import { DbManager } from "../databases/db-manager";
123
import { DbItemKind } from "../databases/db-item";
@@ -17,120 +8,42 @@ export interface RepositorySelection {
178
owners?: string[];
189
}
1910

20-
interface RepoListQuickPickItem extends QuickPickItem {
21-
repositories?: string[];
22-
repositoryList?: string;
23-
useCustomRepo?: boolean;
24-
useAllReposOfOwner?: boolean;
25-
}
26-
27-
interface RepoList {
28-
label: string;
29-
repositories: string[];
30-
}
31-
3211
/**
3312
* Gets the repositories or repository lists to run the query against.
3413
* @returns The user selection.
3514
*/
3615
export async function getRepositorySelection(
3716
dbManager?: DbManager,
3817
): Promise<RepositorySelection> {
39-
if (isVariantAnalysisReposPanelEnabled()) {
40-
const selectedDbItem = dbManager?.getSelectedDbItem();
41-
if (selectedDbItem) {
42-
switch (selectedDbItem.kind) {
43-
case DbItemKind.LocalDatabase || DbItemKind.LocalList:
18+
const selectedDbItem = dbManager?.getSelectedDbItem();
19+
if (selectedDbItem) {
20+
switch (selectedDbItem.kind) {
21+
case DbItemKind.LocalDatabase || DbItemKind.LocalList:
22+
throw new UserCancellationException(
23+
"Local databases and lists are not supported yet.",
24+
);
25+
case DbItemKind.RemoteSystemDefinedList:
26+
return { repositoryLists: [selectedDbItem.listName] };
27+
case DbItemKind.RemoteUserDefinedList:
28+
if (selectedDbItem.repos.length === 0) {
4429
throw new UserCancellationException(
45-
"Local databases and lists are not supported yet.",
30+
"The selected repository list is empty. Please add repositories to it before running a variant analysis.",
4631
);
47-
case DbItemKind.RemoteSystemDefinedList:
48-
return { repositoryLists: [selectedDbItem.listName] };
49-
case DbItemKind.RemoteUserDefinedList:
50-
if (selectedDbItem.repos.length === 0) {
51-
throw new UserCancellationException(
52-
"The selected repository list is empty. Please add repositories to it before running a variant analysis.",
53-
);
54-
} else {
55-
return {
56-
repositories: selectedDbItem.repos.map(
57-
(repo) => repo.repoFullName,
58-
),
59-
};
60-
}
61-
case DbItemKind.RemoteOwner:
62-
return { owners: [selectedDbItem.ownerName] };
63-
case DbItemKind.RemoteRepo:
64-
return { repositories: [selectedDbItem.repoFullName] };
65-
}
66-
} else {
67-
throw new UserCancellationException(
68-
"Please select a remote database to run the query against.",
69-
);
32+
} else {
33+
return {
34+
repositories: selectedDbItem.repos.map((repo) => repo.repoFullName),
35+
};
36+
}
37+
case DbItemKind.RemoteOwner:
38+
return { owners: [selectedDbItem.ownerName] };
39+
case DbItemKind.RemoteRepo:
40+
return { repositories: [selectedDbItem.repoFullName] };
7041
}
7142
}
7243

73-
const quickPickItems = [
74-
createCustomRepoQuickPickItem(),
75-
createAllReposOfOwnerQuickPickItem(),
76-
...createSystemDefinedRepoListsQuickPickItems(),
77-
...(await createUserDefinedRepoListsQuickPickItems()),
78-
];
79-
80-
const options = {
81-
placeHolder:
82-
"Select a repository list. You can define repository lists in the `codeQL.variantAnalysis.repositoryLists` setting.",
83-
ignoreFocusOut: true,
84-
};
85-
86-
const quickpick = await window.showQuickPick<RepoListQuickPickItem>(
87-
quickPickItems,
88-
options,
44+
throw new UserCancellationException(
45+
"Please select a remote database to run the query against.",
8946
);
90-
91-
if (!quickpick) {
92-
// We don't need to display a warning pop-up in this case, since the user just escaped out of the operation.
93-
// We set 'true' to make this a silent exception.
94-
throw new UserCancellationException("No repositories selected", true);
95-
}
96-
97-
if (quickpick.repositories?.length) {
98-
void extLogger.log(
99-
`Selected repositories: ${quickpick.repositories.join(", ")}`,
100-
);
101-
return { repositories: quickpick.repositories };
102-
} else if (quickpick.repositoryList) {
103-
void extLogger.log(`Selected repository list: ${quickpick.repositoryList}`);
104-
return { repositoryLists: [quickpick.repositoryList] };
105-
} else if (quickpick.useCustomRepo) {
106-
const customRepo = await getCustomRepo();
107-
if (customRepo === undefined) {
108-
// The user cancelled, do nothing.
109-
throw new UserCancellationException("No repositories selected", true);
110-
}
111-
if (!customRepo || !REPO_REGEX.test(customRepo)) {
112-
throw new UserCancellationException(
113-
"Invalid repository format. Please enter a valid repository in the format <owner>/<repo> (e.g. github/codeql)",
114-
);
115-
}
116-
void extLogger.log(`Entered repository: ${customRepo}`);
117-
return { repositories: [customRepo] };
118-
} else if (quickpick.useAllReposOfOwner) {
119-
const owner = await getOwner();
120-
if (owner === undefined) {
121-
// The user cancelled, do nothing.
122-
throw new UserCancellationException("No repositories selected", true);
123-
}
124-
if (!owner || !OWNER_REGEX.test(owner)) {
125-
throw new Error(`Invalid user or organization: ${owner}`);
126-
}
127-
void extLogger.log(`Entered owner: ${owner}`);
128-
return { owners: [owner] };
129-
} else {
130-
// This means the user has selected something, but there is nothing actually linked to this item. We want to show
131-
// this to the user.
132-
throw new UserCancellationException("No repositories selected", false);
133-
}
13447
}
13548

13649
/**
@@ -147,133 +60,3 @@ export function isValidSelection(repoSelection: RepositorySelection): boolean {
14760
repositories.length > 0 || repositoryLists.length > 0 || owners.length > 0
14861
);
14962
}
150-
151-
function createSystemDefinedRepoListsQuickPickItems(): RepoListQuickPickItem[] {
152-
const topNs = [10, 100, 1000];
153-
154-
return topNs.map(
155-
(n) =>
156-
({
157-
label: `$(star) Top ${n}`,
158-
repositoryList: `top_${n}`,
159-
alwaysShow: true,
160-
} as RepoListQuickPickItem),
161-
);
162-
}
163-
164-
async function readExternalRepoLists(): Promise<RepoList[]> {
165-
const repoLists: RepoList[] = [];
166-
167-
const path = getRemoteRepositoryListsPath();
168-
if (!path) {
169-
return repoLists;
170-
}
171-
172-
await validateExternalRepoListsFile(path);
173-
const json = await readExternalRepoListsJson(path);
174-
175-
for (const [repoListName, repositories] of Object.entries(json)) {
176-
if (!Array.isArray(repositories)) {
177-
throw Error(
178-
"Invalid repository lists file. It should contain an array of repositories for each list.",
179-
);
180-
}
181-
182-
repoLists.push({
183-
label: repoListName,
184-
repositories,
185-
});
186-
}
187-
188-
return repoLists;
189-
}
190-
191-
async function validateExternalRepoListsFile(path: string): Promise<void> {
192-
const pathExists = await fs_pathExists(path);
193-
if (!pathExists) {
194-
throw Error(`External repository lists file does not exist at ${path}`);
195-
}
196-
197-
const pathStat = await stat(path);
198-
if (pathStat.isDirectory()) {
199-
throw Error(
200-
"External repository lists path should not point to a directory",
201-
);
202-
}
203-
}
204-
205-
async function readExternalRepoListsJson(
206-
path: string,
207-
): Promise<Record<string, unknown>> {
208-
let json;
209-
210-
try {
211-
const fileContents = await readFile(path, "utf8");
212-
json = await JSON.parse(fileContents);
213-
} catch (error) {
214-
throw Error("Invalid repository lists file. It should contain valid JSON.");
215-
}
216-
217-
if (Array.isArray(json)) {
218-
throw Error(
219-
"Invalid repository lists file. It should be an object mapping names to a list of repositories.",
220-
);
221-
}
222-
223-
return json;
224-
}
225-
226-
function readRepoListsFromSettings(): RepoList[] {
227-
const repoLists = getRemoteRepositoryLists();
228-
if (!repoLists) {
229-
return [];
230-
}
231-
232-
return Object.entries(repoLists).map<RepoList>(([label, repositories]) => ({
233-
label,
234-
repositories,
235-
}));
236-
}
237-
238-
async function createUserDefinedRepoListsQuickPickItems(): Promise<
239-
RepoListQuickPickItem[]
240-
> {
241-
const repoListsFromSetings = readRepoListsFromSettings();
242-
const repoListsFromExternalFile = await readExternalRepoLists();
243-
244-
return [...repoListsFromSetings, ...repoListsFromExternalFile];
245-
}
246-
247-
function createCustomRepoQuickPickItem(): RepoListQuickPickItem {
248-
return {
249-
label: "$(edit) Enter a GitHub repository",
250-
useCustomRepo: true,
251-
alwaysShow: true,
252-
};
253-
}
254-
255-
function createAllReposOfOwnerQuickPickItem(): RepoListQuickPickItem {
256-
return {
257-
label: "$(edit) Enter a GitHub user or organization",
258-
useAllReposOfOwner: true,
259-
alwaysShow: true,
260-
};
261-
}
262-
263-
async function getCustomRepo(): Promise<string | undefined> {
264-
return await window.showInputBox({
265-
title:
266-
"Enter a GitHub repository in the format <owner>/<repo> (e.g. github/codeql)",
267-
placeHolder: "<owner>/<repo>",
268-
prompt:
269-
"Tip: you can save frequently used repositories in the `codeQL.variantAnalysis.repositoryLists` setting",
270-
ignoreFocusOut: true,
271-
});
272-
}
273-
274-
async function getOwner(): Promise<string | undefined> {
275-
return await window.showInputBox({
276-
title: "Enter a GitHub user or organization",
277-
ignoreFocusOut: true,
278-
});
279-
}

extensions/ql-vscode/src/variant-analysis/run-remote-query.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ export async function prepareRemoteQueryRun(
223223
uri: Uri | undefined,
224224
progress: ProgressCallback,
225225
token: CancellationToken,
226-
dbManager?: DbManager, // the dbManager is only needed when variantAnalysisReposPanel is enabled
226+
dbManager?: DbManager,
227227
): Promise<PreparedRemoteQuery> {
228228
if (!uri?.fsPath.endsWith(".ql")) {
229229
throw new UserCancellationException("Not a CodeQL query file.");

extensions/ql-vscode/src/variant-analysis/variant-analysis-manager.ts

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ import {
6060
} from "../pure/variant-analysis-filter-sort";
6161
import { URLSearchParams } from "url";
6262
import { DbManager } from "../databases/db-manager";
63-
import { isVariantAnalysisReposPanelEnabled } from "../config";
6463
import { App } from "../common/app";
6564
import { redactableError } from "../pure/errors";
6665

@@ -106,7 +105,7 @@ export class VariantAnalysisManager
106105
private readonly cliServer: CodeQLCliServer,
107106
private readonly storagePath: string,
108107
private readonly variantAnalysisResultsManager: VariantAnalysisResultsManager,
109-
private readonly dbManager?: DbManager, // the dbManager is only needed when variantAnalysisReposPanel is enabled
108+
private readonly dbManager?: DbManager,
110109
) {
111110
super();
112111
this.variantAnalysisMonitor = this.push(
@@ -635,25 +634,15 @@ export class VariantAnalysisManager
635634
return;
636635
}
637636

638-
let text: string[];
639-
if (isVariantAnalysisReposPanelEnabled()) {
640-
text = [
641-
"{",
642-
` "name": "new-repo-list",`,
643-
` "repositories": [`,
644-
...fullNames.slice(0, -1).map((repo) => ` "${repo}",`),
645-
` "${fullNames[fullNames.length - 1]}"`,
646-
` ]`,
647-
"}",
648-
];
649-
} else {
650-
text = [
651-
'"new-repo-list": [',
652-
...fullNames.slice(0, -1).map((repo) => ` "${repo}",`),
653-
` "${fullNames[fullNames.length - 1]}"`,
654-
"]",
655-
];
656-
}
637+
const text = [
638+
"{",
639+
` "name": "new-repo-list",`,
640+
` "repositories": [`,
641+
...fullNames.slice(0, -1).map((repo) => ` "${repo}",`),
642+
` "${fullNames[fullNames.length - 1]}"`,
643+
` ]`,
644+
"}",
645+
];
657646

658647
await env.clipboard.writeText(text.join(EOL));
659648
}

0 commit comments

Comments
 (0)