name: Claude Code Review

on:
  pull_request:
    types: [opened, synchronize, ready_for_review]

jobs:
  claude-review:
    # Skip review on draft PRs unless a review is explicitly requested
    if: |
      github.event.pull_request.draft == false ||
      github.event_name == 'pull_request_review'

    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: read
      issues: read
      id-token: write

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 1

      - name: Run Claude Code Review
        id: claude-review
        uses: anthropics/claude-code-action@v1
        with:
          anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}

          # Optional: Specify model (defaults to Claude Sonnet 4, uncomment for Claude Opus 4)
          # claude_args: --model "claude-opus-4-20250514"

          prompt: |
            Please review this pull request and provide feedback on:

            PR Format:
            - Verify the PR title and description follow the requirements in .github/pull_request_template.md

            Code Review:
            - Code quality and best practices
            - Potential bugs or issues
            - Performance considerations
            - Security concerns
            - Test coverage

            Use the repository skill docs for guidance. Start with:
            - `.claude/skills/code_review/SKILL.md` (review process and repo-specific expectations)
            - `.claude/skills/skills/SKILL.md` (how skills are structured; follow relevant skills for the touched areas)

            Be constructive and helpful in your feedback.

            Use `gh pr comment --edit-last --create-if-none` with your Bash tool so the review stays in a single updated comment on the PR.

          # Optional: Use sticky comments to make Claude reuse the same comment on subsequent pushes to the same PR
          use_sticky_comment: true

          track_progress: true

          claude_args: |
            --allowed-tools "mcp__github_inline_comment__create_inline_comment,Bash(gh issue view:*),Bash(gh search:*),Bash(gh issue list:*),Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(gh pr list:*),Bash(pre-commit run --all-files),Bash(uv run pytest*)"
