mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-03 00:45:22 +02:00
Show review summary in pull requests (#5132)
This commit is contained in:
parent
cef0f12c51
commit
0dcf31ae49
8 changed files with 179 additions and 2 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue