aboutsummaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorparnic <github@parnic.com>2022-04-26 17:40:01 -0500
committerGitHub <noreply@github.com>2022-04-26 23:40:01 +0100
commitcdab46220d62805b21474bfc1d3c2b5d9a63750f (patch)
tree924edb015e94f6ac68b3a70ad99b66139bd0a9bf /services
parent0b38084baa0b27389850edde05ce3105f96a04b0 (diff)
downloadgitea-cdab46220d62805b21474bfc1d3c2b5d9a63750f.tar.gz
gitea-cdab46220d62805b21474bfc1d3c2b5d9a63750f.zip
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
Diffstat (limited to 'services')
-rw-r--r--services/pull/pull.go42
1 files changed, 24 insertions, 18 deletions
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