chore: handle feedback

This commit is contained in:
Rajesh Jonnalagadda 2024-12-10 12:54:50 +05:30
parent 780d483d87
commit 96849dda83
7 changed files with 56 additions and 65 deletions

View File

@ -18,11 +18,11 @@ import (
type CodeComments map[string]map[int64][]*Comment
// FetchCodeComments will return a 2d-map: ["Path"]["Line"] = Comments at line
func FetchCodeComments(ctx context.Context, issue *Issue, currentUser *user_model.User, showOutdatedComments bool) (CodeComments, error) {
return fetchCodeCommentsByReview(ctx, issue, currentUser, nil, showOutdatedComments)
func FetchCodeComments(ctx context.Context, issue *Issue, currentUser *user_model.User, showOutdatedComments bool, filePath *string) (CodeComments, error) {
return fetchCodeCommentsByReview(ctx, issue, currentUser, nil, showOutdatedComments, filePath)
}
func fetchCodeCommentsByReview(ctx context.Context, issue *Issue, currentUser *user_model.User, review *Review, showOutdatedComments bool) (CodeComments, error) {
func fetchCodeCommentsByReview(ctx context.Context, issue *Issue, currentUser *user_model.User, review *Review, showOutdatedComments bool, filePath *string) (CodeComments, error) {
pathToLineToComment := make(CodeComments)
if review == nil {
review = &Review{ID: 0}
@ -33,6 +33,15 @@ func fetchCodeCommentsByReview(ctx context.Context, issue *Issue, currentUser *u
ReviewID: review.ID,
}
if filePath != nil {
opts = FindCommentsOptions{
Type: CommentTypeCode,
IssueID: issue.ID,
ReviewID: review.ID,
TreePath: *filePath,
}
}
comments, err := findCodeComments(ctx, opts, issue, currentUser, review, showOutdatedComments)
if err != nil {
return nil, err

View File

@ -50,7 +50,7 @@ func TestFetchCodeComments(t *testing.T) {
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2})
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
res, err := issues_model.FetchCodeComments(db.DefaultContext, issue, user, false)
res, err := issues_model.FetchCodeComments(db.DefaultContext, issue, user, false, nil)
assert.NoError(t, err)
assert.Contains(t, res, "README.md")
assert.Contains(t, res["README.md"], int64(4))
@ -58,7 +58,7 @@ func TestFetchCodeComments(t *testing.T) {
assert.Equal(t, int64(4), res["README.md"][4][0].ID)
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
res, err = issues_model.FetchCodeComments(db.DefaultContext, issue, user2, false)
res, err = issues_model.FetchCodeComments(db.DefaultContext, issue, user2, false, nil)
assert.NoError(t, err)
assert.Len(t, res, 1)
}

View File

@ -158,7 +158,7 @@ func (r *Review) LoadCodeComments(ctx context.Context) (err error) {
if err = r.LoadIssue(ctx); err != nil {
return err
}
r.CodeComments, err = fetchCodeCommentsByReview(ctx, r.Issue, nil, r, false)
r.CodeComments, err = fetchCodeCommentsByReview(ctx, r.Issue, nil, r, false, nil)
return err
}

View File

@ -932,8 +932,6 @@ func ExcerptBlob(ctx *context.Context) {
LeftHunkSize: leftHunkSize,
RightHunkSize: rightHunkSize,
HasComments: false,
LastRightCommentIdx: 0,
RightCommentIdx: 0,
},
Comments: nil,
}
@ -946,11 +944,11 @@ func ExcerptBlob(ctx *context.Context) {
issueIndex := ctx.FormInt64("issue_index")
if ctx.FormBool("pull") && issueIndex > 0 {
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, issueIndex)
if issue == nil {
if err != nil {
ctx.ServerError("GetIssueByIndex", err)
return
}
allComments, err := issues_model.FetchCodeComments(ctx, issue, ctx.Doer, false)
allComments, err := issues_model.FetchCodeComments(ctx, issue, ctx.Doer, false, &filePath)
if err != nil {
ctx.ServerError("FetchCodeComments", err)
return

View File

@ -1520,10 +1520,6 @@ func registerRoutes(m *web.Router) {
m.Get("/{sha}", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.ExcerptBlob)
}, func(ctx *context.Context) gocontext.CancelFunc {
// FIXME: refactor this function, use separate routes for wiki/code
if ctx.FormBool("pull") {
ctx.Data["PageIsPullFiles"] = true
}
if ctx.FormBool("wiki") {
ctx.Data["PageIsWiki"] = true
repo.MustEnableWiki(ctx)

View File

@ -94,8 +94,6 @@ type DiffLineSectionInfo struct {
LeftHunkSize int
RightHunkSize int
HasComments bool
LastRightCommentIdx int
RightCommentIdx int
}
// BlobExcerptChunkSize represent max lines of excerpt
@ -146,12 +144,10 @@ func (d *DiffLine) GetBlobExcerptQuery() string {
"last_left=%d&last_right=%d&"+
"left=%d&right=%d&"+
"left_hunk_size=%d&right_hunk_size=%d&"+
"last_rightt_comment_idx=%d&right_comment_idx=%d&"+
"path=%s",
d.SectionInfo.LastLeftIdx, d.SectionInfo.LastRightIdx,
d.SectionInfo.LeftIdx, d.SectionInfo.RightIdx,
d.SectionInfo.LeftHunkSize, d.SectionInfo.RightHunkSize,
d.SectionInfo.LastRightCommentIdx, d.SectionInfo.RightCommentIdx,
url.QueryEscape(d.SectionInfo.Path))
return query
}
@ -183,8 +179,6 @@ func getDiffLineSectionInfo(treePath, line string, lastLeftIdx, lastRightIdx int
LeftHunkSize: leftHunk,
RightHunkSize: righHunk,
HasComments: false,
LastRightCommentIdx: 0,
RightCommentIdx: 0,
}
}
@ -410,8 +404,6 @@ func (diffFile *DiffFile) GetTailSection(gitRepo *git.Repository, leftCommit, ri
LeftIdx: leftLineCount,
RightIdx: rightLineCount,
HasComments: false,
LastRightCommentIdx: 0,
RightCommentIdx: 0,
},
}
tailSection := &DiffSection{FileName: diffFile.Name, Lines: []*DiffLine{tailDiffLine}}
@ -469,11 +461,9 @@ type Diff struct {
NumViewedFiles int // user-specific
}
// function (section *DiffSection) GetType() int {
// LoadComments loads comments into each line
func (diff *Diff) LoadComments(ctx context.Context, issue *issues_model.Issue, currentUser *user_model.User, showOutdatedComments bool) error {
allComments, err := issues_model.FetchCodeComments(ctx, issue, currentUser, showOutdatedComments)
allComments, err := issues_model.FetchCodeComments(ctx, issue, currentUser, showOutdatedComments, nil)
if err != nil {
return err
}

View File

@ -67,8 +67,6 @@ func TestGetDiffPreview(t *testing.T) {
LeftHunkSize: 3,
RightHunkSize: 4,
HasComments: false,
LastRightCommentIdx: 0,
RightCommentIdx: 0,
},
},
{