Skip to content

Commit 4a8ba13

Browse files
committed
Don't offer to create skeleton pack again
When running Create Query in the codespaces-codeql repo, it successfully creates codeql-custom-queries-xxx as a subfolder of the first workspace folder, and then adds a database. After the database gets added, we get prompted with this message: ``` We've noticed you don't have a CodeQL pack available to analyze this database. Can we set up a query pack for you? ``` which would try to create another QL pack. Since we're no longer pushing QL packs as top level folders in the workspace when we use the new "Create Query" flow, we also need to adapt the original flow to take into account subfolders. Just as a reminder, the original flow is: - Be in the codespace template - Download a database from GitHub - The extension will offer to create a QL pack for the database The new flow: - Run the "Create Query" command - Choose a language - Create a QL pack - Download a database for it In the new flow the last step of downloading a database would trigger the extension to offer to create a QL pack. Let's fix this by detecting subfolders as well and exiting early.
1 parent b6eaf93 commit 4a8ba13

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

extensions/ql-vscode/src/local-databases.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { isCodespacesTemplate } from "./config";
3030
import { QlPackGenerator } from "./qlpack-generator";
3131
import { QueryLanguage } from "./common/query-language";
3232
import { App } from "./common/app";
33+
import { existsSync } from "fs";
3334

3435
/**
3536
* databases.ts
@@ -663,8 +664,13 @@ export class DatabaseManager extends DisposableObject {
663664
return;
664665
}
665666

667+
const firstWorkspaceFolder = getFirstWorkspaceFolder();
666668
const folderName = `codeql-custom-queries-${databaseItem.language}`;
667-
if (isFolderAlreadyInWorkspace(folderName)) {
669+
670+
if (
671+
existsSync(join(firstWorkspaceFolder, folderName)) ||
672+
isFolderAlreadyInWorkspace(folderName)
673+
) {
668674
return;
669675
}
670676

@@ -677,8 +683,6 @@ export class DatabaseManager extends DisposableObject {
677683
}
678684

679685
try {
680-
const firstWorkspaceFolder = getFirstWorkspaceFolder();
681-
682686
const qlPackGenerator = new QlPackGenerator(
683687
folderName,
684688
databaseItem.language as QueryLanguage,

extensions/ql-vscode/src/skeleton-query-wizard.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { QlPackGenerator } from "./qlpack-generator";
1414
import { DatabaseItem, DatabaseManager } from "./local-databases";
1515
import { ProgressCallback, UserCancellationException } from "./progress";
1616
import { askForGitHubRepo, downloadGitHubDatabase } from "./databaseFetcher";
17+
import { existsSync } from "fs";
1718

1819
type QueryLanguagesToDatabaseMap = Record<string, string>;
1920

@@ -56,9 +57,9 @@ export class SkeletonQueryWizard {
5657

5758
this.qlPackStoragePath = getFirstWorkspaceFolder();
5859

59-
const skeletonPackAlreadyExists = isFolderAlreadyInWorkspace(
60-
this.folderName,
61-
);
60+
const skeletonPackAlreadyExists =
61+
existsSync(join(this.qlPackStoragePath, this.folderName)) ||
62+
isFolderAlreadyInWorkspace(this.folderName);
6263

6364
if (skeletonPackAlreadyExists) {
6465
// just create a new example query file in skeleton QL pack

extensions/ql-vscode/test/vscode-tests/minimal-workspace/local-databases.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,22 @@ describe("local databases", () => {
687687
);
688688
});
689689
});
690+
691+
describe("when the QL pack already exists", () => {
692+
beforeEach(() => {
693+
fs.mkdirSync(join(dir.name, `codeql-custom-queries-${language}`));
694+
});
695+
696+
it("should exit early", async () => {
697+
showBinaryChoiceDialogSpy = jest
698+
.spyOn(helpers, "showBinaryChoiceDialog")
699+
.mockResolvedValue(false);
700+
701+
await (databaseManager as any).createSkeletonPacks(mockDbItem);
702+
703+
expect(generateSpy).not.toBeCalled();
704+
});
705+
});
690706
});
691707

692708
describe("openDatabase", () => {

0 commit comments

Comments
 (0)