]> source.dussan.org Git - gitea.git/commitdiff
Dont load Review if Comment is CommentTypeReviewRequest (#28551) (#29160)
author6543 <6543@obermui.de>
Tue, 13 Feb 2024 22:29:33 +0000 (23:29 +0100)
committerGitHub <noreply@github.com>
Tue, 13 Feb 2024 22:29:33 +0000 (23:29 +0100)
Backport #28551

RequestReview get deleted on review.
So we don't have to try to load them on comments.

models/issues/comment.go
models/issues/comment_list.go
models/issues/review.go

index f038d75eb332313a73307ea399def8d4e71557ed..8ee4e9acd6fb34e99e90d65444f645aa37410cd3 100644 (file)
@@ -688,8 +688,15 @@ func (c *Comment) LoadReactions(ctx context.Context, repo *repo_model.Repository
 }
 
 func (c *Comment) loadReview(ctx context.Context) (err error) {
+       if c.ReviewID == 0 {
+               return nil
+       }
        if c.Review == nil {
                if c.Review, err = GetReviewByID(ctx, c.ReviewID); err != nil {
+                       // review request which has been replaced by actual reviews doesn't exist in database anymore, so ignorem them.
+                       if c.Type == CommentTypeReviewRequest {
+                               return nil
+                       }
                        return err
                }
        }
index 93af45870ed6976da6b437743ad3db6c66cd6bb7..cb7df3270d6ada1af1bd84a23c17ff22787a5eca 100644 (file)
@@ -430,7 +430,8 @@ func (comments CommentList) loadReviews(ctx context.Context) error {
        for _, comment := range comments {
                comment.Review = reviews[comment.ReviewID]
                if comment.Review == nil {
-                       if comment.ReviewID > 0 {
+                       // review request which has been replaced by actual reviews doesn't exist in database anymore, so don't log errors for them.
+                       if comment.ReviewID > 0 && comment.Type != CommentTypeReviewRequest {
                                log.Error("comment with review id [%d] but has no review record", comment.ReviewID)
                        }
                        continue
index eae8c20e97a71e63dbbce8cfe09dc74132e3684e..5bfb8b9dd224204012977dc64b5514cbb06e6ed4 100644 (file)
@@ -622,6 +622,9 @@ func AddReviewRequest(ctx context.Context, issue *Issue, reviewer, doer *user_mo
                return nil, err
        }
 
+       // func caller use the created comment to retrieve created review too.
+       comment.Review = review
+
        return comment, committer.Commit()
 }