Skip to content

Conversation

@enthropy7
Copy link
Contributor

added new func + test

fixes #452

Prevents r+ command from approving PRs with merge conflicts by adding conflict checks in check_pr_approval_validity(). The implementation uses MergeableState::from() to convert GitHub mergeable state and checks both GitHub and database states to catch conflicts even when GitHub state hasn't been refreshed yet. Returns approve_merge_conflict_comment() error message instead of approving the PR.

added tests for all conflict scenarios: dirty, blocked, unknown state with DB conflicts, and clean state with DB conflicts.

Prevent PR approval when merge conflicts are detected in the database, even if GitHub returns Unknown or Clean/Mergeable state. This ensures that merge conflict information is preserved and blocks approval appropriately.

Changes:
- Add check in check_pr_approval_validity to block approval when DB has HasConflicts
- Preserve HasConflicts state in set_pr_mergeability_based_on_user_action when GitHub returns Unknown or Clean/Mergeable
- Reload PR from DB after mergeability update to ensure latest state is used
- Add tests for merge conflict blocking scenarios
Copy link
Member

@Kobzol Kobzol left a comment

Choose a reason for hiding this comment

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

Thank you, looks great! Mergeability checking is very tricky, and I just finished a big reworking of it, so some of the invariants might not be documented properly yet, but this PR shouldn't need to change how it works - it should be enough to simply block approvals if the PR is currently unmergeable on GitHub.

- Block approval only based on GitHub mergeable state (HasConflicts), do not use DB mergeability for approval checks.
- Restore original behavior of set_pr_mergeability_based_on_user_action and avoid extra DB reload in handle_comment.
- Update tests so DB-only conflict scenarios expect approval, matching the desired invariants.
Copy link
Member

@Kobzol Kobzol left a comment

Choose a reason for hiding this comment

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

Yeah I think that you did a bit too much there! 😅 I think that the approve_pr_with_merge_conflict_dirty test is enough, otherwise LGTM.

Keep only approve_pr_with_merge_conflict_dirty test as requested by reviewer. Remove tests that modify DB directly (approve_pr_with_merge_conflict_blocked, approve_pr_with_merge_conflict_in_db, approve_pr_with_merge_conflict_clean_but_db_has_conflicts) to avoid 'cheating' and maintain end-to-end test approach.
Copy link
Member

@Kobzol Kobzol left a comment

Choose a reason for hiding this comment

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

Thank you! :)

@Kobzol Kobzol added this pull request to the merge queue Jan 14, 2026
Merged via the queue into rust-lang:main with commit c2ed614 Jan 14, 2026
2 checks passed
@enthropy7
Copy link
Contributor Author

no problem! it was nice to work together! ping me if there's some difficulty that i could help. of course i will discover some issues by myself, tho i'm near my pc all the time :3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Do not allow approving PRs with a merge conflict

2 participants