Skip to content

Squash merge messages contain information about all commits by default. #35247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 44 additions & 8 deletions routers/web/repo/issue_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,10 @@ func ViewIssue(ctx *context.Context) {
preparePullViewReviewAndMerge,
}

if issue.IsPull {
prepareFuncs = append(prepareFuncs, prepareIssueViewSquashMergeMsg)
}

for _, prepareFunc := range prepareFuncs {
prepareFunc(ctx, issue)
if ctx.Written() {
Expand Down Expand Up @@ -442,6 +446,7 @@ func ViewPullMergeBox(ctx *context.Context) {
}
preparePullViewPullInfo(ctx, issue)
preparePullViewReviewAndMerge(ctx, issue)
prepareIssueViewSquashMergeMsg(ctx, issue)
ctx.Data["PullMergeBoxReloading"] = issue.PullRequest.IsChecking()

// TODO: it should use a dedicated struct to render the pull merge box, to make sure all data is prepared correctly
Expand Down Expand Up @@ -928,14 +933,6 @@ func preparePullViewReviewAndMerge(ctx *context.Context, issue *issues_model.Iss
ctx.Data["DefaultMergeMessage"] = defaultMergeMessage
ctx.Data["DefaultMergeBody"] = defaultMergeBody

defaultSquashMergeMessage, defaultSquashMergeBody, err := pull_service.GetDefaultMergeMessage(ctx, ctx.Repo.GitRepo, pull, repo_model.MergeStyleSquash)
if err != nil {
ctx.ServerError("GetDefaultSquashMergeMessage", err)
return
}
ctx.Data["DefaultSquashMergeMessage"] = defaultSquashMergeMessage
ctx.Data["DefaultSquashMergeBody"] = defaultSquashMergeBody

pb, err := git_model.GetFirstMatchProtectedBranchRule(ctx, pull.BaseRepoID, pull.BaseBranch)
if err != nil {
ctx.ServerError("LoadProtectedBranch", err)
Expand Down Expand Up @@ -1006,3 +1003,42 @@ func prepareIssueViewContent(ctx *context.Context, issue *issues_model.Issue) {
return
}
}

func getIssueViewSquashMergeCommits(ctx *context.Context, issue *issues_model.Issue) (string, error) {
pull := issue.PullRequest
pull.Issue = issue

baseCommit := GetMergedBaseCommitID(ctx, issue)

compareInfo, err := ctx.Repo.GitRepo.GetCompareInfo(ctx.Repo.Repository.RepoPath(),
baseCommit, pull.GetGitHeadRefName(), false, false)
if err != nil {
return "", err
}

commits := ""
for _, c := range compareInfo.Commits {
commits += fmt.Sprintf("* %s\n", c.CommitMessage)
}

return commits, nil
}

func prepareIssueViewSquashMergeMsg(ctx *context.Context, issue *issues_model.Issue) {
pull := issue.PullRequest

defaultSquashMergeMessage, defaultSquashMergeBody, err := pull_service.GetDefaultMergeMessage(ctx, ctx.Repo.GitRepo, pull, repo_model.MergeStyleSquash)
if err != nil {
ctx.ServerError("GetDefaultSquashMergeMessage", err)
return
}

commitsMsg, err := getIssueViewSquashMergeCommits(ctx, issue)
if err != nil {
ctx.ServerError("getIssueViewSquashMergeCommits", err)
return
}

ctx.Data["DefaultSquashMergeMessage"] = defaultSquashMergeMessage
ctx.Data["DefaultSquashMergeBody"] = fmt.Sprintf("--------------------\n%s\n%s", commitsMsg, defaultSquashMergeBody)
}
Loading