fix(pulls): add branch-name option for DEFAULT_TITLE_SOURCE (#38356)

Adds a new `branch-name` value for the `[repository.pull-request]`
`DEFAULT_TITLE_SOURCE` setting that always uses the normalized branch
name as the PR title, regardless of commit count.

Fix #38317

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Copilot
2026-07-07 07:08:05 +00:00
committed by GitHub
parent 26bff7f47e
commit 2b89e2ac97
4 changed files with 9 additions and 1 deletions
+3 -1
View File
@@ -383,7 +383,9 @@ func autoTitleFromBranchName(name string) string {
func prepareNewPullRequestTitleContent(ci *git_service.CompareInfo, commits []*git_model.SignCommitWithStatuses, defaultTitleSource string) (title, content string) {
useFirstCommitAsTitle := len(commits) == 1 || (defaultTitleSource == setting.RepoPRTitleSourceFirstCommit && len(commits) > 0)
if useFirstCommitAsTitle {
if defaultTitleSource == setting.RepoPRTitleSourceBranchName {
title = ci.HeadRef.ShortName()
} else if useFirstCommitAsTitle {
// the "commits" are from "ShowPrettyFormatLogToList", which is ordered from newest to oldest, here take the oldest one
c := commits[len(commits)-1]
title = c.UserCommit.GitCommit.MessageTitle()
+4
View File
@@ -70,6 +70,10 @@ func TestNewPullRequestTitleContent(t *testing.T) {
assert.Equal(t, "Head branch", title)
assert.Empty(t, content)
title, content = prepareNewPullRequestTitleContent(ci, nil, setting.RepoPRTitleSourceBranchName)
assert.Equal(t, "head-branch", title)
assert.Empty(t, content)
// single commit
title, content = prepareNewPullRequestTitleContent(ci, []*git_model.SignCommitWithStatuses{mockCommit("single-commit-title\nbody")}, setting.RepoPRTitleSourceAuto)
assert.Equal(t, "single-commit-title", title)