|
9 | 9 | "bytes"
|
10 | 10 | "context"
|
11 | 11 | "fmt"
|
| 12 | + "regexp" |
12 | 13 | "strings"
|
13 | 14 | "time"
|
14 | 15 |
|
@@ -528,6 +529,8 @@ func CloseRepoBranchesPulls(doer *models.User, repo *models.Repository) error {
|
528 | 529 | return nil
|
529 | 530 | }
|
530 | 531 |
|
| 532 | +var commitMessageTrailersPattern = regexp.MustCompile(`(?:^|\n\n)(?:[\w-]+[ \t]*:[^\n]+\n*(?:[ \t]+[^\n]+\n*)*)+$`) |
| 533 | + |
531 | 534 | // GetSquashMergeCommitMessages returns the commit messages between head and merge base (if there is one)
|
532 | 535 | func GetSquashMergeCommitMessages(pr *models.PullRequest) string {
|
533 | 536 | if err := pr.LoadIssue(); err != nil {
|
@@ -583,10 +586,13 @@ func GetSquashMergeCommitMessages(pr *models.PullRequest) string {
|
583 | 586 | stringBuilder := strings.Builder{}
|
584 | 587 |
|
585 | 588 | if !setting.Repository.PullRequest.PopulateSquashCommentWithCommitMessages {
|
586 |
| - stringBuilder.WriteString(pr.Issue.Content) |
| 589 | + message := strings.TrimSpace(pr.Issue.Content) |
| 590 | + stringBuilder.WriteString(message) |
587 | 591 | if stringBuilder.Len() > 0 {
|
588 | 592 | stringBuilder.WriteRune('\n')
|
589 |
| - stringBuilder.WriteRune('\n') |
| 593 | + if !commitMessageTrailersPattern.MatchString(message) { |
| 594 | + stringBuilder.WriteRune('\n') |
| 595 | + } |
590 | 596 | }
|
591 | 597 | }
|
592 | 598 |
|
@@ -657,13 +663,6 @@ func GetSquashMergeCommitMessages(pr *models.PullRequest) string {
|
657 | 663 | }
|
658 | 664 | }
|
659 | 665 |
|
660 |
| - if len(authors) > 0 { |
661 |
| - if _, err := stringBuilder.WriteRune('\n'); err != nil { |
662 |
| - log.Error("Unable to write to string builder Error: %v", err) |
663 |
| - return "" |
664 |
| - } |
665 |
| - } |
666 |
| - |
667 | 666 | for _, author := range authors {
|
668 | 667 | if _, err := stringBuilder.Write([]byte("Co-authored-by: ")); err != nil {
|
669 | 668 | log.Error("Unable to write to string builder Error: %v", err)
|
|
0 commit comments