@@ -9,46 +9,52 @@ import (
99
1010 "code.gitea.io/gitea/models/db"
1111 "code.gitea.io/gitea/models/renderhelper"
12+ repo_model "code.gitea.io/gitea/models/repo"
1213 user_model "code.gitea.io/gitea/models/user"
1314 "code.gitea.io/gitea/modules/markup/markdown"
1415
1516 "xorm.io/builder"
1617)
1718
1819// CodeComments represents comments on code by using this structure: FILENAME -> LINE (+ == proposed; - == previous) -> COMMENTS
19- type CodeComments map [string ]map [int64 ][]* Comment
20+ type CodeComments map [string ][]* Comment
21+
22+ func (cc CodeComments ) AllComments () []* Comment {
23+ var allComments []* Comment
24+ for _ , comments := range cc {
25+ allComments = append (allComments , comments ... )
26+ }
27+ return allComments
28+ }
2029
2130// FetchCodeComments will return a 2d-map: ["Path"]["Line"] = Comments at line
22- func FetchCodeComments (ctx context.Context , issue * Issue , currentUser * user_model.User , showOutdatedComments bool ) (CodeComments , error ) {
23- return fetchCodeCommentsByReview (ctx , issue , currentUser , nil , showOutdatedComments )
31+ func FetchCodeComments (ctx context.Context , repo * repo_model. Repository , issueID int64 , currentUser * user_model.User , showOutdatedComments bool ) (CodeComments , error ) {
32+ return fetchCodeCommentsByReview (ctx , repo , issueID , currentUser , nil , showOutdatedComments )
2433}
2534
26- func fetchCodeCommentsByReview (ctx context.Context , issue * Issue , currentUser * user_model.User , review * Review , showOutdatedComments bool ) (CodeComments , error ) {
27- pathToLineToComment := make (CodeComments )
35+ func fetchCodeCommentsByReview (ctx context.Context , repo * repo_model. Repository , issueID int64 , currentUser * user_model.User , review * Review , showOutdatedComments bool ) (CodeComments , error ) {
36+ codeCommentsPathMap := make (CodeComments )
2837 if review == nil {
2938 review = & Review {ID : 0 }
3039 }
3140 opts := FindCommentsOptions {
3241 Type : CommentTypeCode ,
33- IssueID : issue . ID ,
42+ IssueID : issueID ,
3443 ReviewID : review .ID ,
3544 }
3645
37- comments , err := findCodeComments (ctx , opts , issue , currentUser , review , showOutdatedComments )
46+ comments , err := FindCodeComments (ctx , opts , repo , currentUser , review , showOutdatedComments )
3847 if err != nil {
3948 return nil , err
4049 }
4150
4251 for _ , comment := range comments {
43- if pathToLineToComment [comment .TreePath ] == nil {
44- pathToLineToComment [comment .TreePath ] = make (map [int64 ][]* Comment )
45- }
46- pathToLineToComment [comment.TreePath ][comment.Line ] = append (pathToLineToComment [comment.TreePath ][comment.Line ], comment )
52+ codeCommentsPathMap [comment .TreePath ] = append (codeCommentsPathMap [comment .TreePath ], comment )
4753 }
48- return pathToLineToComment , nil
54+ return codeCommentsPathMap , nil
4955}
5056
51- func findCodeComments (ctx context.Context , opts FindCommentsOptions , issue * Issue , currentUser * user_model.User , review * Review , showOutdatedComments bool ) ([]* Comment , error ) {
57+ func FindCodeComments (ctx context.Context , opts FindCommentsOptions , repo * repo_model. Repository , currentUser * user_model.User , review * Review , showOutdatedComments bool ) ([]* Comment , error ) {
5258 var comments CommentList
5359 if review == nil {
5460 review = & Review {ID : 0 }
@@ -67,10 +73,6 @@ func findCodeComments(ctx context.Context, opts FindCommentsOptions, issue *Issu
6773 return nil , err
6874 }
6975
70- if err := issue .LoadRepo (ctx ); err != nil {
71- return nil , err
72- }
73-
7476 if err := comments .LoadPosters (ctx ); err != nil {
7577 return nil , err
7678 }
@@ -110,12 +112,12 @@ func findCodeComments(ctx context.Context, opts FindCommentsOptions, issue *Issu
110112 return nil , err
111113 }
112114
113- if err := comment .LoadReactions (ctx , issue . Repo ); err != nil {
115+ if err := comment .LoadReactions (ctx , repo ); err != nil {
114116 return nil , err
115117 }
116118
117119 var err error
118- rctx := renderhelper .NewRenderContextRepoComment (ctx , issue . Repo , renderhelper.RepoCommentOptions {
120+ rctx := renderhelper .NewRenderContextRepoComment (ctx , repo , renderhelper.RepoCommentOptions {
119121 FootnoteContextID : strconv .FormatInt (comment .ID , 10 ),
120122 })
121123 if comment .RenderedContent , err = markdown .RenderString (rctx , comment .Content ); err != nil {
@@ -124,14 +126,3 @@ func findCodeComments(ctx context.Context, opts FindCommentsOptions, issue *Issu
124126 }
125127 return comments [:n ], nil
126128}
127-
128- // FetchCodeCommentsByLine fetches the code comments for a given treePath and line number
129- func FetchCodeCommentsByLine (ctx context.Context , issue * Issue , currentUser * user_model.User , treePath string , line int64 , showOutdatedComments bool ) (CommentList , error ) {
130- opts := FindCommentsOptions {
131- Type : CommentTypeCode ,
132- IssueID : issue .ID ,
133- TreePath : treePath ,
134- Line : line ,
135- }
136- return findCodeComments (ctx , opts , issue , currentUser , nil , showOutdatedComments )
137- }
0 commit comments