From bf01131c559749486d0db4794fa54d8b28af4a49 Mon Sep 17 00:00:00 2001 From: parnic Date: Tue, 18 May 2021 13:58:57 -0500 Subject: [PATCH 1/3] Reinstate most of commit 09304db9a5d88c035a96f74a4544572bc8c5dac0 --- services/pull/pull.go | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/services/pull/pull.go b/services/pull/pull.go index cc560fb199d2a..5352ebe2a3cb9 100644 --- a/services/pull/pull.go +++ b/services/pull/pull.go @@ -564,22 +564,35 @@ func GetSquashMergeCommitMessages(pr *models.PullRequest) string { return "" } + maxSize := setting.Repository.PullRequest.DefaultMergeMessageSize + posterSig := pr.Issue.Poster.NewGitSig().String() authorsMap := map[string]bool{} authors := make([]string, 0, list.Len()) stringBuilder := strings.Builder{} - 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 maxSize < 0 || stringBuilder.Len() < maxSize { + 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) From 927bffa0a531d629e219cf0b0797ba2f46645856 Mon Sep 17 00:00:00 2001 From: Parnic Date: Thu, 10 Jun 2021 14:48:13 -0500 Subject: [PATCH 2/3] Move the behavior behind a config setting --- .../doc/advanced/config-cheat-sheet.en-us.md | 7 ++-- modules/setting/repository.go | 3 ++ services/pull/pull.go | 37 ++++++++++++------- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index 28ab922c439eb..05ef68623c54a 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -94,10 +94,11 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`. - `REOPEN_KEYWORDS`: **reopen**, **reopens**, **reopened**: List of keywords used in Pull Request comments to automatically reopen a related issue - `DEFAULT_MERGE_MESSAGE_COMMITS_LIMIT`: **50**: In the default merge message for squash commits include at most this many commits. Set to `-1` to include all commits -- `DEFAULT_MERGE_MESSAGE_SIZE`: **5120**: In the default merge message for squash commits limit the size of the commit messages. Set to `-1` to have no limit. +- `DEFAULT_MERGE_MESSAGE_SIZE`: **5120**: In the default merge message for squash commits limit the size of the commit messages. Set to `-1` to have no limit. Only used if `POPULATE_SQUASH_COMMENT_WITH_COMMIT_MESSAGES` is `true`. - `DEFAULT_MERGE_MESSAGE_ALL_AUTHORS`: **false**: In the default merge message for squash commits walk all commits to include all authors in the Co-authored-by otherwise just use those in the limited list - `DEFAULT_MERGE_MESSAGE_MAX_APPROVERS`: **10**: In default merge messages limit the number of approvers listed as `Reviewed-by:`. Set to `-1` to include all. - `DEFAULT_MERGE_MESSAGE_OFFICIAL_APPROVERS_ONLY`: **true**: In default merge messages only include approvers who are officially allowed to review. +- `POPULATE_SQUASH_COMMENT_WITH_COMMIT_MESSAGES`: **false**: In default squash-merge messages include the commit message of all commits comprising the pull request. ### Repository - Issue (`repository.issue`) @@ -350,7 +351,7 @@ relation to port exhaustion. - `ISSUE_INDEXER_PATH`: **indexers/issues.bleve**: Index file used for issue search; available when ISSUE_INDEXER_TYPE is bleve and elasticsearch. - The next 4 configuration values are deprecated and should be set in `queue.issue_indexer` however are kept for backwards compatibility: - `ISSUE_INDEXER_QUEUE_TYPE`: **levelqueue**: Issue indexer queue, currently supports:`channel`, `levelqueue`, `redis`. -- `ISSUE_INDEXER_QUEUE_DIR`: **queues/common**: When `ISSUE_INDEXER_QUEUE_TYPE` is `levelqueue`, this will be the path where the queue will be saved. (Previously this was `indexers/issues.queue`.) +- `ISSUE_INDEXER_QUEUE_DIR`: **queues/common**: When `ISSUE_INDEXER_QUEUE_TYPE` is `levelqueue`, this will be the path where the queue will be saved. (Previously this was `indexers/issues.queue`.) - `ISSUE_INDEXER_QUEUE_CONN_STR`: **addrs=127.0.0.1:6379 db=0**: When `ISSUE_INDEXER_QUEUE_TYPE` is `redis`, this will store the redis connection string. When `ISSUE_INDEXER_QUEUE_TYPE` is `levelqueue`, this is a directory or additional options of the form `leveldb://path/to/db?option=value&....`, and overrides `ISSUE_INDEXER_QUEUE_DIR`. - `ISSUE_INDEXER_QUEUE_BATCH_NUMBER`: **20**: Batch queue number. @@ -370,7 +371,7 @@ relation to port exhaustion. ## Queue (`queue` and `queue.*`) - `TYPE`: **persistable-channel**: General queue type, currently support: `persistable-channel` (uses a LevelDB internally), `channel`, `level`, `redis`, `dummy` -- `DATADIR`: **queues/**: Base DataDir for storing persistent and level queues. `DATADIR` for individual queues can be set in `queue.name` sections but will default to `DATADIR/`**`common`**. (Previously each queue would default to `DATADIR/`**`name`**.) +- `DATADIR`: **queues/**: Base DataDir for storing persistent and level queues. `DATADIR` for individual queues can be set in `queue.name` sections but will default to `DATADIR/`**`common`**. (Previously each queue would default to `DATADIR/`**`name`**.) - `LENGTH`: **20**: Maximal queue size before channel queues block - `BATCH_LENGTH`: **20**: Batch data before passing to the handler - `CONN_STR`: **redis://127.0.0.1:6379/0**: Connection string for the redis queue type. Options can be set using query params. Similarly LevelDB options can also be set using: **leveldb://relative/path?option=value** or **leveldb:///absolute/path?option=value**, and will override `DATADIR` diff --git a/modules/setting/repository.go b/modules/setting/repository.go index a6fc73651a305..a7666895e1f36 100644 --- a/modules/setting/repository.go +++ b/modules/setting/repository.go @@ -78,6 +78,7 @@ var ( DefaultMergeMessageAllAuthors bool DefaultMergeMessageMaxApprovers int DefaultMergeMessageOfficialApproversOnly bool + PopulateSquashCommentWithCommitMessages bool } `ini:"repository.pull-request"` // Issue Setting @@ -199,6 +200,7 @@ var ( DefaultMergeMessageAllAuthors bool DefaultMergeMessageMaxApprovers int DefaultMergeMessageOfficialApproversOnly bool + PopulateSquashCommentWithCommitMessages bool }{ WorkInProgressPrefixes: []string{"WIP:", "[WIP]"}, // Same as GitHub. See @@ -210,6 +212,7 @@ var ( DefaultMergeMessageAllAuthors: false, DefaultMergeMessageMaxApprovers: 10, DefaultMergeMessageOfficialApproversOnly: true, + PopulateSquashCommentWithCommitMessages: false, }, // Issue settings diff --git a/services/pull/pull.go b/services/pull/pull.go index 5352ebe2a3cb9..9887d6d1747d8 100644 --- a/services/pull/pull.go +++ b/services/pull/pull.go @@ -564,32 +564,41 @@ func GetSquashMergeCommitMessages(pr *models.PullRequest) string { return "" } - maxSize := setting.Repository.PullRequest.DefaultMergeMessageSize - posterSig := pr.Issue.Poster.NewGitSig().String() authorsMap := map[string]bool{} authors := make([]string, 0, list.Len()) stringBuilder := strings.Builder{} + 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 maxSize < 0 || stringBuilder.Len() < maxSize { - 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 setting.Repository.PullRequest.PopulateSquashCommentWithCommitMessages { + maxSize := setting.Repository.PullRequest.DefaultMergeMessageSize + if maxSize < 0 || stringBuilder.Len() < maxSize { + 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 "" + if _, err := stringBuilder.WriteRune('\n'); err != nil { + log.Error("Unable to write commit message Error: %v", err) + return "" + } } } From ac435d69f727b891829417d6670e04b9c82e33ad Mon Sep 17 00:00:00 2001 From: Parnic Date: Thu, 10 Jun 2021 15:20:42 -0500 Subject: [PATCH 3/3] Also fix the initial #12365 while we're at it --- services/pull/pull.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/services/pull/pull.go b/services/pull/pull.go index 9887d6d1747d8..02c0a7fe7c878 100644 --- a/services/pull/pull.go +++ b/services/pull/pull.go @@ -586,7 +586,13 @@ func GetSquashMergeCommitMessages(pr *models.PullRequest) string { if setting.Repository.PullRequest.PopulateSquashCommentWithCommitMessages { maxSize := setting.Repository.PullRequest.DefaultMergeMessageSize if maxSize < 0 || stringBuilder.Len() < maxSize { - toWrite := []byte(commit.CommitMessage) + 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()], "..."...) }