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
This commit is contained in:
zeripath 2020-03-06 03:44:06 +00:00 committed by GitHub
parent f422a115f4
commit 80db44267c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 154 additions and 4 deletions

View file

@ -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
}

View file

@ -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 {