Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,21 @@ 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)');
}
void logger.log(`Entered repository: ${customRepo}`);
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}`);
}
Expand Down Expand Up @@ -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
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down