Reintroduce squash merge default comment as a config setting (#16134)
* Reinstate most of commit 09304db9a5
* Move the behaviour behind a config setting
* Also fix the initial #12365
This commit is contained in:
parent
889dea8fc1
commit
35742d4af7
3 changed files with 37 additions and 5 deletions
|
@ -570,16 +570,44 @@ func GetSquashMergeCommitMessages(pr *models.PullRequest) string {
|
|||
authors := make([]string, 0, list.Len())
|
||||
stringBuilder := strings.Builder{}
|
||||
|
||||
stringBuilder.WriteString(pr.Issue.Content)
|
||||
if stringBuilder.Len() > 0 {
|
||||
stringBuilder.WriteRune('\n')
|
||||
stringBuilder.WriteRune('\n')
|
||||
if !setting.Repository.PullRequest.PopulateSquashCommentWithCommitMessages {
|
||||
stringBuilder.WriteString(pr.Issue.Content)
|
||||
if stringBuilder.Len() > 0 {
|
||||
stringBuilder.WriteRune('\n')
|
||||
stringBuilder.WriteRune('\n')
|
||||
}
|
||||
}
|
||||
|
||||
// commits list is in reverse chronological order
|
||||
element := list.Back()
|
||||
for element != nil {
|
||||
commit := element.Value.(*git.Commit)
|
||||
|
||||
if setting.Repository.PullRequest.PopulateSquashCommentWithCommitMessages {
|
||||
maxSize := setting.Repository.PullRequest.DefaultMergeMessageSize
|
||||
if maxSize < 0 || stringBuilder.Len() < maxSize {
|
||||
var toWrite []byte
|
||||
if element == list.Back() {
|
||||
toWrite = []byte(strings.TrimPrefix(commit.CommitMessage, pr.Issue.Title))
|
||||
} else {
|
||||
toWrite = []byte(commit.CommitMessage)
|
||||
}
|
||||
|
||||
if len(toWrite) > maxSize-stringBuilder.Len() && maxSize > -1 {
|
||||
toWrite = append(toWrite[:maxSize-stringBuilder.Len()], "..."...)
|
||||
}
|
||||
if _, err := stringBuilder.Write(toWrite); err != nil {
|
||||
log.Error("Unable to write commit message Error: %v", err)
|
||||
return ""
|
||||
}
|
||||
|
||||
if _, err := stringBuilder.WriteRune('\n'); err != nil {
|
||||
log.Error("Unable to write commit message Error: %v", err)
|
||||
return ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
authorString := commit.Author.String()
|
||||
if !authorsMap[authorString] && authorString != posterSig {
|
||||
authors = append(authors, authorString)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue