MRVA: Don't show notification if user aborts firing off a query (#1417)

This commit is contained in:
Charis Kyriakou
2022-06-30 14:35:33 +01:00
committed by GitHub
parent a40a2edaf2
commit ebad1844df
2 changed files with 35 additions and 1 deletions

View File

@@ -52,6 +52,10 @@ export async function getRepositorySelection(): Promise<RepositorySelection> {
return { repositoryLists: [quickpick.repositoryList] };
} else if (quickpick?.useCustomRepo) {
const customRepo = await getCustomRepo();
if (customRepo === undefined) {
// The user cancelled, do nothing.
throw new UserCancellationException('No repositories selected', true);
}
if (!customRepo || !REPO_REGEX.test(customRepo)) {
throw new UserCancellationException('Invalid repository format. Please enter a valid repository in the format <owner>/<repo> (e.g. github/codeql)');
}
@@ -59,6 +63,10 @@ export async function getRepositorySelection(): Promise<RepositorySelection> {
return { repositories: [customRepo] };
} else if (quickpick?.useAllReposOfOwner) {
const owner = await getOwner();
if (owner === undefined) {
// The user cancelled, do nothing.
throw new UserCancellationException('No repositories selected', true);
}
if (!owner || !OWNER_REGEX.test(owner)) {
throw new Error(`Invalid user or organization: ${owner}`);
}
@@ -197,6 +205,6 @@ async function getCustomRepo(): Promise<string | undefined> {
async function getOwner(): Promise<string | undefined> {
return await window.showInputBox({
title: 'Enter a GitHub user or organization',
ignoreFocusOut: true,
ignoreFocusOut: true
});
}

View File

@@ -100,7 +100,9 @@ describe('repository selection', async () => {
['top_100']
);
});
});
describe('custom owner', async () => {
// Test the owner regex in various "good" cases
const goodOwners = [
'owner',
@@ -146,6 +148,18 @@ describe('repository selection', async () => {
await expect(mod.getRepositorySelection()).to.be.rejectedWith(Error, `Invalid user or organization: ${owner}`);
});
});
it('should be ok for the user to change their mind', async () => {
quickPickSpy.resolves(
{ useAllReposOfOwner: true }
);
getRemoteRepositoryListsSpy.returns({});
// The user pressed escape to cancel the operation
showInputBoxSpy.resolves(undefined);
await expect(mod.getRepositorySelection()).to.be.rejectedWith(UserCancellationException, 'No repositories selected');
});
});
describe('custom repo', async () => {
@@ -196,6 +210,18 @@ describe('repository selection', async () => {
await expect(mod.getRepositorySelection()).to.be.rejectedWith(UserCancellationException, 'Invalid repository format');
});
});
it('should be ok for the user to change their mind', async () => {
quickPickSpy.resolves(
{ useCustomRepo: true }
);
getRemoteRepositoryListsSpy.returns({});
// The user pressed escape to cancel the operation
showInputBoxSpy.resolves(undefined);
await expect(mod.getRepositorySelection()).to.be.rejectedWith(UserCancellationException, 'No repositories selected');
});
});
describe('external repository lists file', async () => {