mirror of
https://github.com/go-gitea/gitea.git
synced 2025-08-06 05:19:01 +00:00
Fix test
This commit is contained in:
parent
e895298aba
commit
c68718d114
@ -37,13 +37,14 @@ func TestHandlePullRequestMerging(t *testing.T) {
|
||||
PullRequestID: pr.ID,
|
||||
UserID: 2,
|
||||
}, pr.BaseRepo.OwnerName, pr.BaseRepo.Name, []*repo_module.PushUpdateOptions{
|
||||
{NewCommitID: "01234567"},
|
||||
// assume the first commit is merged from this pull request but it's not a real world scenario
|
||||
{NewCommitID: "65f1bf27bc3bf70f64657658635e66094edbcb4d"},
|
||||
})
|
||||
assert.Empty(t, resp.Body.String())
|
||||
pr, err = issues_model.GetPullRequestByID(db.DefaultContext, pr.ID)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, pr.HasMerged)
|
||||
assert.Equal(t, "01234567", pr.MergedCommitID)
|
||||
assert.Equal(t, "65f1bf27bc3bf70f64657658635e66094edbcb4d", pr.MergedCommitID)
|
||||
|
||||
unittest.AssertNotExistsBean(t, &pull_model.AutoMerge{ID: autoMerge.ID})
|
||||
}
|
||||
|
@ -39,10 +39,7 @@ func TestIssue_DeleteIssue(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, issueIDs, 5)
|
||||
|
||||
issue := &issues_model.Issue{
|
||||
RepoID: 1,
|
||||
ID: issueIDs[2],
|
||||
}
|
||||
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: issueIDs[2]})
|
||||
|
||||
_, err = deleteIssue(db.DefaultContext, issue)
|
||||
assert.NoError(t, err)
|
||||
|
@ -593,8 +593,11 @@ func FetchCodeCommentsByLine(ctx context.Context, gitRepo *git.Repository, repo
|
||||
|
||||
// LoadCodeComments loads comments into each line, so that the comments can be displayed in the diff view.
|
||||
// the comments' line number is recalculated based on the hunks of the diff.
|
||||
func LoadCodeComments(ctx context.Context, gitRepo *git.Repository, repo *repo_model.Repository, diff *gitdiff.Diff, issueID int64, currentUser *user_model.User, startCommit, endCommit *git.Commit, showOutdatedComments bool) error {
|
||||
if startCommit == nil || endCommit == nil {
|
||||
func LoadCodeComments(ctx context.Context, gitRepo *git.Repository, repo *repo_model.Repository,
|
||||
diff *gitdiff.Diff, issueID int64, currentUser *user_model.User,
|
||||
beforeCommit, afterCommit *git.Commit, showOutdatedComments bool,
|
||||
) error {
|
||||
if beforeCommit == nil || afterCommit == nil {
|
||||
return errors.New("startCommit and endCommit cannot be nil")
|
||||
}
|
||||
|
||||
@ -609,9 +612,20 @@ func LoadCodeComments(ctx context.Context, gitRepo *git.Repository, repo *repo_m
|
||||
hunksCache := make(map[string][]*git.HunkInfo)
|
||||
// filecomments should be sorted by created time, so that the latest comments are at the end
|
||||
for _, comment := range fileComments {
|
||||
dstCommitID := startCommit.ID.String()
|
||||
if comment.CommitSHA == "" {
|
||||
if comment.Line > 0 {
|
||||
comment.CommitSHA = afterCommit.ID.String()
|
||||
} else if comment.Line < 0 {
|
||||
comment.CommitSHA = beforeCommit.ID.String()
|
||||
} else {
|
||||
// If the comment has no line number, we cannot display it in the diff view
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
dstCommitID := beforeCommit.ID.String()
|
||||
if comment.Line > 0 {
|
||||
dstCommitID = endCommit.ID.String()
|
||||
dstCommitID = afterCommit.ID.String()
|
||||
}
|
||||
|
||||
if comment.CommitSHA == dstCommitID {
|
||||
|
@ -82,12 +82,12 @@ func TestDiff_LoadCommentsNoOutdated(t *testing.T) {
|
||||
gitRepo, err := gitrepo.OpenRepository(t.Context(), issue.Repo)
|
||||
assert.NoError(t, err)
|
||||
defer gitRepo.Close()
|
||||
startCommit, err := gitRepo.GetCommit(issue.PullRequest.MergeBase)
|
||||
beforeCommit, err := gitRepo.GetCommit(issue.PullRequest.MergeBase)
|
||||
assert.NoError(t, err)
|
||||
endCommit, err := gitRepo.GetCommit(issue.PullRequest.GetGitHeadRefName())
|
||||
afterCommit, err := gitRepo.GetCommit(issue.PullRequest.GetGitHeadRefName())
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.NoError(t, pull_service.LoadCodeComments(db.DefaultContext, gitRepo, issue.Repo, diff, issue.ID, user, startCommit, endCommit, false))
|
||||
assert.NoError(t, pull_service.LoadCodeComments(db.DefaultContext, gitRepo, issue.Repo, diff, issue.ID, user, beforeCommit, afterCommit, false))
|
||||
assert.Len(t, diff.Files[0].Sections[0].Lines[0].Comments, 2)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user