#4407 fix-4083

Merged
zouap merged 2 commits from fix-4083 into V20230628 10 months ago
  1. +10
    -0
      models/issue_comment.go
  2. +27
    -12
      services/pull/review.go

+ 10
- 0
models/issue_comment.go View File

@@ -578,6 +578,7 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err
RefCommentID: opts.RefCommentID,
RefAction: opts.RefAction,
RefIsPull: opts.RefIsPull,
Invalidated: opts.Invalidated,
}
if _, err = e.Insert(comment); err != nil {
return nil, err
@@ -740,6 +741,7 @@ type CreateCommentOptions struct {
RefCommentID int64
RefAction references.XRefAction
RefIsPull bool
Invalidated bool
}

// CreateComment creates comment of issue or commit.
@@ -815,6 +817,8 @@ type FindCommentsOptions struct {
ReviewID int64
Since int64
Before int64
Line int64
TreePath string
Type CommentType
}

@@ -838,6 +842,12 @@ func (opts *FindCommentsOptions) toConds() builder.Cond {
if opts.Type != CommentTypeUnknown {
cond = cond.And(builder.Eq{"comment.type": opts.Type})
}
if opts.Line != 0 {
cond = cond.And(builder.Eq{"comment.line": opts.Line})
}
if len(opts.TreePath) > 0 {
cond = cond.And(builder.Eq{"comment.tree_path": opts.TreePath})
}
return cond
}



+ 27
- 12
services/pull/review.go View File

@@ -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,
})
}



Loading…
Cancel
Save