Skip to content

Append to existing trailers in generated squash commit message #15980

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions services/pull/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"bytes"
"context"
"fmt"
"regexp"
"strings"
"time"

Expand Down Expand Up @@ -573,7 +574,10 @@ func GetSquashMergeCommitMessages(pr *models.PullRequest) string {
stringBuilder.WriteString(pr.Issue.Content)
if stringBuilder.Len() > 0 {
stringBuilder.WriteRune('\n')
stringBuilder.WriteRune('\n')
commitMessageTrailersPattern := regexp.MustCompile(`(^|.*\n\n)([\w-]+: [^\n]+)(\n[\w-]+: [^\n]+)*$`)
if !commitMessageTrailersPattern.MatchString(pr.Issue.Content) {
stringBuilder.WriteRune('\n')
}
}

// commits list is in reverse chronological order
Expand Down Expand Up @@ -617,13 +621,6 @@ func GetSquashMergeCommitMessages(pr *models.PullRequest) string {
}
}

if len(authors) > 0 {
if _, err := stringBuilder.WriteRune('\n'); err != nil {
log.Error("Unable to write to string builder Error: %v", err)
return ""
}
}

for _, author := range authors {
if _, err := stringBuilder.Write([]byte("Co-authored-by: ")); err != nil {
log.Error("Unable to write to string builder Error: %v", err)
Expand Down