Skip to content

Commit abdf8b9

Browse files
committed
Use the text of pull-request as the squash commit's message
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 go-gitea#12365
1 parent c85bb62 commit abdf8b9

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
@@ -426,7 +426,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare
426426
ctx.ServerError("IsUserAllowedToUpdate", err)
427427
return nil
428428
}
429-
ctx.Data["GetCommitMessages"] = pull_service.GetCommitMessages(pull)
429+
ctx.Data["GetCommitMessages"] = pull_service.GetSquashMergeCommitMessages(pull)
430430
}
431431

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

services/pull/pull.go

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

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

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

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

0 commit comments

Comments
 (0)