name: Make sure PRs target the develop branch

on:
  pull_request_target:

# By default, pull_request_target gets write permissions to the repo - this prevents that
permissions:
  pull-requests: write

jobs:
  check-branch:
    if: github.event.pull_request.base.ref == 'master'
    runs-on: ubuntu-latest
    steps:
      - name: Add comment
        uses: actions/github-script@v7
        with:
          script: |
            github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: 'Please do not submit against `master`, use `develop` instead'
            })
      - name: Throw error
        run: |
          echo "::error title=wrong-branch::Please do not submit against 'master', use 'develop' instead"
          exit 1
