mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-24 03:21:49 +01:00
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
|
@ -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
|
- `REOPEN_KEYWORDS`: **reopen**, **reopens**, **reopened**: List of keywords used in Pull Request comments to automatically reopen
|
||||||
a related issue
|
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_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_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_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.
|
- `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`)
|
### Repository - Issue (`repository.issue`)
|
||||||
|
|
||||||
|
|
|
@ -78,6 +78,7 @@ var (
|
||||||
DefaultMergeMessageAllAuthors bool
|
DefaultMergeMessageAllAuthors bool
|
||||||
DefaultMergeMessageMaxApprovers int
|
DefaultMergeMessageMaxApprovers int
|
||||||
DefaultMergeMessageOfficialApproversOnly bool
|
DefaultMergeMessageOfficialApproversOnly bool
|
||||||
|
PopulateSquashCommentWithCommitMessages bool
|
||||||
} `ini:"repository.pull-request"`
|
} `ini:"repository.pull-request"`
|
||||||
|
|
||||||
// Issue Setting
|
// Issue Setting
|
||||||
|
@ -199,6 +200,7 @@ var (
|
||||||
DefaultMergeMessageAllAuthors bool
|
DefaultMergeMessageAllAuthors bool
|
||||||
DefaultMergeMessageMaxApprovers int
|
DefaultMergeMessageMaxApprovers int
|
||||||
DefaultMergeMessageOfficialApproversOnly bool
|
DefaultMergeMessageOfficialApproversOnly bool
|
||||||
|
PopulateSquashCommentWithCommitMessages bool
|
||||||
}{
|
}{
|
||||||
WorkInProgressPrefixes: []string{"WIP:", "[WIP]"},
|
WorkInProgressPrefixes: []string{"WIP:", "[WIP]"},
|
||||||
// Same as GitHub. See
|
// Same as GitHub. See
|
||||||
|
@ -210,6 +212,7 @@ var (
|
||||||
DefaultMergeMessageAllAuthors: false,
|
DefaultMergeMessageAllAuthors: false,
|
||||||
DefaultMergeMessageMaxApprovers: 10,
|
DefaultMergeMessageMaxApprovers: 10,
|
||||||
DefaultMergeMessageOfficialApproversOnly: true,
|
DefaultMergeMessageOfficialApproversOnly: true,
|
||||||
|
PopulateSquashCommentWithCommitMessages: false,
|
||||||
},
|
},
|
||||||
|
|
||||||
// Issue settings
|
// Issue settings
|
||||||
|
|
|
@ -570,16 +570,44 @@ func GetSquashMergeCommitMessages(pr *models.PullRequest) string {
|
||||||
authors := make([]string, 0, list.Len())
|
authors := make([]string, 0, list.Len())
|
||||||
stringBuilder := strings.Builder{}
|
stringBuilder := strings.Builder{}
|
||||||
|
|
||||||
stringBuilder.WriteString(pr.Issue.Content)
|
if !setting.Repository.PullRequest.PopulateSquashCommentWithCommitMessages {
|
||||||
if stringBuilder.Len() > 0 {
|
stringBuilder.WriteString(pr.Issue.Content)
|
||||||
stringBuilder.WriteRune('\n')
|
if stringBuilder.Len() > 0 {
|
||||||
stringBuilder.WriteRune('\n')
|
stringBuilder.WriteRune('\n')
|
||||||
|
stringBuilder.WriteRune('\n')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// commits list is in reverse chronological order
|
// commits list is in reverse chronological order
|
||||||
element := list.Back()
|
element := list.Back()
|
||||||
for element != nil {
|
for element != nil {
|
||||||
commit := element.Value.(*git.Commit)
|
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()
|
authorString := commit.Author.String()
|
||||||
if !authorsMap[authorString] && authorString != posterSig {
|
if !authorsMap[authorString] && authorString != posterSig {
|
||||||
authors = append(authors, authorString)
|
authors = append(authors, authorString)
|
||||||
|
|
Loading…
Reference in a new issue