summaryrefslogtreecommitdiffstats
path: root/models/review.go
diff options
context:
space:
mode:
authorkolaente <konrad@kola-entertainments.de>2018-11-22 14:17:36 +0100
committerLauris BH <lauris@nix.lv>2018-11-22 15:17:36 +0200
commit0dcf31ae49707c10c1b14e112e0831e920cb6e16 (patch)
treefae417a40cfad5dc19d625e797628cc5c6ebbb8f /models/review.go
parentcef0f12c51cee9edeb636fd2174f8d4eb00ea955 (diff)
downloadgitea-0dcf31ae49707c10c1b14e112e0831e920cb6e16.tar.gz
gitea-0dcf31ae49707c10c1b14e112e0831e920cb6e16.zip
Show review summary in pull requests (#5132)
Diffstat (limited to 'models/review.go')
-rw-r--r--models/review.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/models/review.go b/models/review.go
index f58d3f90cb..7eabb93746 100644
--- a/models/review.go
+++ b/models/review.go
@@ -255,3 +255,36 @@ func UpdateReview(r *Review) error {
}
return nil
}
+
+// PullReviewersWithType represents the type used to display a review overview
+type PullReviewersWithType struct {
+ User `xorm:"extends"`
+ Type ReviewType
+ ReviewUpdatedUnix util.TimeStamp `xorm:"review_updated_unix"`
+}
+
+// GetReviewersByPullID gets all reviewers for a pull request with the statuses
+func GetReviewersByPullID(pullID int64) (issueReviewers []*PullReviewersWithType, err error) {
+ irs := []*PullReviewersWithType{}
+ err = x.Select("`user`.*, review.type, max(review.updated_unix) as review_updated_unix").
+ Table("review").
+ Join("INNER", "`user`", "review.reviewer_id = `user`.id").
+ Where("review.issue_id = ? AND (review.type = ? OR review.type = ?)", pullID, ReviewTypeApprove, ReviewTypeReject).
+ GroupBy("`user`.id, review.type").
+ OrderBy("review_updated_unix DESC").
+ Find(&irs)
+
+ // We need to group our results by user id _and_ review type, otherwise the query fails when using postgresql.
+ // But becaus we're doing this, we need to manually filter out multiple reviews of different types by the
+ // same person because we only want to show the newest review grouped by user. Thats why we're using a map here.
+ issueReviewers = []*PullReviewersWithType{}
+ usersInArray := make(map[int64]bool)
+ for _, ir := range irs {
+ if !usersInArray[ir.ID] {
+ issueReviewers = append(issueReviewers, ir)
+ usersInArray[ir.ID] = true
+ }
+ }
+
+ return
+}