Repository navigation
feat: add scope-based tool discovery #578
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Code Review | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, ready_for_review] | |
| paths: | |
| - "**/*.rs" | |
| workflow_dispatch: | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.event.pull_request.number }} | |
| cancel-in-progress: true | |
| jobs: | |
| review: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| id-token: write | |
| pull-requests: write | |
| contents: read | |
| if: ${{ !contains(github.event.pull_request.labels.*.name, 'skip-ai-review') && !github.event.pull_request.draft && github.event.pull_request.head.ref != 'release' && !startsWith(github.event.pull_request.head.ref, 'release/') }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v7 | |
| with: | |
| ref: ${{ github.event.pull_request.head.ref }} # We need a proper checkout for the commands the skill runs | |
| repository: ${{ github.event.pull_request.head.repo.full_name }} # To properly handle forks | |
| fetch-depth: 0 # Fetch full history for proper git operations | |
| - name: Determine model to use | |
| id: model_selection | |
| run: | | |
| # Check if user has manually specified a model via label | |
| HAS_OPUS_LABEL="${{ contains(github.event.pull_request.labels.*.name, 'ai-review-model-opus') }}" | |
| HAS_SONNET_LABEL="${{ contains(github.event.pull_request.labels.*.name, 'ai-review-model-sonnet') }}" | |
| # If manual label is present, always use that | |
| if [ "$HAS_OPUS_LABEL" == "true" ]; then | |
| MODEL="opus" | |
| echo "model=$MODEL" >> $GITHUB_OUTPUT | |
| echo "📊 Using Opus (manual override via label)" | |
| exit 0 | |
| elif [ "$HAS_SONNET_LABEL" == "true" ]; then | |
| MODEL="sonnet" | |
| echo "model=$MODEL" >> $GITHUB_OUTPUT | |
| echo "📊 Using Sonnet (manual override via label)" | |
| exit 0 | |
| fi | |
| # No manual label - use automatic selection based on PR size | |
| ADDITIONS=${{ github.event.pull_request.additions }} | |
| DELETIONS=${{ github.event.pull_request.deletions }} | |
| TOTAL_LINES=$((ADDITIONS + DELETIONS)) | |
| if [ $TOTAL_LINES -gt 500 ]; then | |
| MODEL="opus" | |
| echo "model=$MODEL" >> $GITHUB_OUTPUT | |
| echo "📊 PR Size: $TOTAL_LINES lines changed - Using Opus (automatic)" | |
| else | |
| MODEL="sonnet" | |
| echo "model=$MODEL" >> $GITHUB_OUTPUT | |
| echo "📊 PR Size: $TOTAL_LINES lines changed - Using Sonnet (default)" | |
| fi | |
| - name: Install Skills | |
| run: npx skills add apollographql/skills@rust-best-practices -a claude-code -y | |
| - name: Claude Code Review | |
| id: claude_review | |
| uses: anthropics/claude-code-action@v1 | |
| continue-on-error: true | |
| with: | |
| anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} | |
| # Use the "review" skill defined at .claude/skills/review/SKILL.md | |
| prompt: "/review" | |
| # Model selected automatically based on PR complexity, or manually via label | |
| claude_args: >- | |
| --max-turns 20 | |
| --model ${{ steps.model_selection.outputs.model }} | |
| --allowedTools "Bash(gh:*),Bash(git diff*),Bash(git log*),Bash(git show*),Read,Grep,Glob" | |
| - name: Output Claude execution log | |
| if: always() | |
| run: | | |
| if [ -f /home/runner/work/_temp/claude-execution-output.json ]; then | |
| echo "=== Claude Execution Log ===" | |
| cat /home/runner/work/_temp/claude-execution-output.json | |
| else | |
| echo "No execution log found at /home/runner/work/_temp/claude-execution-output.json" | |
| fi | |
| - name: Post failure comment | |
| if: failure() && steps.claude_review.outcome == 'failure' | |
| uses: actions/github-script@v9 | |
| with: | |
| script: | | |
| const body = '⚠️ Claude Code Review failed to complete. This could be due to API issues, rate limits, or insufficient credits. The PR can still be merged - manual review recommended.'; | |
| const marker = 'Claude Code Review'; | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| }); | |
| const existing = comments.reverse().find(c => c.body?.includes(marker) && c.user?.login === 'github-actions[bot]'); | |
| if (existing) { | |
| await github.rest.issues.updateComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: existing.id, | |
| body, | |
| }); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body, | |
| }); | |
| } |