Remember user's choice to not be prompted again
By writing the setting to our new `codeQL.autogenerateQlPacks` setting.
This commit is contained in:
@@ -10,8 +10,8 @@ import {
|
||||
isLikelyDatabaseRoot,
|
||||
showAndLogExceptionWithTelemetry,
|
||||
isFolderAlreadyInWorkspace,
|
||||
showBinaryChoiceDialog,
|
||||
getFirstWorkspaceFolder,
|
||||
showNeverAskAgainDialog,
|
||||
} from "../helpers";
|
||||
import { ProgressCallback, withProgress } from "../progress";
|
||||
import {
|
||||
@@ -26,7 +26,11 @@ import { asError, getErrorMessage } from "../pure/helpers-pure";
|
||||
import { QueryRunner } from "../query-server";
|
||||
import { pathsEqual } from "../pure/files";
|
||||
import { redactableError } from "../pure/errors";
|
||||
import { isCodespacesTemplate } from "../config";
|
||||
import {
|
||||
getAutogenerateQlPacks,
|
||||
isCodespacesTemplate,
|
||||
setAutogenerateQlPacks,
|
||||
} from "../config";
|
||||
import { QlPackGenerator } from "../qlpack-generator";
|
||||
import { QueryLanguage } from "../common/query-language";
|
||||
import { App } from "../common/app";
|
||||
@@ -742,11 +746,20 @@ export class DatabaseManager extends DisposableObject {
|
||||
return;
|
||||
}
|
||||
|
||||
const answer = await showBinaryChoiceDialog(
|
||||
if (getAutogenerateQlPacks() === "No, and never ask me again") {
|
||||
return;
|
||||
}
|
||||
|
||||
const answer = await showNeverAskAgainDialog(
|
||||
`We've noticed you don't have a CodeQL pack available to analyze this database. Can we set up a query pack for you?`,
|
||||
);
|
||||
|
||||
if (!answer) {
|
||||
if (answer === "No") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (answer === "No, and never ask me again") {
|
||||
await setAutogenerateQlPacks("No, and never ask me again");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,8 +44,8 @@ describe("local databases", () => {
|
||||
let packAddSpy: jest.Mock<any, []>;
|
||||
let logSpy: jest.Mock<any, []>;
|
||||
|
||||
let showBinaryChoiceDialogSpy: jest.SpiedFunction<
|
||||
typeof helpers.showBinaryChoiceDialog
|
||||
let showNeverAskAgainDialogSpy: jest.SpiedFunction<
|
||||
typeof helpers.showNeverAskAgainDialog
|
||||
>;
|
||||
|
||||
let dir: tmp.DirResult;
|
||||
@@ -63,9 +63,9 @@ describe("local databases", () => {
|
||||
/* */
|
||||
});
|
||||
|
||||
showBinaryChoiceDialogSpy = jest
|
||||
.spyOn(helpers, "showBinaryChoiceDialog")
|
||||
.mockResolvedValue(true);
|
||||
showNeverAskAgainDialogSpy = jest
|
||||
.spyOn(helpers, "showNeverAskAgainDialog")
|
||||
.mockResolvedValue("Yes");
|
||||
|
||||
extensionContextStoragePath = dir.name;
|
||||
|
||||
@@ -646,22 +646,51 @@ describe("local databases", () => {
|
||||
});
|
||||
|
||||
describe("when the language is set", () => {
|
||||
let originalValue: string | undefined;
|
||||
|
||||
beforeEach(() => {
|
||||
originalValue = workspace
|
||||
.getConfiguration("codeQL")
|
||||
.get("autogenerateQlPacks");
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await workspace
|
||||
.getConfiguration("codeQL")
|
||||
.update("autogenerateQlPacks", originalValue);
|
||||
});
|
||||
|
||||
it("should offer the user to set up a skeleton QL pack", async () => {
|
||||
await (databaseManager as any).createSkeletonPacks(mockDbItem);
|
||||
|
||||
expect(showBinaryChoiceDialogSpy).toBeCalledTimes(1);
|
||||
expect(showNeverAskAgainDialogSpy).toBeCalledTimes(1);
|
||||
});
|
||||
|
||||
it("should return early if the user refuses help", async () => {
|
||||
showBinaryChoiceDialogSpy = jest
|
||||
.spyOn(helpers, "showBinaryChoiceDialog")
|
||||
.mockResolvedValue(false);
|
||||
showNeverAskAgainDialogSpy = jest
|
||||
.spyOn(helpers, "showNeverAskAgainDialog")
|
||||
.mockResolvedValue("No");
|
||||
|
||||
await (databaseManager as any).createSkeletonPacks(mockDbItem);
|
||||
|
||||
expect(generateSpy).not.toBeCalled();
|
||||
});
|
||||
|
||||
it("should return early and write choice to settings if user wants to never be asked again", async () => {
|
||||
showNeverAskAgainDialogSpy = jest
|
||||
.spyOn(helpers, "showNeverAskAgainDialog")
|
||||
.mockResolvedValue("No, and never ask me again");
|
||||
const updateValueSpy = jest.spyOn(Setting.prototype, "updateValue");
|
||||
|
||||
await (databaseManager as any).createSkeletonPacks(mockDbItem);
|
||||
|
||||
expect(generateSpy).not.toBeCalled();
|
||||
expect(updateValueSpy).toHaveBeenCalledWith(
|
||||
"No, and never ask me again",
|
||||
1,
|
||||
);
|
||||
});
|
||||
|
||||
it("should create the skeleton QL pack for the user", async () => {
|
||||
await (databaseManager as any).createSkeletonPacks(mockDbItem);
|
||||
|
||||
@@ -694,9 +723,9 @@ describe("local databases", () => {
|
||||
});
|
||||
|
||||
it("should exit early", async () => {
|
||||
showBinaryChoiceDialogSpy = jest
|
||||
.spyOn(helpers, "showBinaryChoiceDialog")
|
||||
.mockResolvedValue(false);
|
||||
showNeverAskAgainDialogSpy = jest
|
||||
.spyOn(helpers, "showNeverAskAgainDialog")
|
||||
.mockResolvedValue("No");
|
||||
|
||||
await (databaseManager as any).createSkeletonPacks(mockDbItem);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user