Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicate Reviewed-by trailers #24796

Merged

Conversation

corytodd
Copy link
Contributor

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

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label May 18, 2023
@pull-request-size pull-request-size bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label May 18, 2023
models/issues/review.go Outdated Show resolved Hide resolved
@corytodd corytodd marked this pull request as draft May 19, 2023 15:22
@silverwind
Copy link
Member

A test would be nice here.

@pull-request-size pull-request-size bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels May 22, 2023
@corytodd corytodd force-pushed the corytodd/fix-duplicated-approvers branch from 05bac74 to 3ea36d0 Compare May 22, 2023 21:40
@silverwind
Copy link
Member

Is it ready?

@corytodd corytodd marked this pull request as ready for review May 31, 2023 00:25
@corytodd
Copy link
Contributor Author

Yes, was waiting for the tests to pass before I removed the draft state thanks for the reminder!

@corytodd corytodd force-pushed the corytodd/fix-duplicated-approvers branch from 3ea36d0 to c8e8fea Compare June 3, 2023 17:35
@corytodd
Copy link
Contributor Author

corytodd commented Jun 3, 2023

The merge conflict has been resolved so this is ready again.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jun 5, 2023
@lunny lunny added the type/enhancement An improvement of existing functionality label Jun 5, 2023
Comment on lines 274 to 279
sess.In("id", builder.
Select("max ( id ) ").
From("review").
GroupBy("reviewer_id"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No more "where" condition for this query?

For a instance with 100,000 reviews, this "IN" query will group these 100,000 reviews for each FindReviews call?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue_id condition is necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I wasn't sure about this one since IssueID will not always be provided. I think re-using the outer condition on where on the subquery should be okay?

Cory Todd added 3 commits June 8, 2023 11:46
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.

fixes go-gitea#24795 

Signed-off-by: Cory Todd <cory.todd@canonical.com>
Not all SQL dialects will work with Distinct so use a subquery grouping
instead. Add 3 reviews to the test data to simulate the scenario being
fixed by this patch.

- One reviewer submitting 2 reviews. Only the latest should be returned.
- One reviewer submitting 1 review. This is the oldest review and should
  still be the first approver.

Omitting LatestOnly should preserve existing behavior as it is used by
the REST API.

Signed-off-by: Cory Todd <cory.todd@canonical.com>
On the LatestOnly subquery, re-use the outter condition to avoid always
grouping by all reviews in the database.

Signed-off-by: Cory Todd <cory.todd@canonical.com>
@corytodd corytodd force-pushed the corytodd/fix-duplicated-approvers branch from 97fff06 to bdba85b Compare June 8, 2023 18:54
@corytodd
Copy link
Contributor Author

corytodd commented Jun 8, 2023

Fixed more conflicts.

@@ -243,6 +243,7 @@ type FindReviewOptions struct {
IssueID int64
ReviewerID int64
OfficialOnly bool
LatestOnly bool // Latest per-reviewer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After reading the code again, I think it's better to add a FindLatestReviews , instead of adding LatestOnly to FindReviewOptions.

The reason is, the newly added LatestOnly is not respected by toCond, but FindReviewOptions is shared by FindReviewOptions and CountReviewOptions. So, if LatestOnly=true, FindReviewOptions and CountReviewOptions behave differently, it would cause bugs or confuse developers in the future.


If we introduce a FindLatestReviews, then everything is clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a very good point, thanks for the feedback. I've made the requested revisions.

Do not create future sources for bugs by introducing the LatestOnly
field. Use an explicit function instead.

Signed-off-by: Cory Todd <cory.todd@canonical.com>
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jun 9, 2023
@silverwind silverwind added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Jun 9, 2023
@silverwind silverwind merged commit 1797046 into go-gitea:main Jun 9, 2023
@GiteaBot GiteaBot added this to the 1.21.0 milestone Jun 9, 2023
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Jun 9, 2023
@corytodd corytodd deleted the corytodd/fix-duplicated-approvers branch June 9, 2023 14:42
@silverwind
Copy link
Member

Should we backport this?

zjjhot added a commit to zjjhot/gitea that referenced this pull request Jun 12, 2023
* upstream/main:
  [skip ci] Updated licenses and gitignores
  Add `WithPullRequest` for `actionsNotifier` (go-gitea#25144)
  [skip ci] Updated translations via Crowdin
  [skip ci] Updated translations via Crowdin
  Update github.com/google/go-github to v53 (go-gitea#25157)
  Fix bug for code search if code is disabled (go-gitea#25173)
  Minor arc-green color tweaks (go-gitea#25175)
  Fix duplicate Reviewed-by trailers (go-gitea#24796)
  Fix go-gitea#25133 (go-gitea#25162)
  Fix mobile navbar and misc cleanups (go-gitea#25134)
  Button and color enhancements (go-gitea#24989)
  Fix setup-go actions (go-gitea#25167)

# Conflicts:
#	templates/base/head_navbar.tmpl
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Sep 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Duplicate Reviewed-by lines in default merge message
5 participants