diff options
author | Cory Todd <2796559+corytodd@users.noreply.github.com> | 2023-06-09 07:34:49 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-09 16:34:49 +0200 |
commit | 179704695c2c50b3577a25f16d7344eadb3b2da3 (patch) | |
tree | 550fcc195369f2b958dc8ba275339523f27be0d0 /models/issues/review.go | |
parent | 81211db077af0465848693b85f36894b5c17c427 (diff) | |
download | gitea-179704695c2c50b3577a25f16d7344eadb3b2da3.tar.gz gitea-179704695c2c50b3577a25f16d7344eadb3b2da3.zip |
Fix duplicate Reviewed-by trailers (#24796)
Enable deduplication of unofficial reviews. When pull requests are
configured to include all approvers, not just official ones, in the
default merge messages it was possible to generate duplicated
Reviewed-by lines for a single person. Add an option to find only
distinct reviews for a given query.
fixes #24795
---------
Signed-off-by: Cory Todd <cory.todd@canonical.com>
Co-authored-by: Giteabot <teabot@gitea.io>
Diffstat (limited to 'models/issues/review.go')
-rw-r--r-- | models/issues/review.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/models/issues/review.go b/models/issues/review.go index 06cf132a48..3a1ab7468a 100644 --- a/models/issues/review.go +++ b/models/issues/review.go @@ -275,6 +275,27 @@ func FindReviews(ctx context.Context, opts FindReviewOptions) ([]*Review, error) Find(&reviews) } +// FindLatestReviews returns only latest reviews per user, passing FindReviewOptions +func FindLatestReviews(ctx context.Context, opts FindReviewOptions) ([]*Review, error) { + reviews := make([]*Review, 0, 10) + cond := opts.toCond() + sess := db.GetEngine(ctx).Where(cond) + if opts.Page > 0 { + sess = db.SetSessionPagination(sess, &opts) + } + + sess.In("id", builder. + Select("max ( id ) "). + From("review"). + Where(cond). + GroupBy("reviewer_id")) + + return reviews, sess. + Asc("created_unix"). + Asc("id"). + Find(&reviews) +} + // CountReviews returns count of reviews passing FindReviewOptions func CountReviews(opts FindReviewOptions) (int64, error) { return db.GetEngine(db.DefaultContext).Where(opts.toCond()).Count(&Review{}) |