forked from danielsdeleo/moqueue
-
Notifications
You must be signed in to change notification settings - Fork 4
128 lines (113 loc) · 4.91 KB
/
Copy pathclaude-code-review.yml
File metadata and controls
128 lines (113 loc) · 4.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
name: Claude Code Review
on:
pull_request:
types: [opened, synchronize, ready_for_review, reopened]
issue_comment:
types: [created]
pull_request_review_comment:
types: [created]
pull_request_review:
types: [submitted]
permissions:
contents: read
pull-requests: write
issues: read
id-token: write
jobs:
review:
if: |
(github.event_name == 'pull_request' && github.event.pull_request.draft == false && github.event.pull_request.merged == false) ||
(github.event_name == 'issue_comment' && github.event.issue.pull_request && contains(github.event.comment.body, '@claude')) ||
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude'))
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.event.issue.number || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
steps:
- name: Resolve PR number
id: pr
run: |
if [ "${{ github.event_name }}" = "issue_comment" ]; then
echo "number=${{ github.event.issue.number }}" >> "$GITHUB_OUTPUT"
else
echo "number=${{ github.event.pull_request.number }}" >> "$GITHUB_OUTPUT"
fi
- name: Checkout repository
uses: actions/checkout@v7
with:
ref: refs/pull/${{ steps.pr.outputs.number }}/head
fetch-depth: 0
- name: Fetch PR diff
env:
GH_TOKEN: ${{ github.token }}
run: |
gh pr diff "${{ steps.pr.outputs.number }}" > /tmp/pr-diff.patch
- name: Fetch previous reviews
env:
GH_TOKEN: ${{ github.token }}
run: |
PR_NUM="${{ steps.pr.outputs.number }}"
REPO="${{ github.repository }}"
{
echo "=== Review Summaries ==="
gh api "repos/${REPO}/pulls/${PR_NUM}/reviews" --paginate \
--jq '.[] | select(.state != "PENDING") | "[\(.user.login)] \(.state)\n\(.body)\n---"' 2>/dev/null || true
echo ""
echo "=== Inline Review Comments ==="
gh api "repos/${REPO}/pulls/${PR_NUM}/comments" --paginate \
--jq '.[] | "[\(.user.login)] \(.path):\(.line // .original_line)\n\(.body)\n---"' 2>/dev/null || true
echo ""
echo "=== PR Conversation Comments ==="
gh api "repos/${REPO}/issues/${PR_NUM}/comments" --paginate \
--jq '.[] | "[\(.user.login)]\n\(.body)\n---"' 2>/dev/null || true
} > /tmp/previous-reviews.txt
- name: Build review prompt
id: prompt
run: |
DELIMITER="PROMPT_EOF_$(uuidgen)"
{
echo "REVIEW_PROMPT<<${DELIMITER}"
for f in CLAUDE.md AGENTS.md; do
if [ -f "$f" ]; then
cat "$f"
echo ""
fi
done
if [ -f ".claude/review-prompt.md" ]; then
cat .claude/review-prompt.md
fi
echo "${DELIMITER}"
} >> "$GITHUB_OUTPUT"
- name: Resolve claude_args
id: args
env:
MODEL: ${{ vars.CLAUDE_REVIEW_MODEL }}
run: |
ALLOWED_TOOLS='Read,Glob,Grep,mcp__github_inline_comment__create_inline_comment,Bash(gh pr comment:*),Bash(gh pr view:*)'
if [ -n "$MODEL" ]; then
echo "value=--model ${MODEL} --max-turns 10 --allowedTools \"${ALLOWED_TOOLS}\"" >> "$GITHUB_OUTPUT"
else
echo "value=--max-turns 10 --allowedTools \"${ALLOWED_TOOLS}\"" >> "$GITHUB_OUTPUT"
fi
- name: Claude Code Review
continue-on-error: true
uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
allowed_bots: "custom-ink-triton"
prompt: |
You are reviewing PR #${{ steps.pr.outputs.number }}.
The full diff is in /tmp/pr-diff.patch — Read that file first.
Previous review comments are in /tmp/previous-reviews.txt — Read that file next.
Do NOT run gh pr diff or git diff to re-fetch it.
Use Read on source files if you need more context beyond the diff.
IMPORTANT: Do NOT repeat or reiterate feedback that has already been given
in previous reviews. If a prior reviewer (human or bot) already flagged an
issue and the author has not addressed it in the current diff, you may
reference it briefly but do not re-explain. Focus your review on NEW issues
not covered by prior feedback.
Post inline review comments and stop.
Review this pull request using the following guidelines:
${{ steps.prompt.outputs.REVIEW_PROMPT }}
claude_args: "${{ steps.args.outputs.value }}"