diff --git a/package.json b/package.json index 43ddddc866..beaea34b0f 100644 --- a/package.json +++ b/package.json @@ -146,12 +146,14 @@ "enum": [ "template", "commit", + "branchName", "none", "Copilot" ], "enumDescriptions": [ "%githubPullRequests.pullRequestDescription.template%", "%githubPullRequests.pullRequestDescription.commit%", + "%githubPullRequests.pullRequestDescription.branchName%", "%githubPullRequests.pullRequestDescription.none%", "%githubPullRequests.pullRequestDescription.copilot%" ], diff --git a/package.nls.json b/package.nls.json index aa5358921e..66088edc78 100644 --- a/package.nls.json +++ b/package.nls.json @@ -4,6 +4,7 @@ "githubPullRequests.pullRequestDescription.description": "The description used when creating pull requests.", "githubPullRequests.pullRequestDescription.template": "Use a pull request template and commit description, or just use the commit description if no templates were found.", "githubPullRequests.pullRequestDescription.commit": "Use the latest commit message only.", + "githubPullRequests.pullRequestDescription.branchName": "Use the branch name as the pull request title", "githubPullRequests.pullRequestDescription.none": "Do not have a default description.", "githubPullRequests.pullRequestDescription.copilot": "Generate a pull request title and description from GitHub Copilot. Requires that the GitHub Copilot extension is installed and authenticated. Will fall back to `commit` if Copilot is not set up.", "githubPullRequests.defaultCreateOption.description": "The create option that the \"Create\" button will default to when creating a pull request.", diff --git a/src/github/createPRViewProvider.ts b/src/github/createPRViewProvider.ts index 13f49701a5..89c89b441c 100644 --- a/src/github/createPRViewProvider.ts +++ b/src/github/createPRViewProvider.ts @@ -245,7 +245,7 @@ export abstract class BaseCreatePullRequestViewProvider(PULL_REQUEST_DESCRIPTION) === 'Copilot'); + const useCopilot: boolean = !!this.getTitleAndDescriptionProvider('Copilot') && (vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<'commit' | 'template' | 'branchName' | 'none' | 'Copilot'>(PULL_REQUEST_DESCRIPTION) === 'Copilot'); const defaultTitleAndDescriptionProvider = this.getTitleAndDescriptionProvider()?.title; if (defaultTitleAndDescriptionProvider) { /* __GDPR__ @@ -709,8 +709,21 @@ export class CreatePullRequestViewProvider extends BaseCreatePullRequestViewProv protected async getTitleAndDescription(compareBranch: Branch, baseBranch: string): Promise<{ title: string, description: string }> { let title: string = ''; let description: string = ''; - const descrptionSource = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<'commit' | 'template' | 'none' | 'Copilot'>(PULL_REQUEST_DESCRIPTION); - if (descrptionSource === 'none') { + const descriptionSource = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<'commit' | 'template' | 'branchName' | 'none' | 'Copilot'>(PULL_REQUEST_DESCRIPTION); + if (descriptionSource === 'none') { + return { title, description }; + } + + const name = compareBranch.name; + const branchNameTitle = (name: string) => { + return `${name.charAt(0).toUpperCase()}${name.slice(1)}`; + }; + + // If branchName is selected, use the branch name as the title + if (descriptionSource === 'branchName') { + if (name) { + title = branchNameTitle(name); + } return { title, description }; } @@ -722,11 +735,10 @@ export class CreatePullRequestViewProvider extends BaseCreatePullRequestViewProv let useBranchName = this._pullRequestDefaults.base === compareBranch.name; Logger.debug(`Compare branch name: ${compareBranch.name}, Base branch name: ${this._pullRequestDefaults.base}`, CreatePullRequestViewProvider.ID); try { - const name = compareBranch.name; const [totalCommits, lastCommit, pullRequestTemplate] = await Promise.all([ this.getTotalGitHubCommits(compareBranch, baseBranch), name ? titleAndBodyFrom(promiseWithTimeout(this._folderRepositoryManager.getTipCommitMessage(name), 5000)) : undefined, - descrptionSource === 'template' ? this.getPullRequestTemplate() : undefined + descriptionSource === 'template' ? this.getPullRequestTemplate() : undefined ]); const totalNonMergeCommits = totalCommits?.filter(commit => commit.parents.length < 2); @@ -748,7 +760,7 @@ export class CreatePullRequestViewProvider extends BaseCreatePullRequestViewProv } // Set title if (useBranchName && name) { - title = `${name.charAt(0).toUpperCase()}${name.slice(1)}`; + title = branchNameTitle(name); } else if (name && lastCommit) { title = lastCommit.title; }