Skip to content

Commit d779dee

Browse files
guillep2ktechknowlogick
authored andcommitted
Fix show single review comments in the PR page (#9143)
1 parent 8ab35ee commit d779dee

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

models/review.go

+5
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,11 @@ func getCurrentReview(e Engine, reviewer *User, issue *Issue) (*Review, error) {
223223
return reviews[0], nil
224224
}
225225

226+
// ReviewExists returns whether a review exists for a particular line of code in the PR
227+
func ReviewExists(issue *Issue, treePath string, line int64) (bool, error) {
228+
return x.Cols("id").Exist(&Comment{IssueID: issue.ID, TreePath: treePath, Line: line, Type: CommentTypeCode})
229+
}
230+
226231
// GetCurrentReview returns the current pending review of reviewer for given issue
227232
func GetCurrentReview(reviewer *User, issue *Issue) (*Review, error) {
228233
return getCurrentReview(x, reviewer, issue)

services/pull/review.go

+29-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,28 @@ import (
1919

2020
// CreateCodeComment creates a comment on the code line
2121
func CreateCodeComment(doer *models.User, issue *models.Issue, line int64, content string, treePath string, isReview bool, replyReviewID int64) (*models.Comment, error) {
22-
// It's not a review, maybe a reply to a review comment or a single comment.
22+
23+
var (
24+
existsReview bool
25+
err error
26+
)
27+
28+
// CreateCodeComment() is used for:
29+
// - Single comments
30+
// - Comments that are part of a review
31+
// - Comments that reply to an existing review
32+
2333
if !isReview {
24-
if err := issue.LoadRepo(); err != nil {
34+
// It's not part of a review; maybe a reply to a review comment or a single comment.
35+
// Check if there are reviews for that line already; if there are, this is a reply
36+
if existsReview, err = models.ReviewExists(issue, treePath, line); err != nil {
37+
return nil, err
38+
}
39+
}
40+
41+
// Comments that are replies don't require a review header to show up in the issue view
42+
if !isReview && existsReview {
43+
if err = issue.LoadRepo(); err != nil {
2544
return nil, err
2645
}
2746

@@ -72,7 +91,14 @@ func CreateCodeComment(doer *models.User, issue *models.Issue, line int64, conte
7291
return nil, err
7392
}
7493

75-
// NOTICE: it's a pending review, so the notifications will not be fired until user submit review.
94+
if !isReview && !existsReview {
95+
// Submit the review we've just created so the comment shows up in the issue view
96+
if _, _, err = SubmitReview(doer, issue, models.ReviewTypeComment, ""); err != nil {
97+
return nil, err
98+
}
99+
}
100+
101+
// NOTICE: if it's a pending review the notifications will not be fired until user submit review.
76102

77103
return comment, nil
78104
}

0 commit comments

Comments
 (0)