Skip to content

Commit 29afc85

Browse files
committed
claude_code_review
1 parent 2f93420 commit 29afc85

File tree

1 file changed

+126
-0
lines changed

1 file changed

+126
-0
lines changed
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
name: Claude Code Review
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
branches: [main, cloud, devel]
7+
8+
concurrency:
9+
group: claude-review-${{ github.event.pull_request.number }}
10+
cancel-in-progress: true
11+
12+
env:
13+
CLAUDE_MODEL: claude-opus-4-5-20251101
14+
CLAUDE_MAX_TURNS: 10
15+
16+
jobs:
17+
claude-review:
18+
name: Claude Code Review
19+
runs-on: ubuntu-22.04
20+
permissions:
21+
contents: read
22+
pull-requests: write
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v6
26+
with:
27+
fetch-depth: 0
28+
ref: ${{ github.event.pull_request.head.sha }}
29+
30+
- name: Fetch base branch
31+
run: |
32+
git fetch origin ${{ github.event.pull_request.base.ref }}:${{ github.event.pull_request.base.ref }}
33+
34+
- name: Set up Node.js
35+
uses: actions/setup-node@v4
36+
with:
37+
node-version: "20"
38+
39+
- name: Install Claude Code CLI
40+
run: npm install -g @anthropic-ai/claude-code
41+
42+
- name: Configure Claude Code authentication
43+
run: |
44+
mkdir -p ~/.claude
45+
# Store the OAuth token in the expected location
46+
echo '${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}' > ~/.claude/oauth_token
47+
env:
48+
CLAUDE_CODE_OAUTH_TOKEN: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
49+
50+
- name: Create review script
51+
run: |
52+
cat > /tmp/review.sh << 'SCRIPT_EOF'
53+
#!/bin/bash
54+
set -e
55+
56+
# Create a temporary file for the prompt
57+
PROMPT_FILE=$(mktemp)
58+
59+
cat > "$PROMPT_FILE" << 'PROMPT_EOF'
60+
Please perform a comprehensive code review of this pull request.
61+
62+
Use the /review skill to analyze all the changes in this PR.
63+
64+
After your review, provide a summary that includes:
65+
- Overall assessment
66+
- Key findings (bugs, security issues, performance concerns)
67+
- Suggestions for improvement
68+
- Any questions or areas needing clarification
69+
70+
Format your response in markdown suitable for a GitHub PR comment.
71+
PROMPT_EOF
72+
73+
# Run Claude Code with the review skill
74+
claude /review --max-turns "${{ env.CLAUDE_MAX_TURNS }}" --model "${{ env.CLAUDE_MODEL }}" 2>&1 || {
75+
echo "Claude Code review encountered an error"
76+
echo "## Claude Code Review"
77+
echo ""
78+
echo "⚠️ The automated review encountered an error. Please review manually."
79+
exit 0
80+
}
81+
SCRIPT_EOF
82+
83+
chmod +x /tmp/review.sh
84+
85+
- name: Run Claude Code Review
86+
id: review
87+
run: |
88+
/tmp/review.sh > /tmp/review_output.md 2>&1
89+
echo "Review completed"
90+
continue-on-error: true
91+
92+
- name: Post review as PR comment
93+
uses: actions/github-script@v7
94+
with:
95+
github-token: ${{ secrets.GITHUB_TOKEN }}
96+
script: |
97+
const fs = require('fs');
98+
let review = '';
99+
100+
try {
101+
review = fs.readFileSync('/tmp/review_output.md', 'utf8');
102+
} catch (error) {
103+
review = '⚠️ Unable to read review output. The review may have failed.';
104+
}
105+
106+
// Add header and metadata
107+
const comment = `## 🤖 Claude Code Review
108+
109+
**PR**: #${{ github.event.pull_request.number }}
110+
**Base**: \`${{ github.event.pull_request.base.ref }}\`
111+
**Head**: \`${{ github.event.pull_request.head.ref }}\`
112+
113+
---
114+
115+
${review}
116+
117+
---
118+
119+
<sub>Model: ${{ env.CLAUDE_MODEL }}</sub>`;
120+
121+
await github.rest.issues.createComment({
122+
owner: context.repo.owner,
123+
repo: context.repo.repo,
124+
issue_number: context.issue.number,
125+
body: comment
126+
});

0 commit comments

Comments
 (0)