name: "GitHub Pull Requests Labeler"

on:
  pull_request_target:
    types:
      - opened
      - reopened
      - ready_for_review
    branches:
      - 'main'
      - 'next'

jobs:
  add-label:
    runs-on: ubuntu-latest
    permissions:
      issues: write
      pull-requests: write
    steps:
      - name: Add waiting-for-review label
        uses: actions/github-script@v8
        with:
          script: |
            await github.rest.issues.addLabels({
              owner: context.repo.owner,
              repo: context.repo.repo,
              issue_number: context.payload.pull_request.number,
              labels: ['pr: waiting for review'],
            })
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
