Skip to content

Commit ebad184

Browse files
authored
MRVA: Don't show notification if user aborts firing off a query (#1417)
1 parent a40a2ed commit ebad184

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

extensions/ql-vscode/src/remote-queries/repository-selection.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,21 @@ export async function getRepositorySelection(): Promise<RepositorySelection> {
5252
return { repositoryLists: [quickpick.repositoryList] };
5353
} else if (quickpick?.useCustomRepo) {
5454
const customRepo = await getCustomRepo();
55+
if (customRepo === undefined) {
56+
// The user cancelled, do nothing.
57+
throw new UserCancellationException('No repositories selected', true);
58+
}
5559
if (!customRepo || !REPO_REGEX.test(customRepo)) {
5660
throw new UserCancellationException('Invalid repository format. Please enter a valid repository in the format <owner>/<repo> (e.g. github/codeql)');
5761
}
5862
void logger.log(`Entered repository: ${customRepo}`);
5963
return { repositories: [customRepo] };
6064
} else if (quickpick?.useAllReposOfOwner) {
6165
const owner = await getOwner();
66+
if (owner === undefined) {
67+
// The user cancelled, do nothing.
68+
throw new UserCancellationException('No repositories selected', true);
69+
}
6270
if (!owner || !OWNER_REGEX.test(owner)) {
6371
throw new Error(`Invalid user or organization: ${owner}`);
6472
}
@@ -197,6 +205,6 @@ async function getCustomRepo(): Promise<string | undefined> {
197205
async function getOwner(): Promise<string | undefined> {
198206
return await window.showInputBox({
199207
title: 'Enter a GitHub user or organization',
200-
ignoreFocusOut: true,
208+
ignoreFocusOut: true
201209
});
202210
}

extensions/ql-vscode/src/vscode-tests/no-workspace/remote-queries/repository-selection.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ describe('repository selection', async () => {
100100
['top_100']
101101
);
102102
});
103+
});
103104

105+
describe('custom owner', async () => {
104106
// Test the owner regex in various "good" cases
105107
const goodOwners = [
106108
'owner',
@@ -146,6 +148,18 @@ describe('repository selection', async () => {
146148
await expect(mod.getRepositorySelection()).to.be.rejectedWith(Error, `Invalid user or organization: ${owner}`);
147149
});
148150
});
151+
152+
it('should be ok for the user to change their mind', async () => {
153+
quickPickSpy.resolves(
154+
{ useAllReposOfOwner: true }
155+
);
156+
getRemoteRepositoryListsSpy.returns({});
157+
158+
// The user pressed escape to cancel the operation
159+
showInputBoxSpy.resolves(undefined);
160+
161+
await expect(mod.getRepositorySelection()).to.be.rejectedWith(UserCancellationException, 'No repositories selected');
162+
});
149163
});
150164

151165
describe('custom repo', async () => {
@@ -196,6 +210,18 @@ describe('repository selection', async () => {
196210
await expect(mod.getRepositorySelection()).to.be.rejectedWith(UserCancellationException, 'Invalid repository format');
197211
});
198212
});
213+
214+
it('should be ok for the user to change their mind', async () => {
215+
quickPickSpy.resolves(
216+
{ useCustomRepo: true }
217+
);
218+
getRemoteRepositoryListsSpy.returns({});
219+
220+
// The user pressed escape to cancel the operation
221+
showInputBoxSpy.resolves(undefined);
222+
223+
await expect(mod.getRepositorySelection()).to.be.rejectedWith(UserCancellationException, 'No repositories selected');
224+
});
199225
});
200226

201227
describe('external repository lists file', async () => {

0 commit comments

Comments
 (0)