Skip to content

Commit 05c4db8

Browse files
committed
fix test
1 parent 7d53f05 commit 05c4db8

File tree

1 file changed

+13
-31
lines changed

1 file changed

+13
-31
lines changed

routers/web/repo/issue_view.go

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,10 @@ func ViewIssue(ctx *context.Context) {
388388
prepareIssueViewSidebarTimeTracker,
389389
prepareIssueViewSidebarDependency,
390390
prepareIssueViewSidebarPin,
391-
func(ctx *context.Context, issue *issues_model.Issue) { preparePullViewPullInfo(ctx, issue) },
392-
preparePullViewReviewAndMerge,
391+
func(ctx *context.Context, issue *issues_model.Issue) {
392+
compareInfo := preparePullViewPullInfo(ctx, issue)
393+
preparePullViewReviewAndMerge(ctx, issue, compareInfo)
394+
},
393395
}
394396

395397
for _, prepareFunc := range prepareFuncs {
@@ -441,8 +443,8 @@ func ViewPullMergeBox(ctx *context.Context) {
441443
ctx.NotFound(nil)
442444
return
443445
}
444-
preparePullViewPullInfo(ctx, issue)
445-
preparePullViewReviewAndMerge(ctx, issue)
446+
compareInfo := preparePullViewPullInfo(ctx, issue)
447+
preparePullViewReviewAndMerge(ctx, issue, compareInfo)
446448
ctx.Data["PullMergeBoxReloading"] = issue.PullRequest.IsChecking()
447449

448450
// TODO: it should use a dedicated struct to render the pull merge box, to make sure all data is prepared correctly
@@ -823,7 +825,7 @@ func prepareIssueViewCommentsAndSidebarParticipants(ctx *context.Context, issue
823825
ctx.Data["NumParticipants"] = len(participants)
824826
}
825827

826-
func preparePullViewReviewAndMerge(ctx *context.Context, issue *issues_model.Issue) {
828+
func preparePullViewReviewAndMerge(ctx *context.Context, issue *issues_model.Issue, compareInfo *pull_service.CompareInfo) {
827829
getBranchData(ctx, issue)
828830
if !issue.IsPull {
829831
return
@@ -938,14 +940,15 @@ func preparePullViewReviewAndMerge(ctx *context.Context, issue *issues_model.Iss
938940

939941
defaultSquashMergeBody = fmt.Sprintf("%s%s", defaultSquashMergeBody, coAuthors)
940942

941-
commitsMsg, err := getPullViewSquashMergeCommits(ctx, issue)
942-
if err != nil {
943-
ctx.ServerError("getPullViewSquashMergeCommits", err)
944-
return
943+
commitsBuilder := strings.Builder{}
944+
for _, c := range compareInfo.Commits {
945+
commitsBuilder.WriteString("* ")
946+
commitsBuilder.WriteString(c.CommitMessage)
947+
commitsBuilder.WriteRune('\n')
945948
}
946949

947950
ctx.Data["DefaultSquashMergeMessage"] = defaultSquashMergeMessage
948-
ctx.Data["DefaultSquashMergeBody"] = fmt.Sprintf("--------------------\n%s%s", commitsMsg, defaultSquashMergeBody)
951+
ctx.Data["DefaultSquashMergeBody"] = fmt.Sprintf("--------------------\n%s%s", commitsBuilder.String(), defaultSquashMergeBody)
949952

950953
pb, err := git_model.GetFirstMatchProtectedBranchRule(ctx, pull.BaseRepoID, pull.BaseBranch)
951954
if err != nil {
@@ -1017,24 +1020,3 @@ func prepareIssueViewContent(ctx *context.Context, issue *issues_model.Issue) {
10171020
return
10181021
}
10191022
}
1020-
1021-
func getPullViewSquashMergeCommits(ctx *context.Context, issue *issues_model.Issue) (string, error) {
1022-
pull := issue.PullRequest
1023-
pull.Issue = issue
1024-
1025-
baseCommit := GetMergedBaseCommitID(ctx, issue)
1026-
1027-
compareInfo, err := pull_service.GetCompareInfo(ctx, ctx.Repo.Repository, ctx.Repo.Repository, ctx.Repo.GitRepo, baseCommit, pull.GetGitHeadRefName(), false, false)
1028-
if err != nil {
1029-
return "", err
1030-
}
1031-
1032-
commitsBuilder := strings.Builder{}
1033-
for _, c := range compareInfo.Commits {
1034-
commitsBuilder.WriteString("* ")
1035-
commitsBuilder.WriteString(c.CommitMessage)
1036-
commitsBuilder.WriteRune('\n')
1037-
}
1038-
1039-
return commitsBuilder.String(), nil
1040-
}

0 commit comments

Comments
 (0)