Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show single review comments in the PR conversation tab #9143

Merged
merged 3 commits into from
Nov 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions models/review.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 29 additions & 3 deletions services/pull/review.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
Expand Down