Skip to content

Commit 734834a

Browse files
eloyekunlejonasfranz
authored andcommitted
Add Default Pull Request Title (#5735)
* add default PR title Set default PR title to commit summary if there's a single commit on the head branch, else set it to the head branch name * set default PR description If there's a single commit on the head branch, and it's multiline, then set it as the default PR description
1 parent c2dcb35 commit 734834a

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

routers/repo/pull.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,8 +722,9 @@ func PrepareCompareDiff(
722722
baseBranch, headBranch string) bool {
723723

724724
var (
725-
repo = ctx.Repo.Repository
726-
err error
725+
repo = ctx.Repo.Repository
726+
err error
727+
title string
727728
)
728729

729730
// Get diff information.
@@ -762,6 +763,20 @@ func PrepareCompareDiff(
762763
prInfo.Commits = models.ParseCommitsWithStatus(prInfo.Commits, headRepo)
763764
ctx.Data["Commits"] = prInfo.Commits
764765
ctx.Data["CommitCount"] = prInfo.Commits.Len()
766+
767+
if prInfo.Commits.Len() == 1 {
768+
c := prInfo.Commits.Front().Value.(models.SignCommitWithStatuses)
769+
title = strings.TrimSpace(c.UserCommit.Summary())
770+
771+
body := strings.Split(strings.TrimSpace(c.UserCommit.Message()), "\n")
772+
if len(body) > 1 {
773+
ctx.Data["content"] = strings.Join(body[1:], "\n")
774+
}
775+
} else {
776+
title = headBranch
777+
}
778+
779+
ctx.Data["title"] = title
765780
ctx.Data["Username"] = headUser.Name
766781
ctx.Data["Reponame"] = headRepo.Name
767782
ctx.Data["IsImageFile"] = headCommit.IsImageFile

0 commit comments

Comments
 (0)