diff --git a/models/issue_comment.go b/models/issue_comment.go index 3c9fa64bbe..ac52b80da5 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -839,12 +839,19 @@ func DeleteComment(comment *Comment) error { } func fetchCodeComments(e Engine, issue *Issue, currentUser *User) (map[string]map[int64][]*Comment, error) { - pathToLineToComment := make(map[string]map[int64][]*Comment) + return fetchCodeCommentsByReview(e, issue, currentUser, nil) +} +func fetchCodeCommentsByReview(e Engine, issue *Issue, currentUser *User, review *Review) (map[string]map[int64][]*Comment, error) { + pathToLineToComment := make(map[string]map[int64][]*Comment) + if review == nil { + review = &Review{ID: 0} + } //Find comments opts := FindCommentsOptions{ - Type: CommentTypeCode, - IssueID: issue.ID, + Type: CommentTypeCode, + IssueID: issue.ID, + ReviewID: review.ID, } var comments []*Comment if err := e.Where(opts.toConds().And(builder.Eq{"invalidated": false})). @@ -870,10 +877,12 @@ func fetchCodeComments(e Engine, issue *Issue, currentUser *User) (map[string]ma } for _, comment := range comments { if re, ok := reviews[comment.ReviewID]; ok && re != nil { - // If the review is pending only the author can see the comments - if re.Type == ReviewTypePending && - (currentUser == nil || currentUser.ID != re.ReviewerID) { - continue + // If the review is pending only the author can see the comments (except the review is set) + if review.ID == 0 { + if re.Type == ReviewTypePending && + (currentUser == nil || currentUser.ID != re.ReviewerID) { + continue + } } comment.Review = re } diff --git a/models/review.go b/models/review.go index e5d4527ea3..c02f7a5ba9 100644 --- a/models/review.go +++ b/models/review.go @@ -56,11 +56,11 @@ type Review struct { UpdatedUnix util.TimeStamp `xorm:"INDEX updated"` // CodeComments are the initial code comments of the review - CodeComments []*Comment `xorm:"-"` + CodeComments map[string]map[int64][]*Comment `xorm:"-"` } func (r *Review) loadCodeComments(e Engine) (err error) { - r.CodeComments, err = findComments(e, FindCommentsOptions{IssueID: r.IssueID, ReviewID: r.ID, Type: CommentTypeCode}) + r.CodeComments, err = fetchCodeCommentsByReview(e, r.Issue, nil, r) return } @@ -75,6 +75,9 @@ func (r *Review) loadIssue(e Engine) (err error) { } func (r *Review) loadReviewer(e Engine) (err error) { + if r.ReviewerID == 0 { + return nil + } r.Reviewer, err = getUserByID(e, r.ReviewerID) return } diff --git a/models/review_test.go b/models/review_test.go index 8a968b324c..3c0444e7a3 100644 --- a/models/review_test.go +++ b/models/review_test.go @@ -37,9 +37,10 @@ func TestReview_LoadCodeComments(t *testing.T) { assert.NoError(t, PrepareTestDatabase()) review := AssertExistsAndLoadBean(t, &Review{ID: 4}).(*Review) + assert.NoError(t, review.LoadAttributes()) assert.NoError(t, review.LoadCodeComments()) assert.Len(t, review.CodeComments, 1) - assert.Equal(t, int64(4), review.CodeComments[0].Line) + assert.Equal(t, int64(4), review.CodeComments["README.md"][int64(4)][0].Line) } func TestReviewType_Icon(t *testing.T) { diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 5a276f3fea..c18f0bb352 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -726,6 +726,17 @@ func ViewIssue(ctx *context.Context) { ctx.ServerError("LoadReview", err) return } + if comment.Review == nil { + continue + } + if err = comment.Review.LoadAttributes(); err != nil { + ctx.ServerError("Review.LoadAttributes", err) + return + } + if err = comment.Review.LoadCodeComments(); err != nil { + ctx.ServerError("Review.LoadCodeComments", err) + return + } } } diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index 53ce411e1c..114a4948c2 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -256,6 +256,168 @@ {{.Content}} {{end}} + {{ range $filename, $lines := .Review.CodeComments}} + {{range $line, $comms := $lines}} +
+
+ {{if (index $comms 0).Invalidated}} + + {{end}} + {{$filename}} +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
@@ -27,5 +27,5 @@
+
+ 27 + + 27 + + + +
 			"revisionTime": "2016-08-23T15:25:51Z"
+
+ 28 + + 28 + + + +
 		}
+
+ 29 + + 29 + + + +
 	],
+
+ 30 + + + + + +
-	"rootPath": "github.com/JonasFranzDEV/drone-gitea-release"
+
+ + + 30 + + + +
+	"rootPath": "localhost:3000/JonasFranzDEV/drone-gitea-release"
+
+ 31 + + 31 + + + +
 }
+
+
+
+
+
+
+ {{range $comms}} + {{ $createdSubStr:= TimeSinceUnix .CreatedUnix $.Lang }} +
+ + + +
+ {{.Poster.Name}} + +
+
+ {{if .RenderedContent}} + {{.RenderedContent|Str2html}} + {{else}} + {{$.i18n.Tr "repo.issues.no_content"}} + {{end}} +
+
{{.Content}}
+
+
+
+ {{end}} +
+
+
+ {{end}} + {{end}} {{end}} {{end}}