Comment on PRs that target the wrong branch

This commit is contained in:
Mark McDowall 2026-04-24 18:29:19 -07:00
parent eb97bb563b
commit 7418dec7ec
No known key found for this signature in database

31
.github/workflows/wrong_base_branch.yml vendored Normal file
View file

@ -0,0 +1,31 @@
name: Wrong Base Branch
on:
pull_request_target:
types:
- opened
jobs:
comment:
name: Comment on PRs targeting non-default branch
runs-on: ubuntu-latest
if: >-
github.event.pull_request.base.ref != github.event.repository.default_branch &&
!contains(fromJSON('["OWNER", "MEMBER"]'), github.event.pull_request.author_association)
permissions:
pull-requests: write
steps:
- name: Add comment
run: |
gh pr comment ${{ github.event.pull_request.number }} --body ":wave: @${{ github.event.pull_request.user.login }}, thanks for your contribution!
This PR targets \`${{ github.event.pull_request.base.ref }}\`, but all features and bug fixes must target the default branch (\`${{ github.event.repository.default_branch }}\`).
Please:
1. Rebase your changes onto \`${{ github.event.repository.default_branch }}\` (for example: \`git rebase --onto origin/${{ github.event.repository.default_branch }} ${{ github.event.pull_request.base.ref }}\`).
2. Update this PR to target \`${{ github.event.repository.default_branch }}\` using the *Edit* button next to the PR title.
**Please do not close this PR and open a new one** — you can change the base branch on the existing PR directly."
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}