From 766743629d411fe19540e13780eed2718fc09e3b Mon Sep 17 00:00:00 2001 From: "Babak K. Shandiz" Date: Fri, 10 Jun 2022 12:54:37 +0000 Subject: [PATCH] Polish PR template picker (#151415) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🔨 Set ignoreFocusOut to true on PR template selection Signed-off-by: Babak K. Shandiz * 🔨 Translate PR template paths to relative in quick pick list Signed-off-by: Babak K. Shandiz * 💄 Shorten line length Signed-off-by: Babak K. Shandiz * ⚗️ Update tests with latest required args Signed-off-by: Babak K. Shandiz * ⚗️ Update GitHub extension unit tests Signed-off-by: Babak K. Shandiz Co-authored-by: João Moreno --- extensions/github/src/pushErrorHandler.ts | 12 +++++++----- extensions/github/src/test/github.test.ts | 22 +++++++++++----------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/extensions/github/src/pushErrorHandler.ts b/extensions/github/src/pushErrorHandler.ts index 2ddae480c2c8e..f054df8941db9 100644 --- a/extensions/github/src/pushErrorHandler.ts +++ b/extensions/github/src/pushErrorHandler.ts @@ -21,8 +21,9 @@ export function isInCodespaces(): boolean { async function handlePushError(repository: Repository, remote: Remote, refspec: string, owner: string, repo: string): Promise { 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; } @@ -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)); @@ -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 { - const quickPickItemFromUri = (x: Uri) => ({ label: x.path, template: x }); +export async function pickPullRequestTemplate(repositoryRootUri: Uri, templates: Uri[]): Promise { + const quickPickItemFromUri = (x: Uri) => ({ label: path.relative(repositoryRootUri.path, x.path), template: x }); const quickPickItems = [ { label: localize('no pr template', "No template"), @@ -202,7 +203,8 @@ export async function pickPullRequestTemplate(templates: Uri[]): Promise { 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');