Skip to content

Commit 7a2bffe

Browse files
committed
Start of a PR reviewer workflow
1 parent 7c07a98 commit 7a2bffe

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
name: PR Review on Command
2+
3+
on:
4+
issue_comment:
5+
types: [created]
6+
workflow_dispatch:
7+
inputs:
8+
pr_number:
9+
description: "PR number to review"
10+
required: true
11+
type: number
12+
13+
permissions:
14+
contents: read
15+
pull-requests: write
16+
issues: write
17+
18+
jobs:
19+
check-trigger:
20+
if: |
21+
(github.event_name == 'issue_comment' && github.event.issue.pull_request && contains(github.event.comment.body, '/review')) ||
22+
github.event_name == 'workflow_dispatch'
23+
runs-on: ubuntu-latest
24+
outputs:
25+
pr_number: ${{ steps.get-pr.outputs.pr_number }}
26+
steps:
27+
- name: Get PR number
28+
id: get-pr
29+
run: |
30+
if [ "${{ github.event_name }}" == "issue_comment" ]; then
31+
echo "pr_number=${{ github.event.issue.number }}" >> $GITHUB_OUTPUT
32+
else
33+
echo "pr_number=${{ inputs.pr_number }}" >> $GITHUB_OUTPUT
34+
fi
35+
36+
- name: Add eyes reaction
37+
if: github.event_name == 'issue_comment'
38+
uses: actions/github-script@v7
39+
with:
40+
script: |
41+
await github.rest.reactions.createForIssueComment({
42+
owner: context.repo.owner,
43+
repo: context.repo.repo,
44+
comment_id: context.payload.comment.id,
45+
content: 'eyes'
46+
});
47+
48+
run-review:
49+
needs: [check-trigger]
50+
runs-on: ubuntu-latest
51+
steps:
52+
- name: Checkout PR
53+
uses: actions/checkout@v4
54+
55+
- name: Get PR details
56+
id: pr-details
57+
uses: actions/github-script@v7
58+
with:
59+
script: |
60+
const prNumber = ${{ needs.check-trigger.outputs.pr_number }};
61+
const { data: pr } = await github.rest.pulls.get({
62+
owner: context.repo.owner,
63+
repo: context.repo.repo,
64+
pull_number: prNumber
65+
});
66+
const { data: files } = await github.rest.pulls.listFiles({
67+
owner: context.repo.owner,
68+
repo: context.repo.repo,
69+
pull_number: prNumber
70+
});
71+
core.setOutput('pr_title', pr.title);
72+
core.setOutput('pr_author', pr.user.login);
73+
core.setOutput('files_changed', files.length);
74+
core.setOutput('head_ref', pr.head.ref);
75+
76+
- name: Checkout PR branch
77+
run: |
78+
git fetch origin ${{ steps.pr-details.outputs.head_ref }}
79+
git checkout ${{ steps.pr-details.outputs.head_ref }}
80+
81+
- name: Run PR Reviewer Agent
82+
uses: docker/cagent-action@1f7ec0445e138a587639fc9c046076e22d184349
83+
with:
84+
agent: agentcatalog/github-action-pr-reviewer:2.0.0
85+
mcp-gateway: true
86+
anthropic-api-key: ${{ secrets.ANTHROPIC_API_KEY }}
87+
github-token: ${{ secrets.GITHUB_TOKEN }}
88+
env:
89+
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
90+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
91+
continue-on-error: true
92+
93+
- name: Add success reaction
94+
if: success() && github.event_name == 'issue_comment'
95+
uses: actions/github-script@v7
96+
with:
97+
script: |
98+
await github.rest.reactions.createForIssueComment({
99+
owner: context.repo.owner,
100+
repo: context.repo.repo,
101+
comment_id: context.payload.comment.id,
102+
content: 'rocket'
103+
});
104+
105+
- name: Add failure reaction
106+
if: failure() && github.event_name == 'issue_comment'
107+
uses: actions/github-script@v7
108+
with:
109+
script: |
110+
await github.rest.reactions.createForIssueComment({
111+
owner: context.repo.owner,
112+
repo: context.repo.repo,
113+
comment_id: context.payload.comment.id,
114+
content: 'confused'
115+
});

0 commit comments

Comments
 (0)