From 97980146c52c1cb27e18f60fcd876519d53dad2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=99=BA=E8=B6=85?= <1012112796@qq.com> Date: Wed, 14 Oct 2020 20:11:11 +0800 Subject: [PATCH] Show original author's reviews on pull summary box (#13127) follow #12039, show original author's reviews by other way. fix #11705. Signed-off-by: a1012112796 <1012112796@qq.com> --- models/review.go | 14 +++++++++++++ routers/repo/issue.go | 7 +++++++ templates/repo/issue/view_content/pull.tmpl | 20 ++++++++++++++++++- .../repo/issue/view_content/sidebar.tmpl | 14 ++++++++++++- 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/models/review.go b/models/review.go index 2c38176ef4..326b06b5ed 100644 --- a/models/review.go +++ b/models/review.go @@ -486,6 +486,20 @@ func GetReviewersByIssueID(issueID int64) ([]*Review, error) { return reviews, nil } +// GetReviewersFromOriginalAuthorsByIssueID gets the latest review of each original authors for a pull request +func GetReviewersFromOriginalAuthorsByIssueID(issueID int64) ([]*Review, error) { + reviews := make([]*Review, 0, 10) + + // Get latest review of each reviwer, sorted in order they were made + if err := x.SQL("SELECT * FROM review WHERE id IN (SELECT max(id) as id FROM review WHERE issue_id = ? AND reviewer_team_id = 0 AND type in (?, ?, ?) AND original_author_id <> 0 GROUP BY issue_id, original_author_id) ORDER BY review.updated_unix ASC", + issueID, ReviewTypeApprove, ReviewTypeReject, ReviewTypeRequest). + Find(&reviews); err != nil { + return nil, err + } + + return reviews, nil +} + // GetReviewByIssueIDAndUserID get the latest review of reviewer for a pull request func GetReviewByIssueIDAndUserID(issueID, userID int64) (*Review, error) { return getReviewByIssueIDAndUserID(x, issueID, userID) diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 7977647097..8aef322090 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -450,6 +450,13 @@ type repoReviewerSelection struct { func RetrieveRepoReviewers(ctx *context.Context, repo *models.Repository, issue *models.Issue, canChooseReviewer bool) { ctx.Data["CanChooseReviewer"] = canChooseReviewer + originalAuthorReviews, err := models.GetReviewersFromOriginalAuthorsByIssueID(issue.ID) + if err != nil { + ctx.ServerError("GetReviewersFromOriginalAuthorsByIssueID", err) + return + } + ctx.Data["OriginalReviews"] = originalAuthorReviews + reviews, err := models.GetReviewersByIssueID(issue.ID) if err != nil { ctx.ServerError("GetReviewersByIssueID", err) diff --git a/templates/repo/issue/view_content/pull.tmpl b/templates/repo/issue/view_content/pull.tmpl index d043c269ee..a67783ebb1 100644 --- a/templates/repo/issue/view_content/pull.tmpl +++ b/templates/repo/issue/view_content/pull.tmpl @@ -1,4 +1,4 @@ -{{if .PullReviewers }} +{{if or .PullReviewers .OriginalReviews }}