Require merge commit for merge PR (+ new rules.yml file) #1510
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why?
Our merge script requires that PRs be merged with a merge commit to maintain git history and avoid conflicts in the future. Our normal PR process is to squash before merging, usually with auto-merge enabled. Since Github defaults to the last merge method selected, its very easy to accidentally enable auto-squash in this one situation where we really need a merge commit.
Neither Github's branch rulesets nor branch protection rules let us define rules in the context of the HEAD ref, so this PR adds a CI that can.
What?
/merge-
, and check that the auto merge method is 'merge'Demo
When auto-merge is enabled on a merge PR like stripe/stripe-dotnet#3106, it runs the rule as part of its checks. If the auto-merge method is not 'merge', it fails:

The error provides a brief description about why it failed as a reminder to go fix the auto-merge method:

Once fixed, the merge PR check is green, and everything's good to go:

Note that this must exist in the repo and enabled as a blocking status check to get the full benefit!
See Also