Skip to content

Commit 09304db

Browse files
authored
Use the text of pull-request as the squash commit's message (#13071)
Originally, it was filled by the commit messages of the involved commits. In this change, we use the headline comment of the pull request as the commit message when it is a squash merge. Thanks to @zeripath for suggesting the idea. Fixes #12365 Co-authored-by: Mura Li <[email protected]>
1 parent 34df4e5 commit 09304db

File tree

2 files changed

+10
-22
lines changed

2 files changed

+10
-22
lines changed

routers/repo/pull.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare
440440
ctx.ServerError("IsUserAllowedToUpdate", err)
441441
return nil
442442
}
443-
ctx.Data["GetCommitMessages"] = pull_service.GetCommitMessages(pull)
443+
ctx.Data["GetCommitMessages"] = pull_service.GetSquashMergeCommitMessages(pull)
444444
}
445445

446446
sha, err := baseGitRepo.GetRefCommitID(pull.GetGitRefName())

services/pull/pull.go

+9-21
Original file line numberDiff line numberDiff line change
@@ -502,8 +502,8 @@ func CloseRepoBranchesPulls(doer *models.User, repo *models.Repository) error {
502502
return nil
503503
}
504504

505-
// GetCommitMessages returns the commit messages between head and merge base (if there is one)
506-
func GetCommitMessages(pr *models.PullRequest) string {
505+
// GetSquashMergeCommitMessages returns the commit messages between head and merge base (if there is one)
506+
func GetSquashMergeCommitMessages(pr *models.PullRequest) string {
507507
if err := pr.LoadIssue(); err != nil {
508508
log.Error("Cannot load issue %d for PR id %d: Error: %v", pr.IssueID, pr.ID, err)
509509
return ""
@@ -550,34 +550,22 @@ func GetCommitMessages(pr *models.PullRequest) string {
550550
return ""
551551
}
552552

553-
maxSize := setting.Repository.PullRequest.DefaultMergeMessageSize
554-
555553
posterSig := pr.Issue.Poster.NewGitSig().String()
556554

557555
authorsMap := map[string]bool{}
558556
authors := make([]string, 0, list.Len())
559557
stringBuilder := strings.Builder{}
558+
559+
stringBuilder.WriteString(pr.Issue.Content)
560+
if stringBuilder.Len() > 0 {
561+
stringBuilder.WriteRune('\n')
562+
stringBuilder.WriteRune('\n')
563+
}
564+
560565
// commits list is in reverse chronological order
561566
element := list.Back()
562567
for element != nil {
563568
commit := element.Value.(*git.Commit)
564-
565-
if maxSize < 0 || stringBuilder.Len() < maxSize {
566-
toWrite := []byte(commit.CommitMessage)
567-
if len(toWrite) > maxSize-stringBuilder.Len() && maxSize > -1 {
568-
toWrite = append(toWrite[:maxSize-stringBuilder.Len()], "..."...)
569-
}
570-
if _, err := stringBuilder.Write(toWrite); err != nil {
571-
log.Error("Unable to write commit message Error: %v", err)
572-
return ""
573-
}
574-
575-
if _, err := stringBuilder.WriteRune('\n'); err != nil {
576-
log.Error("Unable to write commit message Error: %v", err)
577-
return ""
578-
}
579-
}
580-
581569
authorString := commit.Author.String()
582570
if !authorsMap[authorString] && authorString != posterSig {
583571
authors = append(authors, authorString)

0 commit comments

Comments
 (0)