|
| 1 | +name: PR Review on Command |
| 2 | + |
| 3 | +on: |
| 4 | + # Trigger when an issue comment is created (includes PR comments) |
| 5 | + issue_comment: |
| 6 | + types: [created] |
| 7 | + |
| 8 | + # Allow manual trigger from GitHub UI |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + pr_number: |
| 12 | + description: "PR number to review" |
| 13 | + required: true |
| 14 | + type: number |
| 15 | + |
| 16 | +# Minimal permissions needed |
| 17 | +permissions: |
| 18 | + contents: read |
| 19 | + pull-requests: write |
| 20 | + issues: write |
| 21 | + |
| 22 | +jobs: |
| 23 | + # Check if the comment trigger should run the review |
| 24 | + check-comment: |
| 25 | + if: github.event_name == 'issue_comment' && github.event.issue.pull_request && contains(github.event.comment.body, '/review') |
| 26 | + runs-on: ubuntu-latest |
| 27 | + outputs: |
| 28 | + should_run: ${{ steps.check.outputs.result }} |
| 29 | + pr_number: ${{ github.event.issue.number }} |
| 30 | + |
| 31 | + steps: |
| 32 | + - name: Check comment conditions |
| 33 | + id: check |
| 34 | + run: | |
| 35 | + echo "Comment body: ${{ github.event.comment.body }}" |
| 36 | + echo "result=true" >> $GITHUB_OUTPUT |
| 37 | +
|
| 38 | + - name: Add reaction to comment |
| 39 | + uses: actions/github-script@v7 |
| 40 | + with: |
| 41 | + script: | |
| 42 | + await github.rest.reactions.createForIssueComment({ |
| 43 | + owner: context.repo.owner, |
| 44 | + repo: context.repo.repo, |
| 45 | + comment_id: context.payload.comment.id, |
| 46 | + content: 'eyes' |
| 47 | + }); |
| 48 | +
|
| 49 | + # Run the actual review process |
| 50 | + run-review: |
| 51 | + needs: [check-comment] |
| 52 | + if: | |
| 53 | + always() && |
| 54 | + (needs.check-comment.outputs.should_run == 'true' || github.event_name == 'workflow_dispatch') |
| 55 | + runs-on: ubuntu-latest |
| 56 | + steps: |
| 57 | + - name: Checkout repository |
| 58 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 59 | + with: |
| 60 | + ref: ${{ teps.pr-details.outputs.head_ref }} |
| 61 | + |
| 62 | + - name: Run PR Reviewer Agent |
| 63 | + id: review |
| 64 | + uses: docker/cagent-action@1f7ec0445e138a587639fc9c046076e22d184349 # v1.0.4 |
| 65 | + with: |
| 66 | + agent: agentcatalog/github-action-pr-reviewer:2.0.0 |
| 67 | + mcp-gateway: true |
| 68 | + anthropic-api-key: ${{ secrets.ANTHROPIC_API_KEY }} |
| 69 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 70 | + continue-on-error: true |
| 71 | + |
| 72 | + - name: Add success reaction |
| 73 | + if: success() && github.event_name == 'issue_comment' |
| 74 | + uses: actions/github-script@v7 |
| 75 | + with: |
| 76 | + script: | |
| 77 | + await github.rest.reactions.createForIssueComment({ |
| 78 | + owner: context.repo.owner, |
| 79 | + repo: context.repo.repo, |
| 80 | + comment_id: context.payload.comment.id, |
| 81 | + content: 'rocket' |
| 82 | + }); |
| 83 | +
|
| 84 | + - name: Add failure reaction |
| 85 | + if: failure() && github.event_name == 'issue_comment' |
| 86 | + uses: actions/github-script@v7 |
| 87 | + with: |
| 88 | + script: | |
| 89 | + await github.rest.reactions.createForIssueComment({ |
| 90 | + owner: context.repo.owner, |
| 91 | + repo: context.repo.repo, |
| 92 | + comment_id: context.payload.comment.id, |
| 93 | + content: 'confused' |
| 94 | + }); |
0 commit comments