|
9 | 9 | "bytes"
|
10 | 10 | "context"
|
11 | 11 | "fmt"
|
| 12 | + "regexp" |
12 | 13 | "strings"
|
13 | 14 | "time"
|
14 | 15 |
|
@@ -516,6 +517,8 @@ func CloseRepoBranchesPulls(doer *models.User, repo *models.Repository) error {
|
516 | 517 | return nil
|
517 | 518 | }
|
518 | 519 |
|
| 520 | +var commitMessageTrailersPattern = regexp.MustCompile(`(?:^|\n\n)(?:[\w-]+[ \t]*:[^\n]+\n*(?:[ \t]+[^\n]+\n*)*)+$`) |
| 521 | + |
519 | 522 | // GetSquashMergeCommitMessages returns the commit messages between head and merge base (if there is one)
|
520 | 523 | func GetSquashMergeCommitMessages(pr *models.PullRequest) string {
|
521 | 524 | if err := pr.LoadIssue(); err != nil {
|
@@ -571,10 +574,13 @@ func GetSquashMergeCommitMessages(pr *models.PullRequest) string {
|
571 | 574 | stringBuilder := strings.Builder{}
|
572 | 575 |
|
573 | 576 | if !setting.Repository.PullRequest.PopulateSquashCommentWithCommitMessages {
|
574 |
| - stringBuilder.WriteString(pr.Issue.Content) |
| 577 | + message := strings.TrimSpace(pr.Issue.Content) |
| 578 | + stringBuilder.WriteString(message) |
575 | 579 | if stringBuilder.Len() > 0 {
|
576 | 580 | stringBuilder.WriteRune('\n')
|
577 |
| - stringBuilder.WriteRune('\n') |
| 581 | + if !commitMessageTrailersPattern.MatchString(message) { |
| 582 | + stringBuilder.WriteRune('\n') |
| 583 | + } |
578 | 584 | }
|
579 | 585 | }
|
580 | 586 |
|
@@ -645,13 +651,6 @@ func GetSquashMergeCommitMessages(pr *models.PullRequest) string {
|
645 | 651 | }
|
646 | 652 | }
|
647 | 653 |
|
648 |
| - if len(authors) > 0 { |
649 |
| - if _, err := stringBuilder.WriteRune('\n'); err != nil { |
650 |
| - log.Error("Unable to write to string builder Error: %v", err) |
651 |
| - return "" |
652 |
| - } |
653 |
| - } |
654 |
| - |
655 | 654 | for _, author := range authors {
|
656 | 655 | if _, err := stringBuilder.Write([]byte("Co-authored-by: ")); err != nil {
|
657 | 656 | log.Error("Unable to write to string builder Error: %v", err)
|
|
0 commit comments