diff options
author | guillep2k <18600385+guillep2k@users.noreply.github.com> | 2019-11-24 02:46:16 -0300 |
---|---|---|
committer | techknowlogick <techknowlogick@gitea.io> | 2019-11-24 00:46:16 -0500 |
commit | d779deef6ec95db35299096cc1170ada553b102c (patch) | |
tree | e9c3432ebd351ff0f5d806f5a426bf12d0470468 | |
parent | 8ab35eefc4ff5db3f2f0a62f6f0272eae9be0585 (diff) | |
download | gitea-d779deef6ec95db35299096cc1170ada553b102c.tar.gz gitea-d779deef6ec95db35299096cc1170ada553b102c.zip |
Fix show single review comments in the PR page (#9143)
-rw-r--r-- | models/review.go | 5 | ||||
-rw-r--r-- | services/pull/review.go | 32 |
2 files changed, 34 insertions, 3 deletions
diff --git a/models/review.go b/models/review.go index 0dc44a2a4c..fb989b2b35 100644 --- a/models/review.go +++ b/models/review.go @@ -223,6 +223,11 @@ func getCurrentReview(e Engine, reviewer *User, issue *Issue) (*Review, error) { return reviews[0], nil } +// ReviewExists returns whether a review exists for a particular line of code in the PR +func ReviewExists(issue *Issue, treePath string, line int64) (bool, error) { + return x.Cols("id").Exist(&Comment{IssueID: issue.ID, TreePath: treePath, Line: line, Type: CommentTypeCode}) +} + // GetCurrentReview returns the current pending review of reviewer for given issue func GetCurrentReview(reviewer *User, issue *Issue) (*Review, error) { return getCurrentReview(x, reviewer, issue) diff --git a/services/pull/review.go b/services/pull/review.go index 880647c6b5..29cd4fb716 100644 --- a/services/pull/review.go +++ b/services/pull/review.go @@ -19,9 +19,28 @@ import ( // CreateCodeComment creates a comment on the code line func CreateCodeComment(doer *models.User, issue *models.Issue, line int64, content string, treePath string, isReview bool, replyReviewID int64) (*models.Comment, error) { - // It's not a review, maybe a reply to a review comment or a single comment. + + var ( + existsReview bool + err error + ) + + // CreateCodeComment() is used for: + // - Single comments + // - Comments that are part of a review + // - Comments that reply to an existing review + if !isReview { - if err := issue.LoadRepo(); err != nil { + // It's not part of a review; maybe a reply to a review comment or a single comment. + // Check if there are reviews for that line already; if there are, this is a reply + if existsReview, err = models.ReviewExists(issue, treePath, line); err != nil { + return nil, err + } + } + + // Comments that are replies don't require a review header to show up in the issue view + if !isReview && existsReview { + if err = issue.LoadRepo(); err != nil { return nil, err } @@ -72,7 +91,14 @@ func CreateCodeComment(doer *models.User, issue *models.Issue, line int64, conte return nil, err } - // NOTICE: it's a pending review, so the notifications will not be fired until user submit review. + if !isReview && !existsReview { + // Submit the review we've just created so the comment shows up in the issue view + if _, _, err = SubmitReview(doer, issue, models.ReviewTypeComment, ""); err != nil { + return nil, err + } + } + + // NOTICE: if it's a pending review the notifications will not be fired until user submit review. return comment, nil } |