name: Warn PR targets main

on:
  pull_request_target:
    types: [opened, edited]
    branches:
      - main

jobs:
  warn:
    if: ${{ !github.event.repository.fork }}
    runs-on: ubuntu-latest

    permissions:
      pull-requests: write

    steps:
      - name: Comment on PR
        uses: actions/github-script@v7
        with:
          script: |
            await github.rest.issues.createComment({
              owner: context.repo.owner,
              repo: context.repo.repo,
              issue_number: context.payload.pull_request.number,
              body: '⚠️ This PR targets the `main` branch. We do not accept PRs directly to `main` — please retarget your PR to the `dev` branch instead.'
            });
