From 2b89e2ac97bfce5238ba39222b38fbabed2ba708 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Tue, 7 Jul 2026 07:08:05 +0000 Subject: [PATCH] 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 --- custom/conf/app.example.ini | 1 + modules/setting/repository.go | 1 + routers/web/repo/compare.go | 4 +++- routers/web/repo/compare_test.go | 4 ++++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index e5451af76a..2ecdad9da5 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -1191,6 +1191,7 @@ LEVEL = Info ;; Default source for the pull request title when opening a new PR. ;; "first-commit" uses the oldest commit's summary. ;; "auto" uses commit's summary if the PR only has one commit, normalizes the branch name if multiple commits. +;; "branch-name" always uses the PR's branch name. ;DEFAULT_TITLE_SOURCE = auto ;; ;; Delay mergeable check until page view or API access, for pull requests that have not been updated in the specified days when their base branches get updated. diff --git a/modules/setting/repository.go b/modules/setting/repository.go index d1000c5280..8f3fa049a3 100644 --- a/modules/setting/repository.go +++ b/modules/setting/repository.go @@ -22,6 +22,7 @@ const ( const ( RepoPRTitleSourceFirstCommit = "first-commit" RepoPRTitleSourceAuto = "auto" + RepoPRTitleSourceBranchName = "branch-name" ) // ItemsPerPage maximum items per page in forks, watchers and stars of a repo diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index adb51ab69c..dd00be2da2 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -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() diff --git a/routers/web/repo/compare_test.go b/routers/web/repo/compare_test.go index af0a735227..d5b7609fa3 100644 --- a/routers/web/repo/compare_test.go +++ b/routers/web/repo/compare_test.go @@ -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)