Skip to content

Require merge commit for merge PR (+ new rules.yml file) #1510

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

Merged
merged 1 commit into from
May 2, 2025

Conversation

jar-stripe
Copy link
Contributor

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?

  • add rules.yml to define PR/branch rules that we cannot define in the Github UI
  • added Merge script PRs must create merge commits rule to run when auto merge is enabled and when the branch contains /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:
image

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

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

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

See Also

…t rule to prevent auto-squash on merge commits
@jar-stripe jar-stripe requested a review from a team as a code owner May 2, 2025 20:50
@jar-stripe jar-stripe requested review from mbroshi-stripe and removed request for a team May 2, 2025 20:50
@jar-stripe jar-stripe enabled auto-merge (squash) May 2, 2025 20:52
@jar-stripe jar-stripe merged commit 9283e81 into master May 2, 2025
15 checks passed
@jar-stripe jar-stripe deleted the jar/ci-rules-require-merge-commit branch May 2, 2025 20:58
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.

2 participants