Skip to content

Commit 6436221

Browse files
Copilotalexr00
andauthored
Add branchName option to pullRequestDescription setting (#8275)
* Initial plan * Initial plan for adding branchName option to pullRequestDescription setting Co-authored-by: alexr00 <[email protected]> * Add branchName option to pullRequestDescription setting Co-authored-by: alexr00 <[email protected]> * Address code review feedback: fix typo and add missing type definition Co-authored-by: alexr00 <[email protected]> * Clean up --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: alexr00 <[email protected]>
1 parent 0bed968 commit 6436221

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,14 @@
146146
"enum": [
147147
"template",
148148
"commit",
149+
"branchName",
149150
"none",
150151
"Copilot"
151152
],
152153
"enumDescriptions": [
153154
"%githubPullRequests.pullRequestDescription.template%",
154155
"%githubPullRequests.pullRequestDescription.commit%",
156+
"%githubPullRequests.pullRequestDescription.branchName%",
155157
"%githubPullRequests.pullRequestDescription.none%",
156158
"%githubPullRequests.pullRequestDescription.copilot%"
157159
],

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"githubPullRequests.pullRequestDescription.description": "The description used when creating pull requests.",
55
"githubPullRequests.pullRequestDescription.template": "Use a pull request template and commit description, or just use the commit description if no templates were found.",
66
"githubPullRequests.pullRequestDescription.commit": "Use the latest commit message only.",
7+
"githubPullRequests.pullRequestDescription.branchName": "Use the branch name as the pull request title",
78
"githubPullRequests.pullRequestDescription.none": "Do not have a default description.",
89
"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.",
910
"githubPullRequests.defaultCreateOption.description": "The create option that the \"Create\" button will default to when creating a pull request.",

src/github/createPRViewProvider.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ export abstract class BaseCreatePullRequestViewProvider<T extends BasePullReques
245245
}
246246
commands.setContext(contexts.CREATE_PR_PERMISSIONS, viewerPermission);
247247

248-
const useCopilot: boolean = !!this.getTitleAndDescriptionProvider('Copilot') && (vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<'commit' | 'template' | 'none' | 'Copilot'>(PULL_REQUEST_DESCRIPTION) === 'Copilot');
248+
const useCopilot: boolean = !!this.getTitleAndDescriptionProvider('Copilot') && (vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<'commit' | 'template' | 'branchName' | 'none' | 'Copilot'>(PULL_REQUEST_DESCRIPTION) === 'Copilot');
249249
const defaultTitleAndDescriptionProvider = this.getTitleAndDescriptionProvider()?.title;
250250
if (defaultTitleAndDescriptionProvider) {
251251
/* __GDPR__
@@ -709,8 +709,21 @@ export class CreatePullRequestViewProvider extends BaseCreatePullRequestViewProv
709709
protected async getTitleAndDescription(compareBranch: Branch, baseBranch: string): Promise<{ title: string, description: string }> {
710710
let title: string = '';
711711
let description: string = '';
712-
const descrptionSource = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<'commit' | 'template' | 'none' | 'Copilot'>(PULL_REQUEST_DESCRIPTION);
713-
if (descrptionSource === 'none') {
712+
const descriptionSource = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<'commit' | 'template' | 'branchName' | 'none' | 'Copilot'>(PULL_REQUEST_DESCRIPTION);
713+
if (descriptionSource === 'none') {
714+
return { title, description };
715+
}
716+
717+
const name = compareBranch.name;
718+
const branchNameTitle = (name: string) => {
719+
return `${name.charAt(0).toUpperCase()}${name.slice(1)}`;
720+
};
721+
722+
// If branchName is selected, use the branch name as the title
723+
if (descriptionSource === 'branchName') {
724+
if (name) {
725+
title = branchNameTitle(name);
726+
}
714727
return { title, description };
715728
}
716729

@@ -722,11 +735,10 @@ export class CreatePullRequestViewProvider extends BaseCreatePullRequestViewProv
722735
let useBranchName = this._pullRequestDefaults.base === compareBranch.name;
723736
Logger.debug(`Compare branch name: ${compareBranch.name}, Base branch name: ${this._pullRequestDefaults.base}`, CreatePullRequestViewProvider.ID);
724737
try {
725-
const name = compareBranch.name;
726738
const [totalCommits, lastCommit, pullRequestTemplate] = await Promise.all([
727739
this.getTotalGitHubCommits(compareBranch, baseBranch),
728740
name ? titleAndBodyFrom(promiseWithTimeout(this._folderRepositoryManager.getTipCommitMessage(name), 5000)) : undefined,
729-
descrptionSource === 'template' ? this.getPullRequestTemplate() : undefined
741+
descriptionSource === 'template' ? this.getPullRequestTemplate() : undefined
730742
]);
731743
const totalNonMergeCommits = totalCommits?.filter(commit => commit.parents.length < 2);
732744

@@ -748,7 +760,7 @@ export class CreatePullRequestViewProvider extends BaseCreatePullRequestViewProv
748760
}
749761
// Set title
750762
if (useBranchName && name) {
751-
title = `${name.charAt(0).toUpperCase()}${name.slice(1)}`;
763+
title = branchNameTitle(name);
752764
} else if (name && lastCommit) {
753765
title = lastCommit.title;
754766
}

0 commit comments

Comments
 (0)