diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2020-11-06 15:04:21 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-06 09:04:21 +0200 |
commit | 35cc82abbf2315f05a5132115bc6e53786df6a3c (patch) | |
tree | bb3691948c5e5b216bd1a471a82b809cb439a0a8 /services/pull/review.go | |
parent | 3c7908b51c78d549160597e6bc9c98930c6a25c9 (diff) | |
download | gitea-35cc82abbf2315f05a5132115bc6e53786df6a3c.tar.gz gitea-35cc82abbf2315f05a5132115bc6e53786df6a3c.zip |
Revert "Replies to outdated code comments should also be outdated (#13217)" (#13439)
This reverts commit 3cab3bee5750a12da9ef8a9ba5cbe3da00594921.
Diffstat (limited to 'services/pull/review.go')
-rw-r--r-- | services/pull/review.go | 83 |
1 files changed, 24 insertions, 59 deletions
diff --git a/services/pull/review.go b/services/pull/review.go index f0ee234a42..99afdd73c2 100644 --- a/services/pull/review.go +++ b/services/pull/review.go @@ -122,76 +122,41 @@ func createCodeComment(doer *models.User, repo *models.Repository, issue *models } defer gitRepo.Close() - invalidated := false - head := pr.GetGitRefName() + // FIXME validate treePath + // Get latest commit referencing the commented line + // No need for get commit for base branch changes if line > 0 { - 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 { - commitID = first[0].CommitSHA - invalidated = first[0].Invalidated - patch = first[0].Patch - } else if err != nil && !models.IsErrCommentNotExist(err) { - return nil, fmt.Errorf("Find first comment for %d line %d path %s. Error: %v", reviewID, line, treePath, err) - } else { - review, err := models.GetReviewByID(reviewID) - if err == nil && len(review.CommitID) > 0 { - head = review.CommitID - } else if err != nil && !models.IsErrReviewNotExist(err) { - return nil, fmt.Errorf("GetReviewByID %d. Error: %v", reviewID, err) - } - } - } - - if len(commitID) == 0 { - // FIXME validate treePath - // Get latest commit referencing the commented line - // No need for get commit for base branch changes - commit, err := gitRepo.LineBlame(head, gitRepo.Path, treePath, uint(line)) - if err == nil { - commitID = commit.ID.String() - } else if !(strings.Contains(err.Error(), "exit status 128 - fatal: no such path") || notEnoughLines.MatchString(err.Error())) { - return nil, fmt.Errorf("LineBlame[%s, %s, %s, %d]: %v", pr.GetGitRefName(), gitRepo.Path, treePath, line, err) - } + commit, err := gitRepo.LineBlame(pr.GetGitRefName(), gitRepo.Path, treePath, uint(line)) + if err == nil { + commitID = commit.ID.String() + } else if !(strings.Contains(err.Error(), "exit status 128 - fatal: no such path") || notEnoughLines.MatchString(err.Error())) { + return nil, fmt.Errorf("LineBlame[%s, %s, %s, %d]: %v", pr.GetGitRefName(), gitRepo.Path, treePath, line, err) } } // Only fetch diff if comment is review comment - if len(patch) == 0 && reviewID != 0 { - if len(commitID) == 0 { - commitID, err = gitRepo.GetRefCommitID(pr.GetGitRefName()) - if err != nil { - return nil, fmt.Errorf("GetRefCommitID[%s]: %v", pr.GetGitRefName(), err) - } + if reviewID != 0 { + headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitRefName()) + if err != nil { + return nil, fmt.Errorf("GetRefCommitID[%s]: %v", pr.GetGitRefName(), err) } - patchBuf := new(bytes.Buffer) - if err := git.GetRepoRawDiffForFile(gitRepo, pr.MergeBase, commitID, git.RawDiffNormal, treePath, patchBuf); err != nil { - return nil, fmt.Errorf("GetRawDiffForLine[%s, %s, %s, %s]: %v", gitRepo.Path, pr.MergeBase, commitID, treePath, err) + if err := git.GetRepoRawDiffForFile(gitRepo, pr.MergeBase, headCommitID, git.RawDiffNormal, treePath, patchBuf); err != nil { + return nil, fmt.Errorf("GetRawDiffForLine[%s, %s, %s, %s]: %v", err, gitRepo.Path, pr.MergeBase, headCommitID, treePath) } 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, - Invalidated: invalidated, + Type: models.CommentTypeCode, + Doer: doer, + Repo: repo, + Issue: issue, + Content: content, + LineNum: line, + TreePath: treePath, + CommitSHA: commitID, + ReviewID: reviewID, + Patch: patch, }) } |