|
| 1 | +name: Claude Code |
| 2 | + |
| 3 | +on: |
| 4 | + issue_comment: |
| 5 | + types: [created] |
| 6 | + pull_request_review_comment: |
| 7 | + types: [created] |
| 8 | + issues: |
| 9 | + types: [opened, assigned] |
| 10 | + pull_request_review: |
| 11 | + types: [submitted] |
| 12 | + |
| 13 | +jobs: |
| 14 | + claude: |
| 15 | + if: | |
| 16 | + (github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) || |
| 17 | + (github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) || |
| 18 | + (github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) || |
| 19 | + (github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude'))) |
| 20 | + runs-on: ubuntu-latest |
| 21 | + permissions: |
| 22 | + contents: read |
| 23 | + pull-requests: read |
| 24 | + issues: read |
| 25 | + id-token: write |
| 26 | + actions: read # Required for Claude to read CI results on PRs |
| 27 | + steps: |
| 28 | + - name: Check repository permissions |
| 29 | + run: | |
| 30 | + # Check if user has at least triage rights on the repository |
| 31 | + PERMISSION=$(gh api "repos/${{ github.repository }}/collaborators/${{ github.actor }}/permission" -q '.permission' 2>/dev/null) |
| 32 | +
|
| 33 | + case "$PERMISSION" in |
| 34 | + admin|maintain|push|triage) |
| 35 | + echo "✓ User has $PERMISSION rights on the repository" |
| 36 | + exit 0 |
| 37 | + ;; |
| 38 | + pull) |
| 39 | + echo "✗ User only has pull (read-only) rights" |
| 40 | + exit 1 |
| 41 | + ;; |
| 42 | + *) |
| 43 | + echo "✗ User does not have sufficient permissions" |
| 44 | + exit 1 |
| 45 | + ;; |
| 46 | + esac |
| 47 | + env: |
| 48 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 49 | + |
| 50 | + - name: Checkout repository |
| 51 | + uses: actions/checkout@v4 |
| 52 | + with: |
| 53 | + fetch-depth: 1 |
| 54 | + |
| 55 | + - name: Run Claude Code |
| 56 | + id: claude |
| 57 | + uses: anthropics/claude-code-action@v1 |
| 58 | + with: |
| 59 | + anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} |
| 60 | + |
| 61 | + # This is an optional setting that allows Claude to read CI results on PRs |
| 62 | + additional_permissions: | |
| 63 | + actions: read |
| 64 | +
|
| 65 | + # Optional: Give a custom prompt to Claude. If this is not specified, Claude will perform the instructions specified in the comment that tagged it. |
| 66 | + # prompt: 'Update the pull request description to include a summary of changes.' |
| 67 | + |
| 68 | + # Optional: Add claude_args to customize behavior and configuration |
| 69 | + # See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md |
| 70 | + # or https://docs.claude.com/en/docs/claude-code/cli-reference for available options |
| 71 | + # claude_args: '--allowed-tools Bash(gh pr:*)' |
| 72 | + |
0 commit comments