Skip to content

Commit

Permalink
Polish PR template picker (#151415)
Browse files Browse the repository at this point in the history
* 🔨 Set ignoreFocusOut to true on PR template selection

Signed-off-by: Babak K. Shandiz <babak.k.shandiz@gmail.com>

* 🔨 Translate PR template paths to relative in quick pick list

Signed-off-by: Babak K. Shandiz <babak.k.shandiz@gmail.com>

* 💄 Shorten line length

Signed-off-by: Babak K. Shandiz <babak.k.shandiz@gmail.com>

* ⚗️ Update tests with latest required args

Signed-off-by: Babak K. Shandiz <babak.k.shandiz@gmail.com>

* ⚗️ Update GitHub extension unit tests

Signed-off-by: Babak K. Shandiz <babak.k.shandiz@gmail.com>

Co-authored-by: João Moreno <joao.moreno@microsoft.com>
  • Loading branch information
babakks and joaomoreno authored Jun 10, 2022
1 parent 85323c1 commit 7667436
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
12 changes: 7 additions & 5 deletions extensions/github/src/pushErrorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ export function isInCodespaces(): boolean {
async function handlePushError(repository: Repository, remote: Remote, refspec: string, owner: string, repo: string): Promise<void> {
const yes = localize('create a fork', "Create Fork");
const no = localize('no', "No");
const askFork = localize('fork', "You don't have permissions to push to '{0}/{1}' on GitHub. Would you like to create a fork and push to it instead?", owner, repo);

const answer = await window.showInformationMessage(localize('fork', "You don't have permissions to push to '{0}/{1}' on GitHub. Would you like to create a fork and push to it instead?", owner, repo), yes, no);
const answer = await window.showInformationMessage(askFork, yes, no);
if (answer !== yes) {
return;
}
Expand Down Expand Up @@ -114,7 +115,7 @@ async function handlePushError(repository: Repository, remote: Remote, refspec:
if (templates.length > 0) {
templates.sort((a, b) => a.path.localeCompare(b.path));

const template = await pickPullRequestTemplate(templates);
const template = await pickPullRequestTemplate(repository.rootUri, templates);

if (template) {
body = new TextDecoder('utf-8').decode(await workspace.fs.readFile(template));
Expand Down Expand Up @@ -191,8 +192,8 @@ export async function findPullRequestTemplates(repositoryRootUri: Uri): Promise<
return results.flatMap(x => x.status === 'fulfilled' && x.value || []);
}

export async function pickPullRequestTemplate(templates: Uri[]): Promise<Uri | undefined> {
const quickPickItemFromUri = (x: Uri) => ({ label: x.path, template: x });
export async function pickPullRequestTemplate(repositoryRootUri: Uri, templates: Uri[]): Promise<Uri | undefined> {
const quickPickItemFromUri = (x: Uri) => ({ label: path.relative(repositoryRootUri.path, x.path), template: x });
const quickPickItems = [
{
label: localize('no pr template', "No template"),
Expand All @@ -202,7 +203,8 @@ export async function pickPullRequestTemplate(templates: Uri[]): Promise<Uri | u
...templates.map(quickPickItemFromUri)
];
const quickPickOptions: QuickPickOptions = {
placeHolder: localize('select pr template', "Select the Pull Request template")
placeHolder: localize('select pr template', "Select the Pull Request template"),
ignoreFocusOut: true
};
const pickedTemplate = await window.showQuickPick(quickPickItems, quickPickOptions);
return pickedTemplate?.template;
Expand Down
22 changes: 11 additions & 11 deletions extensions/github/src/test/github.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ suite('github smoke test', function () {

test('should find all templates', async function () {
const expectedValuesSorted = [
'/PULL_REQUEST_TEMPLATE/a.md',
'/PULL_REQUEST_TEMPLATE/b.md',
'/docs/PULL_REQUEST_TEMPLATE.md',
'/docs/PULL_REQUEST_TEMPLATE/a.md',
'/docs/PULL_REQUEST_TEMPLATE/b.md',
'/.github/PULL_REQUEST_TEMPLATE.md',
'/.github/PULL_REQUEST_TEMPLATE/a.md',
'/.github/PULL_REQUEST_TEMPLATE/b.md',
'/PULL_REQUEST_TEMPLATE.md'
'PULL_REQUEST_TEMPLATE/a.md',
'PULL_REQUEST_TEMPLATE/b.md',
'docs/PULL_REQUEST_TEMPLATE.md',
'docs/PULL_REQUEST_TEMPLATE/a.md',
'docs/PULL_REQUEST_TEMPLATE/b.md',
'.github/PULL_REQUEST_TEMPLATE.md',
'.github/PULL_REQUEST_TEMPLATE/a.md',
'.github/PULL_REQUEST_TEMPLATE/b.md',
'PULL_REQUEST_TEMPLATE.md'
];
expectedValuesSorted.sort();

Expand All @@ -43,7 +43,7 @@ suite('github smoke test', function () {
const template1 = Uri.file("some-imaginary-template-1");
const templates = [template0, template1];

const pick = pickPullRequestTemplate(templates);
const pick = pickPullRequestTemplate(Uri.file("/"), templates);

await commands.executeCommand('workbench.action.quickOpenSelectNext');
await commands.executeCommand('workbench.action.quickOpenSelectNext');
Expand All @@ -55,7 +55,7 @@ suite('github smoke test', function () {
test('selecting first quick-pick item should return undefined', async () => {
const templates = [Uri.file("some-imaginary-file")];

const pick = pickPullRequestTemplate(templates);
const pick = pickPullRequestTemplate(Uri.file("/"), templates);

await commands.executeCommand('workbench.action.quickOpenSelectNext');
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
Expand Down

0 comments on commit 7667436

Please sign in to comment.