name: 'CI: Owners Review Recommendations'

# Posts (or updates) a PR comment recommending which @n8n-io teams should
# review the PR, based on file ownership defined in .github/OWNERS.
#
# Advisory only — does not gate merging.

on:
  pull_request:
    types:
      - opened
      - synchronize
      - reopened
    branches:
      - master

jobs:
  recommend-reviewers:
    name: Recommend reviewers
    # Skipped for:
    #  - PRs from forks (no token to comment with)
    #  - Bot-authored PRs (Dependabot, Renovate, etc. — noise, not useful)
    if: |
      github.event.pull_request.head.repo.full_name == github.repository &&
      github.event.pull_request.user.type != 'Bot'
    runs-on: ubuntu-latest
    timeout-minutes: 5
    permissions:
      contents: read
      pull-requests: write
    steps:
      - name: Generate App Token
        id: app-token
        uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1
        with:
          app-id: ${{ secrets.N8N_ASSISTANT_APP_ID }}
          private-key: ${{ secrets.N8N_ASSISTANT_PRIVATE_KEY }}

      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

      - name: Setup Node.js
        uses: ./.github/actions/setup-nodejs
        with:
          build-command: ''
          install-command: pnpm install --frozen-lockfile --dir ./.github/scripts --ignore-workspace

      - name: Post review recommendations
        env:
          GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
          PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }}
        run: node .github/scripts/owners-review-recommendations.mjs
