|
12 | 12 |
|
13 | 13 | jobs: |
14 | 14 | claude: |
| 15 | + # Only allow trusted collaborators to trigger Claude via @claude mention |
15 | 16 | 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'))) |
| 17 | + ( |
| 18 | + github.event.comment.author_association == 'OWNER' || |
| 19 | + github.event.comment.author_association == 'MEMBER' || |
| 20 | + github.event.comment.author_association == 'COLLABORATOR' || |
| 21 | + github.event.review.author_association == 'OWNER' || |
| 22 | + github.event.review.author_association == 'MEMBER' || |
| 23 | + github.event.review.author_association == 'COLLABORATOR' || |
| 24 | + github.event.issue.author_association == 'OWNER' || |
| 25 | + github.event.issue.author_association == 'MEMBER' || |
| 26 | + github.event.issue.author_association == 'COLLABORATOR' |
| 27 | + ) && ( |
| 28 | + (github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) || |
| 29 | + (github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) || |
| 30 | + (github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) || |
| 31 | + (github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude'))) |
| 32 | + ) |
20 | 33 | runs-on: ubuntu-latest |
21 | 34 | permissions: |
22 | 35 | contents: write |
23 | 36 | pull-requests: write |
24 | 37 | issues: write |
25 | | - id-token: write |
26 | | - actions: read # Required for Claude to read CI results on PRs |
| 38 | + actions: read |
27 | 39 | steps: |
| 40 | + - name: Determine checkout ref |
| 41 | + id: determine-ref |
| 42 | + uses: actions/github-script@v7 |
| 43 | + with: |
| 44 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 45 | + script: | |
| 46 | + const eventName = context.eventName; |
| 47 | + let ref = context.sha; |
| 48 | +
|
| 49 | + if (eventName === 'pull_request_review' || eventName === 'pull_request_review_comment') { |
| 50 | + ref = context.payload.pull_request.head.sha; |
| 51 | + } else if (eventName === 'issue_comment' && context.payload.issue && context.payload.issue.pull_request) { |
| 52 | + const prNumber = context.payload.issue.number; |
| 53 | + const { data: pr } = await github.rest.pulls.get({ |
| 54 | + owner: context.repo.owner, |
| 55 | + repo: context.repo.repo, |
| 56 | + pull_number: prNumber, |
| 57 | + }); |
| 58 | + ref = pr.head.sha; |
| 59 | + } |
| 60 | +
|
| 61 | + core.setOutput('ref', ref); |
| 62 | +
|
28 | 63 | - name: Checkout repository |
29 | 64 | uses: actions/checkout@v6 |
30 | 65 | with: |
31 | | - fetch-depth: 1 |
| 66 | + ref: ${{ steps.determine-ref.outputs.ref }} |
32 | 67 |
|
33 | 68 | - name: Set up JDK 21 |
34 | 69 | uses: actions/setup-java@v5 |
|
37 | 72 | distribution: 'temurin' |
38 | 73 | cache: gradle |
39 | 74 |
|
| 75 | + - name: Grant execute permission for gradlew |
| 76 | + run: chmod +x gradlew |
| 77 | + |
40 | 78 | - name: Setup Gradle |
41 | 79 | uses: gradle/actions/setup-gradle@v4 |
42 | 80 |
|
|
0 commit comments