aboutsummaryrefslogtreecommitdiffstats
path: root/models/issue_list.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2020-03-06 03:44:06 +0000
committerGitHub <noreply@github.com>2020-03-06 03:44:06 +0000
commit80db44267ccb688c596e8375523af5cd92864d87 (patch)
treeb10136ec813c23e18ab30085a0b6f0e014550702 /models/issue_list.go
parentf422a115f461472db6892da9142e930c67e63128 (diff)
downloadgitea-80db44267ccb688c596e8375523af5cd92864d87.tar.gz
gitea-80db44267ccb688c596e8375523af5cd92864d87.zip
Add Approval Counts to pulls list (#10238)
* Add Approval Counts to pulls list Add simple approvals counts to pulls lists * Remove non-official counts * Add PR features to milestone_issues.tmpl
Diffstat (limited to 'models/issue_list.go')
-rw-r--r--models/issue_list.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/models/issue_list.go b/models/issue_list.go
index 4554f906c4..e6ca3fc890 100644
--- a/models/issue_list.go
+++ b/models/issue_list.go
@@ -515,3 +515,37 @@ func (issues IssueList) LoadComments() error {
func (issues IssueList) LoadDiscussComments() error {
return issues.loadComments(x, builder.Eq{"comment.type": CommentTypeComment})
}
+
+// GetApprovalCounts returns a map of issue ID to slice of approval counts
+// FIXME: only returns official counts due to double counting of non-official approvals
+func (issues IssueList) GetApprovalCounts() (map[int64][]*ReviewCount, error) {
+ return issues.getApprovalCounts(x)
+}
+
+func (issues IssueList) getApprovalCounts(e Engine) (map[int64][]*ReviewCount, error) {
+ rCounts := make([]*ReviewCount, 0, 6*len(issues))
+ ids := make([]int64, len(issues))
+ for i, issue := range issues {
+ ids[i] = issue.ID
+ }
+ sess := e.In("issue_id", ids)
+ err := sess.Select("issue_id, type, count(id) as `count`").Where("official = ?", true).GroupBy("issue_id, type").OrderBy("issue_id").Table("review").Find(&rCounts)
+ if err != nil {
+ return nil, err
+ }
+
+ approvalCountMap := make(map[int64][]*ReviewCount, len(issues))
+ if len(rCounts) > 0 {
+ start := 0
+ lastID := rCounts[0].IssueID
+ for i, current := range rCounts[1:] {
+ if lastID != current.IssueID {
+ approvalCountMap[lastID] = rCounts[start:i]
+ start = i
+ lastID = current.IssueID
+ }
+ }
+ approvalCountMap[lastID] = rCounts[start:]
+ }
+ return approvalCountMap, nil
+}