aboutsummaryrefslogtreecommitdiffstats
path: root/models/pull.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/pull.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/pull.go')
-rw-r--r--models/pull.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/models/pull.go b/models/pull.go
index 3e177ea5e9..48d2340544 100644
--- a/models/pull.go
+++ b/models/pull.go
@@ -352,6 +352,25 @@ func (pr *PullRequest) GetCommitMessages() string {
return stringBuilder.String()
}
+// ReviewCount represents a count of Reviews
+type ReviewCount struct {
+ IssueID int64
+ Type ReviewType
+ Count int64
+}
+
+// GetApprovalCounts returns the approval counts by type
+// FIXME: Only returns official counts due to double counting of non-official counts
+func (pr *PullRequest) GetApprovalCounts() ([]*ReviewCount, error) {
+ return pr.getApprovalCounts(x)
+}
+
+func (pr *PullRequest) getApprovalCounts(e Engine) ([]*ReviewCount, error) {
+ rCounts := make([]*ReviewCount, 0, 6)
+ sess := e.Where("issue_id = ?", pr.IssueID)
+ return rCounts, sess.Select("issue_id, type, count(id) as `count`").Where("official = ?", true).GroupBy("issue_id, type").Table("review").Find(&rCounts)
+}
+
// GetApprovers returns the approvers of the pull request
func (pr *PullRequest) GetApprovers() string {