Skip to content

Commit cdab462

Browse files
authored
Add commit status popup to issuelist (#19375)
This gets the necessary data to the issuelist for it to support a clickable commit status icon which pops up the full list of commit statuses related to the commit. It accomplishes this without any additional queries or fetching as the existing codepath was already doing the necessary work but only returning the "last" status. All methods were wrapped to call the least-filtered version of each function in order to maximize code reuse. Note that I originally left `getLastCommitStatus()` in `pull.go` which called to the new function, but `make lint` complained that it was unused, so I removed it. I would have preferred to keep it, but alas. The only thing I'd still like to do here is force these popups to happen to the right by default instead of the left. I see that the only other place this is popping up right is on view_list.tmpl, but I can't figure out how/why right now. Fixes #18810
1 parent 0b38084 commit cdab462

File tree

4 files changed

+33
-25
lines changed

4 files changed

+33
-25
lines changed

routers/web/repo/issue.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,14 +269,15 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
269269
}
270270
}
271271

272-
commitStatus, err := pull_service.GetIssuesLastCommitStatus(ctx, issues)
272+
commitStatuses, lastStatus, err := pull_service.GetIssuesAllCommitStatus(ctx, issues)
273273
if err != nil {
274-
ctx.ServerError("GetIssuesLastCommitStatus", err)
274+
ctx.ServerError("GetIssuesAllCommitStatus", err)
275275
return
276276
}
277277

278278
ctx.Data["Issues"] = issues
279-
ctx.Data["CommitStatus"] = commitStatus
279+
ctx.Data["CommitLastStatus"] = lastStatus
280+
ctx.Data["CommitStatuses"] = commitStatuses
280281

281282
// Get assignees.
282283
ctx.Data["Assignees"], err = models.GetRepoAssignees(repo)

routers/web/user/home.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
573573
}
574574
}
575575

576-
commitStatus, err := pull_service.GetIssuesLastCommitStatus(ctx, issues)
576+
commitStatuses, lastStatus, err := pull_service.GetIssuesAllCommitStatus(ctx, issues)
577577
if err != nil {
578578
ctx.ServerError("GetIssuesLastCommitStatus", err)
579579
return
@@ -650,7 +650,8 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
650650
}
651651
return 0
652652
}
653-
ctx.Data["CommitStatus"] = commitStatus
653+
ctx.Data["CommitLastStatus"] = lastStatus
654+
ctx.Data["CommitStatuses"] = commitStatuses
654655
ctx.Data["Repos"] = showRepos
655656
ctx.Data["Counts"] = issueCountByRepo
656657
ctx.Data["IssueStats"] = issueStats

services/pull/pull.go

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -726,18 +726,25 @@ func GetSquashMergeCommitMessages(ctx context.Context, pr *models.PullRequest) s
726726
return stringBuilder.String()
727727
}
728728

729-
// GetIssuesLastCommitStatus returns a map
729+
// GetIssuesLastCommitStatus returns a map of issue ID to the most recent commit's latest status
730730
func GetIssuesLastCommitStatus(ctx context.Context, issues models.IssueList) (map[int64]*models.CommitStatus, error) {
731+
_, lastStatus, err := GetIssuesAllCommitStatus(ctx, issues)
732+
return lastStatus, err
733+
}
734+
735+
// GetIssuesAllCommitStatus returns a map of issue ID to a list of all statuses for the most recent commit as well as a map of issue ID to only the commit's latest status
736+
func GetIssuesAllCommitStatus(ctx context.Context, issues models.IssueList) (map[int64][]*models.CommitStatus, map[int64]*models.CommitStatus, error) {
731737
if err := issues.LoadPullRequests(); err != nil {
732-
return nil, err
738+
return nil, nil, err
733739
}
734740
if _, err := issues.LoadRepositories(); err != nil {
735-
return nil, err
741+
return nil, nil, err
736742
}
737743

738744
var (
739745
gitRepos = make(map[int64]*git.Repository)
740-
res = make(map[int64]*models.CommitStatus)
746+
res = make(map[int64][]*models.CommitStatus)
747+
lastRes = make(map[int64]*models.CommitStatus)
741748
err error
742749
)
743750
defer func() {
@@ -760,28 +767,27 @@ func GetIssuesLastCommitStatus(ctx context.Context, issues models.IssueList) (ma
760767
gitRepos[issue.RepoID] = gitRepo
761768
}
762769

763-
status, err := getLastCommitStatus(gitRepo, issue.PullRequest)
770+
statuses, lastStatus, err := getAllCommitStatus(gitRepo, issue.PullRequest)
764771
if err != nil {
765-
log.Error("getLastCommitStatus: cant get last commit of pull [%d]: %v", issue.PullRequest.ID, err)
772+
log.Error("getAllCommitStatus: cant get commit statuses of pull [%d]: %v", issue.PullRequest.ID, err)
766773
continue
767774
}
768-
res[issue.PullRequest.ID] = status
775+
res[issue.PullRequest.ID] = statuses
776+
lastRes[issue.PullRequest.ID] = lastStatus
769777
}
770-
return res, nil
778+
return res, lastRes, nil
771779
}
772780

773-
// getLastCommitStatus get pr's last commit status. PR's last commit status is the head commit id's last commit status
774-
func getLastCommitStatus(gitRepo *git.Repository, pr *models.PullRequest) (status *models.CommitStatus, err error) {
775-
sha, err := gitRepo.GetRefCommitID(pr.GetGitRefName())
776-
if err != nil {
777-
return nil, err
781+
// getAllCommitStatus get pr's commit statuses.
782+
func getAllCommitStatus(gitRepo *git.Repository, pr *models.PullRequest) (statuses []*models.CommitStatus, lastStatus *models.CommitStatus, err error) {
783+
sha, shaErr := gitRepo.GetRefCommitID(pr.GetGitRefName())
784+
if shaErr != nil {
785+
return nil, nil, shaErr
778786
}
779787

780-
statusList, _, err := models.GetLatestCommitStatus(pr.BaseRepo.ID, sha, db.ListOptions{})
781-
if err != nil {
782-
return nil, err
783-
}
784-
return models.CalcCommitStatus(statusList), nil
788+
statuses, _, err = models.GetLatestCommitStatus(pr.BaseRepo.ID, sha, db.ListOptions{})
789+
lastStatus = models.CalcCommitStatus(statuses)
790+
return statuses, lastStatus, err
785791
}
786792

787793
// IsHeadEqualWithBranch returns if the commits of branchName are available in pull request head

templates/shared/issuelist.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
<div class="issue-item-top-row">
3434
<a class="title tdn" href="{{if .HTMLURL}}{{.HTMLURL}}{{else}}{{$.Link}}/{{.Index}}{{end}}">{{RenderEmoji .Title}}</a>
3535
{{if .IsPull}}
36-
{{if (index $.CommitStatus .PullRequest.ID)}}
37-
{{template "repo/commit_status" (index $.CommitStatus .PullRequest.ID)}}
36+
{{if (index $.CommitStatuses .PullRequest.ID)}}
37+
{{template "repo/commit_statuses" dict "Status" (index $.CommitLastStatus .PullRequest.ID) "Statuses" (index $.CommitStatuses .PullRequest.ID) "root" $}}
3838
{{end}}
3939
{{end}}
4040
<span class="labels-list ml-2">

0 commit comments

Comments
 (0)