From 7418dec7ec2ca2145c3ff9beed8a13caf24ec6c2 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Fri, 24 Apr 2026 18:29:19 -0700 Subject: [PATCH] Comment on PRs that target the wrong branch --- .github/workflows/wrong_base_branch.yml | 31 +++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .github/workflows/wrong_base_branch.yml diff --git a/.github/workflows/wrong_base_branch.yml b/.github/workflows/wrong_base_branch.yml new file mode 100644 index 000000000..7745aa0f6 --- /dev/null +++ b/.github/workflows/wrong_base_branch.yml @@ -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 }}