aboutsummaryrefslogtreecommitdiffstats
path: root/services/pull/pull.go
diff options
context:
space:
mode:
authorparnic <github@parnic.com>2021-06-18 17:08:22 -0500
committerGitHub <noreply@github.com>2021-06-19 00:08:22 +0200
commit35742d4af72da3cf6262fbacc688d53db88b68a6 (patch)
tree5b01b61666e6a3e31dc58f5e3efaeecf04f6eccc /services/pull/pull.go
parent889dea8fc1e78b0d915b27f122df116e7296336d (diff)
downloadgitea-35742d4af72da3cf6262fbacc688d53db88b68a6.tar.gz
gitea-35742d4af72da3cf6262fbacc688d53db88b68a6.zip
Reintroduce squash merge default comment as a config setting (#16134)
* Reinstate most of commit 09304db9a5d88c035a96f74a4544572bc8c5dac0 * Move the behaviour behind a config setting * Also fix the initial #12365
Diffstat (limited to 'services/pull/pull.go')
-rw-r--r--services/pull/pull.go36
1 files changed, 32 insertions, 4 deletions
diff --git a/services/pull/pull.go b/services/pull/pull.go
index cc560fb199..02c0a7fe7c 100644
--- a/services/pull/pull.go
+++ b/services/pull/pull.go
@@ -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)