Skip to content

Commit

Permalink
Load reviewer for comments when dismissing a review (go-gitea#24281)
Browse files Browse the repository at this point in the history
If a comment dismisses a review, we need to load the reviewer to show
whose review has been dismissed.

Related to:

https://github.com/go-gitea/gitea/blob/20b6ae0e5399cfc22c6a0989d8e520194e920bdd/templates/repo/issue/view_content/comments.tmpl#L765-L770

We don't need `.Review.Reviewer` for all comments, because
"dismissing" doesn't happen often, or we would have already received
error reports.
  • Loading branch information
wolfogre authored and GiteaBot committed Apr 23, 2023
1 parent 7297cce commit dc86aad
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions models/issues/comment_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (comments CommentList) getLabelIDs() []int64 {
return ids.Values()
}

func (comments CommentList) loadLabels(ctx context.Context) error { //nolint
func (comments CommentList) loadLabels(ctx context.Context) error {
if len(comments) == 0 {
return nil
}
Expand Down Expand Up @@ -415,7 +415,7 @@ func (comments CommentList) getReviewIDs() []int64 {
return ids.Values()
}

func (comments CommentList) loadReviews(ctx context.Context) error { //nolint
func (comments CommentList) loadReviews(ctx context.Context) error {
if len(comments) == 0 {
return nil
}
Expand Down Expand Up @@ -453,6 +453,14 @@ func (comments CommentList) loadReviews(ctx context.Context) error { //nolint

for _, comment := range comments {
comment.Review = reviews[comment.ReviewID]

// If the comment dismisses a review, we need to load the reviewer to show whose review has been dismissed.
// Otherwise, the reviewer is the poster of the comment, so we don't need to load it.
if comment.Type == CommentTypeDismissReview {
if err := comment.Review.LoadReviewer(ctx); err != nil {
return err
}
}
}
return nil
}
Expand Down

0 comments on commit dc86aad

Please sign in to comment.