@@ -19,9 +19,28 @@ import (
1919
2020// CreateCodeComment creates a comment on the code line
2121func 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