Skip to content

Commit 927bffa

Browse files
committed
Move the behavior behind a config setting
1 parent bf01131 commit 927bffa

File tree

3 files changed

+30
-17
lines changed

3 files changed

+30
-17
lines changed

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,11 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
9494
- `REOPEN_KEYWORDS`: **reopen**, **reopens**, **reopened**: List of keywords used in Pull Request comments to automatically reopen
9595
a related issue
9696
- `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
97-
- `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.
97+
- `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`.
9898
- `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
9999
- `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.
100100
- `DEFAULT_MERGE_MESSAGE_OFFICIAL_APPROVERS_ONLY`: **true**: In default merge messages only include approvers who are officially allowed to review.
101+
- `POPULATE_SQUASH_COMMENT_WITH_COMMIT_MESSAGES`: **false**: In default squash-merge messages include the commit message of all commits comprising the pull request.
101102

102103
### Repository - Issue (`repository.issue`)
103104

@@ -350,7 +351,7 @@ relation to port exhaustion.
350351
- `ISSUE_INDEXER_PATH`: **indexers/issues.bleve**: Index file used for issue search; available when ISSUE_INDEXER_TYPE is bleve and elasticsearch.
351352
- The next 4 configuration values are deprecated and should be set in `queue.issue_indexer` however are kept for backwards compatibility:
352353
- `ISSUE_INDEXER_QUEUE_TYPE`: **levelqueue**: Issue indexer queue, currently supports:`channel`, `levelqueue`, `redis`.
353-
- `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`.)
354+
- `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`.)
354355
- `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`.
355356
- `ISSUE_INDEXER_QUEUE_BATCH_NUMBER`: **20**: Batch queue number.
356357

@@ -370,7 +371,7 @@ relation to port exhaustion.
370371
## Queue (`queue` and `queue.*`)
371372

372373
- `TYPE`: **persistable-channel**: General queue type, currently support: `persistable-channel` (uses a LevelDB internally), `channel`, `level`, `redis`, `dummy`
373-
- `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`**.)
374+
- `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`**.)
374375
- `LENGTH`: **20**: Maximal queue size before channel queues block
375376
- `BATCH_LENGTH`: **20**: Batch data before passing to the handler
376377
- `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`

modules/setting/repository.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ var (
7878
DefaultMergeMessageAllAuthors bool
7979
DefaultMergeMessageMaxApprovers int
8080
DefaultMergeMessageOfficialApproversOnly bool
81+
PopulateSquashCommentWithCommitMessages bool
8182
} `ini:"repository.pull-request"`
8283

8384
// Issue Setting
@@ -199,6 +200,7 @@ var (
199200
DefaultMergeMessageAllAuthors bool
200201
DefaultMergeMessageMaxApprovers int
201202
DefaultMergeMessageOfficialApproversOnly bool
203+
PopulateSquashCommentWithCommitMessages bool
202204
}{
203205
WorkInProgressPrefixes: []string{"WIP:", "[WIP]"},
204206
// Same as GitHub. See
@@ -210,6 +212,7 @@ var (
210212
DefaultMergeMessageAllAuthors: false,
211213
DefaultMergeMessageMaxApprovers: 10,
212214
DefaultMergeMessageOfficialApproversOnly: true,
215+
PopulateSquashCommentWithCommitMessages: false,
213216
},
214217

215218
// Issue settings

services/pull/pull.go

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -564,32 +564,41 @@ func GetSquashMergeCommitMessages(pr *models.PullRequest) string {
564564
return ""
565565
}
566566

567-
maxSize := setting.Repository.PullRequest.DefaultMergeMessageSize
568-
569567
posterSig := pr.Issue.Poster.NewGitSig().String()
570568

571569
authorsMap := map[string]bool{}
572570
authors := make([]string, 0, list.Len())
573571
stringBuilder := strings.Builder{}
574572

573+
if !setting.Repository.PullRequest.PopulateSquashCommentWithCommitMessages {
574+
stringBuilder.WriteString(pr.Issue.Content)
575+
if stringBuilder.Len() > 0 {
576+
stringBuilder.WriteRune('\n')
577+
stringBuilder.WriteRune('\n')
578+
}
579+
}
580+
575581
// commits list is in reverse chronological order
576582
element := list.Back()
577583
for element != nil {
578584
commit := element.Value.(*git.Commit)
579585

580-
if maxSize < 0 || stringBuilder.Len() < maxSize {
581-
toWrite := []byte(commit.CommitMessage)
582-
if len(toWrite) > maxSize-stringBuilder.Len() && maxSize > -1 {
583-
toWrite = append(toWrite[:maxSize-stringBuilder.Len()], "..."...)
584-
}
585-
if _, err := stringBuilder.Write(toWrite); err != nil {
586-
log.Error("Unable to write commit message Error: %v", err)
587-
return ""
588-
}
586+
if setting.Repository.PullRequest.PopulateSquashCommentWithCommitMessages {
587+
maxSize := setting.Repository.PullRequest.DefaultMergeMessageSize
588+
if maxSize < 0 || stringBuilder.Len() < maxSize {
589+
toWrite := []byte(commit.CommitMessage)
590+
if len(toWrite) > maxSize-stringBuilder.Len() && maxSize > -1 {
591+
toWrite = append(toWrite[:maxSize-stringBuilder.Len()], "..."...)
592+
}
593+
if _, err := stringBuilder.Write(toWrite); err != nil {
594+
log.Error("Unable to write commit message Error: %v", err)
595+
return ""
596+
}
589597

590-
if _, err := stringBuilder.WriteRune('\n'); err != nil {
591-
log.Error("Unable to write commit message Error: %v", err)
592-
return ""
598+
if _, err := stringBuilder.WriteRune('\n'); err != nil {
599+
log.Error("Unable to write commit message Error: %v", err)
600+
return ""
601+
}
593602
}
594603
}
595604

0 commit comments

Comments
 (0)