name: Auto Reviewer

on:
  pull_request:
    types: [opened, labeled]

jobs:
  auto-reviewer:
    runs-on: ubuntu-latest
    if: contains(github.event.pull_request.labels.*.name, 'dependencies')
    permissions:
      pull-requests: write

    steps:
      - name: Add reviewers for Github Actions dependencies
        if: contains(github.event.pull_request.labels.*.name, 'github_actions')
        uses: actions/github-script@v8
        with:
          script: |
            await github.rest.pulls.requestReviewers({
              owner: context.repo.owner,
              repo: context.repo.repo,
              pull_number: context.issue.number,
              reviewers: ['fvacek', 'syyyr']
            });

      - name: Add reviewers for Rust dependencies
        if: contains(github.event.pull_request.labels.*.name, 'rust')
        uses: actions/github-script@v8
        with:
          script: |
            await github.rest.pulls.requestReviewers({
              owner: context.repo.owner,
              repo: context.repo.repo,
              pull_number: context.issue.number,
              reviewers: ['fvacek', 'j4r0u53k', 'syyyr']
            });

