diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 3b9fd0bbca..ee36216d9f 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -269,14 +269,15 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti } } - commitStatus, err := pull_service.GetIssuesLastCommitStatus(ctx, issues) + commitStatuses, lastStatus, err := pull_service.GetIssuesAllCommitStatus(ctx, issues) if err != nil { - ctx.ServerError("GetIssuesLastCommitStatus", err) + ctx.ServerError("GetIssuesAllCommitStatus", err) return } ctx.Data["Issues"] = issues - ctx.Data["CommitStatus"] = commitStatus + ctx.Data["CommitLastStatus"] = lastStatus + ctx.Data["CommitStatuses"] = commitStatuses // Get assignees. ctx.Data["Assignees"], err = models.GetRepoAssignees(repo) diff --git a/routers/web/user/home.go b/routers/web/user/home.go index 73a1e9e556..2e7b382de6 100644 --- a/routers/web/user/home.go +++ b/routers/web/user/home.go @@ -573,7 +573,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) { } } - commitStatus, err := pull_service.GetIssuesLastCommitStatus(ctx, issues) + commitStatuses, lastStatus, err := pull_service.GetIssuesAllCommitStatus(ctx, issues) if err != nil { ctx.ServerError("GetIssuesLastCommitStatus", err) return @@ -650,7 +650,8 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) { } return 0 } - ctx.Data["CommitStatus"] = commitStatus + ctx.Data["CommitLastStatus"] = lastStatus + ctx.Data["CommitStatuses"] = commitStatuses ctx.Data["Repos"] = showRepos ctx.Data["Counts"] = issueCountByRepo ctx.Data["IssueStats"] = issueStats diff --git a/services/pull/pull.go b/services/pull/pull.go index 0537964b9d..f036211871 100644 --- a/services/pull/pull.go +++ b/services/pull/pull.go @@ -726,18 +726,25 @@ func GetSquashMergeCommitMessages(ctx context.Context, pr *models.PullRequest) s return stringBuilder.String() } -// GetIssuesLastCommitStatus returns a map +// GetIssuesLastCommitStatus returns a map of issue ID to the most recent commit's latest status func GetIssuesLastCommitStatus(ctx context.Context, issues models.IssueList) (map[int64]*models.CommitStatus, error) { + _, lastStatus, err := GetIssuesAllCommitStatus(ctx, issues) + return lastStatus, err +} + +// 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 +func GetIssuesAllCommitStatus(ctx context.Context, issues models.IssueList) (map[int64][]*models.CommitStatus, map[int64]*models.CommitStatus, error) { if err := issues.LoadPullRequests(); err != nil { - return nil, err + return nil, nil, err } if _, err := issues.LoadRepositories(); err != nil { - return nil, err + return nil, nil, err } var ( gitRepos = make(map[int64]*git.Repository) - res = make(map[int64]*models.CommitStatus) + res = make(map[int64][]*models.CommitStatus) + lastRes = make(map[int64]*models.CommitStatus) err error ) defer func() { @@ -760,28 +767,27 @@ func GetIssuesLastCommitStatus(ctx context.Context, issues models.IssueList) (ma gitRepos[issue.RepoID] = gitRepo } - status, err := getLastCommitStatus(gitRepo, issue.PullRequest) + statuses, lastStatus, err := getAllCommitStatus(gitRepo, issue.PullRequest) if err != nil { - log.Error("getLastCommitStatus: cant get last commit of pull [%d]: %v", issue.PullRequest.ID, err) + log.Error("getAllCommitStatus: cant get commit statuses of pull [%d]: %v", issue.PullRequest.ID, err) continue } - res[issue.PullRequest.ID] = status + res[issue.PullRequest.ID] = statuses + lastRes[issue.PullRequest.ID] = lastStatus } - return res, nil + return res, lastRes, nil } -// getLastCommitStatus get pr's last commit status. PR's last commit status is the head commit id's last commit status -func getLastCommitStatus(gitRepo *git.Repository, pr *models.PullRequest) (status *models.CommitStatus, err error) { - sha, err := gitRepo.GetRefCommitID(pr.GetGitRefName()) - if err != nil { - return nil, err +// getAllCommitStatus get pr's commit statuses. +func getAllCommitStatus(gitRepo *git.Repository, pr *models.PullRequest) (statuses []*models.CommitStatus, lastStatus *models.CommitStatus, err error) { + sha, shaErr := gitRepo.GetRefCommitID(pr.GetGitRefName()) + if shaErr != nil { + return nil, nil, shaErr } - statusList, _, err := models.GetLatestCommitStatus(pr.BaseRepo.ID, sha, db.ListOptions{}) - if err != nil { - return nil, err - } - return models.CalcCommitStatus(statusList), nil + statuses, _, err = models.GetLatestCommitStatus(pr.BaseRepo.ID, sha, db.ListOptions{}) + lastStatus = models.CalcCommitStatus(statuses) + return statuses, lastStatus, err } // IsHeadEqualWithBranch returns if the commits of branchName are available in pull request head diff --git a/templates/shared/issuelist.tmpl b/templates/shared/issuelist.tmpl index 002aa5b5ab..e81855851b 100644 --- a/templates/shared/issuelist.tmpl +++ b/templates/shared/issuelist.tmpl @@ -33,8 +33,8 @@