|
| 1 | +name: Claude Review on Maintainer PRs |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request_target: |
| 5 | + types: |
| 6 | + - opened |
| 7 | + - ready_for_review |
| 8 | + |
| 9 | +jobs: |
| 10 | + comment: |
| 11 | + if: github.event.pull_request.draft == false |
| 12 | + runs-on: ubuntu-latest |
| 13 | + permissions: |
| 14 | + issues: write |
| 15 | + pull-requests: write |
| 16 | + steps: |
| 17 | + - name: Check author permission and existing review request |
| 18 | + id: check |
| 19 | + uses: actions/github-script@v7 |
| 20 | + with: |
| 21 | + script: | |
| 22 | + const owner = context.repo.owner; |
| 23 | + const repo = context.repo.repo; |
| 24 | + const issue_number = context.payload.pull_request.number; |
| 25 | + const username = context.payload.pull_request.user.login; |
| 26 | +
|
| 27 | + let permission = "none"; |
| 28 | + try { |
| 29 | + const { data } = await github.rest.repos.getCollaboratorPermissionLevel({ |
| 30 | + owner, |
| 31 | + repo, |
| 32 | + username, |
| 33 | + }); |
| 34 | + permission = data.permission; |
| 35 | + } catch (error) { |
| 36 | + if (error.status !== 404) { |
| 37 | + throw error; |
| 38 | + } |
| 39 | + } |
| 40 | +
|
| 41 | + const canWrite = ["write", "admin"].includes(permission); |
| 42 | + const comments = await github.paginate(github.rest.issues.listComments, { |
| 43 | + owner, |
| 44 | + repo, |
| 45 | + issue_number, |
| 46 | + per_page: 100, |
| 47 | + }); |
| 48 | + const hasReviewRequest = comments.some( |
| 49 | + (comment) => comment.body?.trim() === "@claude review", |
| 50 | + ); |
| 51 | +
|
| 52 | + core.info( |
| 53 | + `PR #${issue_number} by ${username}: permission=${permission}, hasReviewRequest=${hasReviewRequest}`, |
| 54 | + ); |
| 55 | +
|
| 56 | + core.setOutput("should_comment", canWrite && !hasReviewRequest ? "true" : "false"); |
| 57 | +
|
| 58 | + - name: Add Claude review comment |
| 59 | + if: steps.check.outputs.should_comment == 'true' |
| 60 | + uses: actions/github-script@v7 |
| 61 | + with: |
| 62 | + script: | |
| 63 | + await github.rest.issues.createComment({ |
| 64 | + owner: context.repo.owner, |
| 65 | + repo: context.repo.repo, |
| 66 | + issue_number: context.payload.pull_request.number, |
| 67 | + body: "@claude review", |
| 68 | + }); |
0 commit comments