mirror of
https://github.com/go-gitea/gitea
synced 2025-01-03 11:55:59 +01:00
chore: handle feedback
This commit is contained in:
parent
780d483d87
commit
96849dda83
@ -18,11 +18,11 @@ import (
|
|||||||
type CodeComments map[string]map[int64][]*Comment
|
type CodeComments map[string]map[int64][]*Comment
|
||||||
|
|
||||||
// FetchCodeComments will return a 2d-map: ["Path"]["Line"] = Comments at line
|
// 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) {
|
func FetchCodeComments(ctx context.Context, issue *Issue, currentUser *user_model.User, showOutdatedComments bool, filePath *string) (CodeComments, error) {
|
||||||
return fetchCodeCommentsByReview(ctx, issue, currentUser, nil, showOutdatedComments)
|
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)
|
pathToLineToComment := make(CodeComments)
|
||||||
if review == nil {
|
if review == nil {
|
||||||
review = &Review{ID: 0}
|
review = &Review{ID: 0}
|
||||||
@ -33,6 +33,15 @@ func fetchCodeCommentsByReview(ctx context.Context, issue *Issue, currentUser *u
|
|||||||
ReviewID: review.ID,
|
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)
|
comments, err := findCodeComments(ctx, opts, issue, currentUser, review, showOutdatedComments)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -50,7 +50,7 @@ func TestFetchCodeComments(t *testing.T) {
|
|||||||
|
|
||||||
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2})
|
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2})
|
||||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
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.NoError(t, err)
|
||||||
assert.Contains(t, res, "README.md")
|
assert.Contains(t, res, "README.md")
|
||||||
assert.Contains(t, res["README.md"], int64(4))
|
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)
|
assert.Equal(t, int64(4), res["README.md"][4][0].ID)
|
||||||
|
|
||||||
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
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.NoError(t, err)
|
||||||
assert.Len(t, res, 1)
|
assert.Len(t, res, 1)
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,7 @@ func (r *Review) LoadCodeComments(ctx context.Context) (err error) {
|
|||||||
if err = r.LoadIssue(ctx); err != nil {
|
if err = r.LoadIssue(ctx); err != nil {
|
||||||
return err
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -924,16 +924,14 @@ func ExcerptBlob(ctx *context.Context) {
|
|||||||
Type: gitdiff.DiffLineSection,
|
Type: gitdiff.DiffLineSection,
|
||||||
Content: lineText,
|
Content: lineText,
|
||||||
SectionInfo: &gitdiff.DiffLineSectionInfo{
|
SectionInfo: &gitdiff.DiffLineSectionInfo{
|
||||||
Path: filePath,
|
Path: filePath,
|
||||||
LastLeftIdx: lastLeft,
|
LastLeftIdx: lastLeft,
|
||||||
LastRightIdx: lastRight,
|
LastRightIdx: lastRight,
|
||||||
LeftIdx: idxLeft,
|
LeftIdx: idxLeft,
|
||||||
RightIdx: idxRight,
|
RightIdx: idxRight,
|
||||||
LeftHunkSize: leftHunkSize,
|
LeftHunkSize: leftHunkSize,
|
||||||
RightHunkSize: rightHunkSize,
|
RightHunkSize: rightHunkSize,
|
||||||
HasComments: false,
|
HasComments: false,
|
||||||
LastRightCommentIdx: 0,
|
|
||||||
RightCommentIdx: 0,
|
|
||||||
},
|
},
|
||||||
Comments: nil,
|
Comments: nil,
|
||||||
}
|
}
|
||||||
@ -946,11 +944,11 @@ func ExcerptBlob(ctx *context.Context) {
|
|||||||
issueIndex := ctx.FormInt64("issue_index")
|
issueIndex := ctx.FormInt64("issue_index")
|
||||||
if ctx.FormBool("pull") && issueIndex > 0 {
|
if ctx.FormBool("pull") && issueIndex > 0 {
|
||||||
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, issueIndex)
|
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, issueIndex)
|
||||||
if issue == nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetIssueByIndex", err)
|
ctx.ServerError("GetIssueByIndex", err)
|
||||||
return
|
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 {
|
if err != nil {
|
||||||
ctx.ServerError("FetchCodeComments", err)
|
ctx.ServerError("FetchCodeComments", err)
|
||||||
return
|
return
|
||||||
|
@ -1520,10 +1520,6 @@ func registerRoutes(m *web.Router) {
|
|||||||
m.Get("/{sha}", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.ExcerptBlob)
|
m.Get("/{sha}", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.ExcerptBlob)
|
||||||
}, func(ctx *context.Context) gocontext.CancelFunc {
|
}, func(ctx *context.Context) gocontext.CancelFunc {
|
||||||
// FIXME: refactor this function, use separate routes for wiki/code
|
// FIXME: refactor this function, use separate routes for wiki/code
|
||||||
if ctx.FormBool("pull") {
|
|
||||||
ctx.Data["PageIsPullFiles"] = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if ctx.FormBool("wiki") {
|
if ctx.FormBool("wiki") {
|
||||||
ctx.Data["PageIsWiki"] = true
|
ctx.Data["PageIsWiki"] = true
|
||||||
repo.MustEnableWiki(ctx)
|
repo.MustEnableWiki(ctx)
|
||||||
|
@ -86,16 +86,14 @@ type DiffLine struct {
|
|||||||
|
|
||||||
// DiffLineSectionInfo represents diff line section meta data
|
// DiffLineSectionInfo represents diff line section meta data
|
||||||
type DiffLineSectionInfo struct {
|
type DiffLineSectionInfo struct {
|
||||||
Path string
|
Path string
|
||||||
LastLeftIdx int
|
LastLeftIdx int
|
||||||
LastRightIdx int
|
LastRightIdx int
|
||||||
LeftIdx int
|
LeftIdx int
|
||||||
RightIdx int
|
RightIdx int
|
||||||
LeftHunkSize int
|
LeftHunkSize int
|
||||||
RightHunkSize int
|
RightHunkSize int
|
||||||
HasComments bool
|
HasComments bool
|
||||||
LastRightCommentIdx int
|
|
||||||
RightCommentIdx int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// BlobExcerptChunkSize represent max lines of excerpt
|
// BlobExcerptChunkSize represent max lines of excerpt
|
||||||
@ -146,12 +144,10 @@ func (d *DiffLine) GetBlobExcerptQuery() string {
|
|||||||
"last_left=%d&last_right=%d&"+
|
"last_left=%d&last_right=%d&"+
|
||||||
"left=%d&right=%d&"+
|
"left=%d&right=%d&"+
|
||||||
"left_hunk_size=%d&right_hunk_size=%d&"+
|
"left_hunk_size=%d&right_hunk_size=%d&"+
|
||||||
"last_rightt_comment_idx=%d&right_comment_idx=%d&"+
|
|
||||||
"path=%s",
|
"path=%s",
|
||||||
d.SectionInfo.LastLeftIdx, d.SectionInfo.LastRightIdx,
|
d.SectionInfo.LastLeftIdx, d.SectionInfo.LastRightIdx,
|
||||||
d.SectionInfo.LeftIdx, d.SectionInfo.RightIdx,
|
d.SectionInfo.LeftIdx, d.SectionInfo.RightIdx,
|
||||||
d.SectionInfo.LeftHunkSize, d.SectionInfo.RightHunkSize,
|
d.SectionInfo.LeftHunkSize, d.SectionInfo.RightHunkSize,
|
||||||
d.SectionInfo.LastRightCommentIdx, d.SectionInfo.RightCommentIdx,
|
|
||||||
url.QueryEscape(d.SectionInfo.Path))
|
url.QueryEscape(d.SectionInfo.Path))
|
||||||
return query
|
return query
|
||||||
}
|
}
|
||||||
@ -175,16 +171,14 @@ func getDiffLineSectionInfo(treePath, line string, lastLeftIdx, lastRightIdx int
|
|||||||
leftLine, leftHunk, rightLine, righHunk := git.ParseDiffHunkString(line)
|
leftLine, leftHunk, rightLine, righHunk := git.ParseDiffHunkString(line)
|
||||||
|
|
||||||
return &DiffLineSectionInfo{
|
return &DiffLineSectionInfo{
|
||||||
Path: treePath,
|
Path: treePath,
|
||||||
LastLeftIdx: lastLeftIdx,
|
LastLeftIdx: lastLeftIdx,
|
||||||
LastRightIdx: lastRightIdx,
|
LastRightIdx: lastRightIdx,
|
||||||
LeftIdx: leftLine,
|
LeftIdx: leftLine,
|
||||||
RightIdx: rightLine,
|
RightIdx: rightLine,
|
||||||
LeftHunkSize: leftHunk,
|
LeftHunkSize: leftHunk,
|
||||||
RightHunkSize: righHunk,
|
RightHunkSize: righHunk,
|
||||||
HasComments: false,
|
HasComments: false,
|
||||||
LastRightCommentIdx: 0,
|
|
||||||
RightCommentIdx: 0,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -404,14 +398,12 @@ func (diffFile *DiffFile) GetTailSection(gitRepo *git.Repository, leftCommit, ri
|
|||||||
Type: DiffLineSection,
|
Type: DiffLineSection,
|
||||||
Content: " ",
|
Content: " ",
|
||||||
SectionInfo: &DiffLineSectionInfo{
|
SectionInfo: &DiffLineSectionInfo{
|
||||||
Path: diffFile.Name,
|
Path: diffFile.Name,
|
||||||
LastLeftIdx: lastLine.LeftIdx,
|
LastLeftIdx: lastLine.LeftIdx,
|
||||||
LastRightIdx: lastLine.RightIdx,
|
LastRightIdx: lastLine.RightIdx,
|
||||||
LeftIdx: leftLineCount,
|
LeftIdx: leftLineCount,
|
||||||
RightIdx: rightLineCount,
|
RightIdx: rightLineCount,
|
||||||
HasComments: false,
|
HasComments: false,
|
||||||
LastRightCommentIdx: 0,
|
|
||||||
RightCommentIdx: 0,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
tailSection := &DiffSection{FileName: diffFile.Name, Lines: []*DiffLine{tailDiffLine}}
|
tailSection := &DiffSection{FileName: diffFile.Name, Lines: []*DiffLine{tailDiffLine}}
|
||||||
@ -469,11 +461,9 @@ type Diff struct {
|
|||||||
NumViewedFiles int // user-specific
|
NumViewedFiles int // user-specific
|
||||||
}
|
}
|
||||||
|
|
||||||
// function (section *DiffSection) GetType() int {
|
|
||||||
|
|
||||||
// LoadComments loads comments into each line
|
// LoadComments loads comments into each line
|
||||||
func (diff *Diff) LoadComments(ctx context.Context, issue *issues_model.Issue, currentUser *user_model.User, showOutdatedComments bool) error {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -59,16 +59,14 @@ func TestGetDiffPreview(t *testing.T) {
|
|||||||
Content: "@@ -1,3 +1,4 @@",
|
Content: "@@ -1,3 +1,4 @@",
|
||||||
Comments: nil,
|
Comments: nil,
|
||||||
SectionInfo: &gitdiff.DiffLineSectionInfo{
|
SectionInfo: &gitdiff.DiffLineSectionInfo{
|
||||||
Path: "README.md",
|
Path: "README.md",
|
||||||
LastLeftIdx: 0,
|
LastLeftIdx: 0,
|
||||||
LastRightIdx: 0,
|
LastRightIdx: 0,
|
||||||
LeftIdx: 1,
|
LeftIdx: 1,
|
||||||
RightIdx: 1,
|
RightIdx: 1,
|
||||||
LeftHunkSize: 3,
|
LeftHunkSize: 3,
|
||||||
RightHunkSize: 4,
|
RightHunkSize: 4,
|
||||||
HasComments: false,
|
HasComments: false,
|
||||||
LastRightCommentIdx: 0,
|
|
||||||
RightCommentIdx: 0,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user