1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 10:18:38 +00:00

Add support for showing code comments of reviews in conversation

Signed-off-by: Jonas Franz <info@jonasfranz.software>
This commit is contained in:
Jonas Franz
2018-05-15 12:52:28 +02:00
parent 6ae32b27e3
commit 4ea74e5327
5 changed files with 196 additions and 10 deletions

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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) {