name: BugBot Trigger

on:
  pull_request_target:
    types: [opened, synchronize, ready_for_review, reopened]

# Restrict default permissions; each job declares only what it needs.
permissions: {}

jobs:
  trigger-bugbot:
    environment: ai-bots
    # Only review code from regular contributors since bug bot has a capped # of PR reviews.
    if: >-
      contains(
        fromJSON('["wwwillchen","keppo-bot","keppo-bot[bot]","dyad-assistant","azizmejri1","princeaden1","nourzakhama2003","ryangroch"]'),
        github.event.pull_request.user.login
      ) &&
      !contains(github.event.pull_request.body, '#skip-bugbot') &&
      !contains(github.event.pull_request.body, '#skip-bb')
    runs-on: ubuntu-latest
    permissions:
      pull-requests: write
    steps:
      - name: Comment @BugBot run
        uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5
        with:
          # Use a PAT from wwwillchen to post on their behalf
          token: ${{ secrets.WWWILLCHEN_PR_RW_PAT }}
          issue-number: ${{ github.event.pull_request.number }}
          body: "@BugBot run"
