Add automated PR review workflow with /review command
#2
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: PR Review on Command | |
| on: | |
| # Trigger when an issue comment is created (includes PR comments) | |
| issue_comment: | |
| types: [created] | |
| # Allow manual trigger from GitHub UI | |
| workflow_dispatch: | |
| inputs: | |
| pr_number: | |
| description: "PR number to review" | |
| required: true | |
| type: number | |
| # TEMPORARY: For testing in PR - REMOVE THIS after merging to main | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| # Minimal permissions needed | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| issues: write | |
| jobs: | |
| # Check if the comment trigger should run the review | |
| check-comment: | |
| if: | | |
| (github.event_name == 'issue_comment' && github.event.issue.pull_request && contains(github.event.comment.body, '/review')) || | |
| github.event_name == 'pull_request' || | |
| github.event_name == 'workflow_dispatch' | |
| runs-on: ubuntu-latest | |
| outputs: | |
| should_run: ${{ steps.check.outputs.result }} | |
| pr_number: ${{ steps.get-pr.outputs.pr_number }} | |
| steps: | |
| - name: Get PR number | |
| id: get-pr | |
| run: | | |
| if [ "${{ github.event_name }}" == "pull_request" ]; then | |
| echo "pr_number=${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT | |
| elif [ "${{ github.event_name }}" == "issue_comment" ]; then | |
| echo "pr_number=${{ github.event.issue.number }}" >> $GITHUB_OUTPUT | |
| elif [ "${{ github.event_name }}" == "workflow_dispatch" ]; then | |
| echo "pr_number=${{ inputs.pr_number }}" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Check comment conditions | |
| id: check | |
| run: | | |
| echo "Event: ${{ github.event_name }}" | |
| echo "PR Number: ${{ steps.get-pr.outputs.pr_number }}" | |
| echo "result=true" >> $GITHUB_OUTPUT | |
| - name: Add reaction to comment | |
| if: github.event_name == 'issue_comment' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| await github.rest.reactions.createForIssueComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: context.payload.comment.id, | |
| content: 'eyes' | |
| }); | |
| # Run the actual review process | |
| run-review: | |
| needs: [check-comment] | |
| if: always() && needs.check-comment.outputs.should_run == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Run PR Reviewer Agent | |
| id: review | |
| uses: docker/cagent-action@1f7ec0445e138a587639fc9c046076e22d184349 # v1.0.4 | |
| with: | |
| agent: agentcatalog/github-action-pr-reviewer:2.0.0 | |
| mcp-gateway: true | |
| anthropic-api-key: ${{ secrets.ANTHROPIC_API_KEY }} | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| continue-on-error: true | |
| - name: Add success reaction | |
| if: success() && github.event_name == 'issue_comment' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| await github.rest.reactions.createForIssueComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: context.payload.comment.id, | |
| content: 'rocket' | |
| }); | |
| - name: Add failure reaction | |
| if: failure() && github.event_name == 'issue_comment' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| await github.rest.reactions.createForIssueComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: context.payload.comment.id, | |
| content: 'confused' | |
| }); |