@@ -29,7 +29,7 @@ func CreateCodeComment(doer *models.User, gitRepo *git.Repository, issue *models
// - Comments that are part of a review
// - Comments that reply to an existing review
if !isReview {
if !isReview && replyReviewID != 0 {
// 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 {
@@ -38,7 +38,7 @@ func CreateCodeComment(doer *models.User, gitRepo *git.Repository, issue *models
}
// Comments that are replies don't require a review header to show up in the issue view
if !isReview && existsReview && replyReviewID != 0 {
if !isReview && existsReview {
if err = issue.LoadRepo(); err != nil {
return nil, err
}
@@ -123,6 +123,7 @@ func createCodeComment(doer *models.User, repo *models.Repository, issue *models
// FIXME validate treePath
// Get latest commit referencing the commented line
// No need for get commit for base branch changes
invalidated := false
if line > 0 {
commit, err := gitRepo.LineBlame(pr.GetGitRefName(), gitRepo.Path, treePath, uint(line))
if err == nil {
@@ -134,6 +135,19 @@ func createCodeComment(doer *models.User, repo *models.Repository, issue *models
// Only fetch diff if comment is review comment
if reviewID != 0 {
first, err := models.FindComments(models.FindCommentsOptions{
ReviewID: reviewID,
Line: line,
TreePath: treePath,
Type: models.CommentTypeCode,
ListOptions: models.ListOptions{
PageSize: 1,
Page: 1,
},
})
if err == nil && len(first) > 0 {
invalidated = first[0].Invalidated
}
headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitRefName())
if err != nil {
return nil, fmt.Errorf("GetRefCommitID[%s]: %v", pr.GetGitRefName(), err)
@@ -145,16 +159,17 @@ func createCodeComment(doer *models.User, repo *models.Repository, issue *models
patch = git.CutDiffAroundLine(patchBuf, int64((&models.Comment{Line: line}).UnsignedLine()), line < 0, setting.UI.CodeCommentLines)
}
return models.CreateComment(&models.CreateCommentOptions{
Type: models.CommentTypeCode,
Doer: doer,
Repo: repo,
Issue: issue,
Content: content,
LineNum: line,
TreePath: treePath,
CommitSHA: commitID,
ReviewID: reviewID,
Patch: patch,
Type: models.CommentTypeCode,
Doer: doer,
Repo: repo,
Issue: issue,
Content: content,
LineNum: line,
TreePath: treePath,
CommitSHA: commitID,
ReviewID: reviewID,
Patch: patch,
Invalidated: invalidated,
})
}