Skip to content

Commit

Permalink
fix dismiss review
Browse files Browse the repository at this point in the history
  • Loading branch information
lng2020 committed Nov 4, 2023
1 parent a5bdcfc commit edd2b66
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
10 changes: 10 additions & 0 deletions models/issues/review.go
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,16 @@ func DeleteReview(ctx context.Context, r *Review) error {
return err
}

opts = FindCommentsOptions{
Type: CommentTypeDismissReview,
IssueID: r.IssueID,
ReviewID: r.ID,
}

if _, err := sess.Where(opts.ToConds()).Delete(new(Comment)); err != nil {
return err
}

if _, err := sess.ID(r.ID).Delete(new(Review)); err != nil {
return err
}
Expand Down
30 changes: 30 additions & 0 deletions models/issues/review_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"code.gitea.io/gitea/models/db"
issues_model "code.gitea.io/gitea/models/issues"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"

Expand Down Expand Up @@ -258,3 +259,32 @@ func TestDeleteReview(t *testing.T) {
assert.NoError(t, err)
assert.True(t, review1.Official)
}

func TestDeleteDismissedReview(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())

ctx := db.DefaultContext
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2})
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID})
review, err := issues_model.CreateReview(ctx, issues_model.CreateReviewOptions{
Content: "reject",
Type: issues_model.ReviewTypeReject,
Official: false,
Issue: issue,
Reviewer: user,
})
assert.NoError(t, err)
assert.NoError(t, issues_model.DismissReview(ctx, review, true))
comment, err := issues_model.CreateComment(ctx, &issues_model.CreateCommentOptions{

Check failure on line 279 in models/issues/review_test.go

View workflow job for this annotation

GitHub Actions / lint-backend

ineffectual assignment to err (ineffassign)

Check failure on line 279 in models/issues/review_test.go

View workflow job for this annotation

GitHub Actions / lint-go-gogit

ineffectual assignment to err (ineffassign)

Check failure on line 279 in models/issues/review_test.go

View workflow job for this annotation

GitHub Actions / lint-go-windows

ineffectual assignment to err (ineffassign)
Type: issues_model.CommentTypeDismissReview,
Doer: user,
Repo: repo,
Issue: issue,
ReviewID: review.ID,
Content: "dismiss",
})
unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: comment.ID})
assert.NoError(t, issues_model.DeleteReview(ctx, review))
unittest.AssertNotExistsBean(t, &issues_model.Comment{ID: comment.ID})
}

0 comments on commit edd2b66

Please sign in to comment.