diff options
author | 6543 <6543@obermui.de> | 2022-07-19 15:20:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-19 15:20:28 +0200 |
commit | c0f5111fea0b742a60113e1bda81bf39607d6ca8 (patch) | |
tree | 78d8414ef40d6c4a2ddedfa7f71d10cee100feba /models/issues/review.go | |
parent | e519249266cb69065b65f59477afa36f240b28cf (diff) | |
download | gitea-c0f5111fea0b742a60113e1bda81bf39607d6ca8.tar.gz gitea-c0f5111fea0b742a60113e1bda81bf39607d6ca8.zip |
Dismiss prior pull reviews if done via web in review dismiss (#20197)
Diffstat (limited to 'models/issues/review.go')
-rw-r--r-- | models/issues/review.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/models/issues/review.go b/models/issues/review.go index 1cb99dc337..5835900801 100644 --- a/models/issues/review.go +++ b/models/issues/review.go @@ -19,6 +19,7 @@ import ( "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/timeutil" + "code.gitea.io/gitea/modules/util" "xorm.io/builder" ) @@ -474,6 +475,35 @@ func SubmitReview(doer *user_model.User, issue *Issue, reviewType ReviewType, co return review, comm, committer.Commit() } +// GetReviewOptions represent filter options for GetReviews +type GetReviewOptions struct { + IssueID int64 + ReviewerID int64 + Dismissed util.OptionalBool +} + +// GetReviews return reviews based on GetReviewOptions +func GetReviews(ctx context.Context, opts *GetReviewOptions) ([]*Review, error) { + if opts == nil { + return nil, fmt.Errorf("opts are nil") + } + + sess := db.GetEngine(ctx) + + if opts.IssueID != 0 { + sess = sess.Where("issue_id=?", opts.IssueID) + } + if opts.ReviewerID != 0 { + sess = sess.Where("reviewer_id=?", opts.ReviewerID) + } + if !opts.Dismissed.IsNone() { + sess = sess.Where("dismissed=?", opts.Dismissed.IsTrue()) + } + + reviews := make([]*Review, 0, 4) + return reviews, sess.Find(&reviews) +} + // GetReviewersByIssueID gets the latest review of each reviewer for a pull request func GetReviewersByIssueID(issueID int64) ([]*Review, error) { reviews := make([]*Review, 0, 10) |