-
Notifications
You must be signed in to change notification settings - Fork 6
300 lines (247 loc) · 11.1 KB
/
Copy pathclaude-code-review.yml
File metadata and controls
300 lines (247 loc) · 11.1 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
name: Claude Code Review
on:
pull_request:
types: [opened, synchronize]
jobs:
claude-review:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
issues: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Get full history to see what changed
- name: Run Claude Code Review
id: claude-review
uses: anthropics/claude-code-action@v1
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
# Use sticky comments so Claude updates the same comment
use_sticky_comment: false
# track_progress enables tracking comments like v0.x agent mode
track_progress: true
# Enhanced prompt that makes Claude track and verify fixes
prompt: |
REPO: ${{ github.repository }}
PR NUMBER: ${{ github.event.pull_request.number }}
You are reviewing a pull request. Check your previous comment to see the previous issues and make sure these have been fixed before highlighting new ones.
IMPORTANT INSTRUCTIONS:
1. If this is a subsequent review (synchronize event), check what changed since your last review
2. Track each issue with a unique identifier like [ISSUE-001], [ISSUE-002], etc.
3. Mark issues that have been fixed as ✅ FIXED
4. Mark unresolved issues as ⚠️ STILL OPEN
5. Mark new issues as 🔍 NEW
Review this pull request and provide feedback on:
- Code quality and best practices
- Potential bugs or issues
- Performance considerations
- Security concerns
- Test coverage
Format your response like this:
## Code Review Status
### Issues Found:
[ISSUE-001] ⚠️ STILL OPEN - Service mode confusion
- File: dist/index.js:341
- Problem: this.mode is undefined
- Suggestion: Remove the check since only writer mode runs this
[ISSUE-002] ✅ FIXED - Missing error handling
- File: socketMapping.js:234
- Status: Fixed in latest commit
[ISSUE-003] 🔍 NEW - Unused variable
- File: someFile.js:123
- Problem: Variable declared but never used
### Summary:
- Total Issues: 3
- Fixed: 1
- Still Open: 1
- New: 1
Be constructive and helpful. When an issue is fixed, acknowledge it positively!
- name: Manage GitHub Issues from Review
if: steps.claude-review.outputs.comment != ''
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_TITLE: ${{ github.event.pull_request.title }}
REPO: ${{ github.repository }}
run: |
# Save review comment to temp file for parsing
cat > /tmp/review.txt << 'REVIEW_EOF'
${{ steps.claude-review.outputs.comment }}
REVIEW_EOF
# Initialize counters
new_count=0
still_open_count=0
closed_count=0
echo "## Issue Management Summary" > /tmp/issue_summary.txt
echo "" >> /tmp/issue_summary.txt
# First pass: Handle FIXED issues (close them)
echo "### ✅ Closed Issues" >> /tmp/issue_summary.txt
awk '
/^\[ISSUE-[0-9]+\] ✅ FIXED/ {
match($0, /\[ISSUE-[0-9]+\]/, arr)
issue_id = arr[0]
sub(/^\[ISSUE-[0-9]+\] ✅ FIXED - /, "", $0)
title = $0
print issue_id "|" title
}
' /tmp/review.txt | while IFS='|' read -r issue_id title; do
if [ -z "$issue_id" ]; then
continue
fi
# Convert [ISSUE-001] to issue-id:ISSUE-001 for label search
label_id=$(echo "$issue_id" | tr -d '[]' | sed 's/^/issue-id:/')
# Search for existing issue with this label
existing_issue=$(gh issue list --label "$label_id" --state open --json number --jq '.[0].number' --repo "${REPO}" 2>/dev/null)
if [ -n "$existing_issue" ]; then
echo "Closing issue #${existing_issue} for ${issue_id}: ${title}"
gh issue close "$existing_issue" \
--comment "✅ This issue has been resolved and verified in PR #${PR_NUMBER}" \
--repo "${REPO}"
echo "- ${issue_id}: ${title} (Issue #${existing_issue})" >> /tmp/issue_summary.txt
closed_count=$((closed_count + 1))
else
echo "No open issue found for ${issue_id} (already closed or never created)"
fi
done
if [ "$closed_count" -eq 0 ]; then
echo "- None" >> /tmp/issue_summary.txt
fi
echo "" >> /tmp/issue_summary.txt
# Second pass: Handle NEW and STILL OPEN issues
echo "### 🔍 New Issues Created" >> /tmp/issue_summary.txt
awk '
/^\[ISSUE-[0-9]+\] (🔍 NEW|⚠️ STILL OPEN)/ {
if (issue_id) {
print issue_id "|" status "|" title "|" details
}
match($0, /\[ISSUE-[0-9]+\]/, arr)
issue_id = arr[0]
if ($0 ~ /🔍 NEW/) status = "new"
else if ($0 ~ /⚠️ STILL OPEN/) status = "open"
sub(/^\[ISSUE-[0-9]+\] (🔍 NEW|⚠️ STILL OPEN) - /, "", $0)
title = $0
details = ""
next
}
/^- File:/ || /^- Problem:/ || /^- Suggestion:/ || /^- Status:/ {
if (details) details = details "\n" $0
else details = $0
next
}
/^\[ISSUE-[0-9]+\]/ || /^###/ || /^##/ {
if (issue_id) {
print issue_id "|" status "|" title "|" details
issue_id = ""
}
}
END {
if (issue_id) {
print issue_id "|" status "|" title "|" details
}
}
' /tmp/review.txt | while IFS='|' read -r issue_id status title details; do
if [ -z "$issue_id" ]; then
continue
fi
# Convert [ISSUE-001] to issue-id:ISSUE-001 for label
label_id=$(echo "$issue_id" | tr -d '[]' | sed 's/^/issue-id:/')
# Check if issue already exists
existing_issue=$(gh issue list --label "$label_id" --state open --json number --jq '.[0].number' --repo "${REPO}" 2>/dev/null)
if [ "$status" = "new" ]; then
status_emoji="🔍 NEW"
base_labels="code-review,automated,new-finding"
else
status_emoji="⚠️ STILL OPEN"
base_labels="code-review,automated,needs-attention"
fi
if [ -n "$existing_issue" ]; then
# Issue exists and is still open - update it
echo "Updating existing issue #${existing_issue} for ${issue_id}"
cat > /tmp/issue_comment.txt << 'COMMENT_EOF'
**Still present in PR #${PR_NUMBER}**
${status_emoji} This issue is still open.
## Latest Details
${details}
*Updated: $(date -u +"%Y-%m-%d %H:%M:%S UTC")*
COMMENT_EOF
# Replace variables in the comment
sed -i "s|\${PR_NUMBER}|${PR_NUMBER}|g" /tmp/issue_comment.txt
sed -i "s|\${status_emoji}|${status_emoji}|g" /tmp/issue_comment.txt
sed -i "s|\${details}|${details}|g" /tmp/issue_comment.txt
gh issue comment "$existing_issue" --body "$(cat /tmp/issue_comment.txt)" --repo "${REPO}"
if [ "$status" = "open" ]; then
still_open_count=$((still_open_count + 1))
fi
else
# Create new issue
cat > /tmp/issue_body.txt << 'ISSUE_EOF'
**Found in PR #${PR_NUMBER}**: ${PR_TITLE}
**Status**: ${status_emoji}
**Issue ID**: ${issue_id}
## Details
${details}
---
*This issue was automatically identified during code review.*
*For full context, see the [code review comment](https://github.com/${REPO}/pull/${PR_NUMBER}).*
ISSUE_EOF
# Replace variables in the issue body
sed -i "s|\${PR_NUMBER}|${PR_NUMBER}|g" /tmp/issue_body.txt
sed -i "s|\${PR_TITLE}|${PR_TITLE}|g" /tmp/issue_body.txt
sed -i "s|\${status_emoji}|${status_emoji}|g" /tmp/issue_body.txt
sed -i "s|\${issue_id}|${issue_id}|g" /tmp/issue_body.txt
sed -i "s|\${details}|${details}|g" /tmp/issue_body.txt
sed -i "s|\${REPO}|${REPO}|g" /tmp/issue_body.txt
echo "Creating new issue for ${issue_id}: ${title}"
new_issue=$(gh issue create \
--title "Code Review: ${title}" \
--body "$(cat /tmp/issue_body.txt)" \
--label "${base_labels},${label_id}" \
--repo "${REPO}" \
--json number --jq '.number' 2>/dev/null)
if [ -n "$new_issue" ]; then
echo "- ${issue_id}: ${title} (Issue #${new_issue})" >> /tmp/issue_summary.txt
new_count=$((new_count + 1))
fi
fi
done
if [ "$new_count" -eq 0 ]; then
echo "- None" >> /tmp/issue_summary.txt
fi
echo "" >> /tmp/issue_summary.txt
# Third pass: List still open issues
echo "### ⚠️ Still Open Issues" >> /tmp/issue_summary.txt
awk '
/^\[ISSUE-[0-9]+\] ⚠️ STILL OPEN/ {
match($0, /\[ISSUE-[0-9]+\]/, arr)
issue_id = arr[0]
sub(/^\[ISSUE-[0-9]+\] ⚠️ STILL OPEN - /, "", $0)
print issue_id "|" $0
}
' /tmp/review.txt | while IFS='|' read -r issue_id title; do
if [ -z "$issue_id" ]; then
continue
fi
label_id=$(echo "$issue_id" | tr -d '[]' | sed 's/^/issue-id:/')
existing_issue=$(gh issue list --label "$label_id" --state open --json number --jq '.[0].number' --repo "${REPO}" 2>/dev/null)
if [ -n "$existing_issue" ]; then
echo "- ${issue_id}: ${title} (Issue #${existing_issue})" >> /tmp/issue_summary.txt
fi
done
if [ "$still_open_count" -eq 0 ]; then
echo "- None" >> /tmp/issue_summary.txt
fi
echo "" >> /tmp/issue_summary.txt
# Summary stats
echo "---" >> /tmp/issue_summary.txt
echo "**Summary**: ${new_count} new, ${still_open_count} still open, ${closed_count} closed" >> /tmp/issue_summary.txt
# Output summary
cat /tmp/issue_summary.txt
# Post summary as PR comment
gh pr comment "${PR_NUMBER}" \
--body "$(cat /tmp/issue_summary.txt)" \
--repo "${REPO}"
echo "Issue management completed: ${new_count} new, ${still_open_count} still open, ${closed_count} closed"