mirror of https://github.com/go-gitea/gitea.git
Use the text of pull-request as the squash commit's message (#13071)
Originally, it was filled by the commit messages of the involved commits. In this change, we use the headline comment of the pull request as the commit message when it is a squash merge. Thanks to @zeripath for suggesting the idea. Fixes #12365 Co-authored-by: Mura Li <typeless@users.noreply.github.com>
This commit is contained in:
parent
34df4e5df5
commit
09304db9a5
|
@ -440,7 +440,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare
|
||||||
ctx.ServerError("IsUserAllowedToUpdate", err)
|
ctx.ServerError("IsUserAllowedToUpdate", err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
ctx.Data["GetCommitMessages"] = pull_service.GetCommitMessages(pull)
|
ctx.Data["GetCommitMessages"] = pull_service.GetSquashMergeCommitMessages(pull)
|
||||||
}
|
}
|
||||||
|
|
||||||
sha, err := baseGitRepo.GetRefCommitID(pull.GetGitRefName())
|
sha, err := baseGitRepo.GetRefCommitID(pull.GetGitRefName())
|
||||||
|
|
|
@ -502,8 +502,8 @@ func CloseRepoBranchesPulls(doer *models.User, repo *models.Repository) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCommitMessages returns the commit messages between head and merge base (if there is one)
|
// GetSquashMergeCommitMessages returns the commit messages between head and merge base (if there is one)
|
||||||
func GetCommitMessages(pr *models.PullRequest) string {
|
func GetSquashMergeCommitMessages(pr *models.PullRequest) string {
|
||||||
if err := pr.LoadIssue(); err != nil {
|
if err := pr.LoadIssue(); err != nil {
|
||||||
log.Error("Cannot load issue %d for PR id %d: Error: %v", pr.IssueID, pr.ID, err)
|
log.Error("Cannot load issue %d for PR id %d: Error: %v", pr.IssueID, pr.ID, err)
|
||||||
return ""
|
return ""
|
||||||
|
@ -550,34 +550,22 @@ func GetCommitMessages(pr *models.PullRequest) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
maxSize := setting.Repository.PullRequest.DefaultMergeMessageSize
|
|
||||||
|
|
||||||
posterSig := pr.Issue.Poster.NewGitSig().String()
|
posterSig := pr.Issue.Poster.NewGitSig().String()
|
||||||
|
|
||||||
authorsMap := map[string]bool{}
|
authorsMap := map[string]bool{}
|
||||||
authors := make([]string, 0, list.Len())
|
authors := make([]string, 0, list.Len())
|
||||||
stringBuilder := strings.Builder{}
|
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
|
// 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 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()
|
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 New Issue