Skip to content

Commit 45b1b78

Browse files
committed
Simplify regex and deal with trailing \n in PR description
1 parent 94333e2 commit 45b1b78

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

services/pull/pull.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ func CloseRepoBranchesPulls(doer *models.User, repo *models.Repository) error {
517517
return nil
518518
}
519519

520-
var commitMessageTrailersPattern = regexp.MustCompile(`(^|.*\n\n)([\w-]+: [^\n]+)(\n[\w-]+: [^\n]+)*$`)
520+
var commitMessageTrailersPattern = regexp.MustCompile(`(?:^|\n\n)(?:[\w-]+: [^\n]+\n*)+$`)
521521

522522
// GetSquashMergeCommitMessages returns the commit messages between head and merge base (if there is one)
523523
func GetSquashMergeCommitMessages(pr *models.PullRequest) string {
@@ -574,12 +574,13 @@ func GetSquashMergeCommitMessages(pr *models.PullRequest) string {
574574
stringBuilder := strings.Builder{}
575575

576576
if !setting.Repository.PullRequest.PopulateSquashCommentWithCommitMessages {
577-
stringBuilder.WriteString(pr.Issue.Content)
577+
message := strings.TrimSpace(pr.Issue.Content)
578+
stringBuilder.WriteString(message)
578579
if stringBuilder.Len() > 0 {
579580
stringBuilder.WriteRune('\n')
580-
if !commitMessageTrailersPattern.MatchString(pr.Issue.Content) {
581-
stringBuilder.WriteRune('\n')
582-
}
581+
if !commitMessageTrailersPattern.MatchString(message) {
582+
stringBuilder.WriteRune('\n')
583+
}
583584
}
584585
}
585586

0 commit comments

Comments
 (0)