Skip to content

Commit 69c95e8

Browse files
authored
Merge pull request #1 from node9-ai/dev
fix: merge latest dev updates into main
2 parents f5fe836 + c52fbb4 commit 69c95e8

2 files changed

Lines changed: 92 additions & 0 deletions

File tree

‎.github/workflows/ai-review.yml‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: AI Code Review
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
7+
jobs:
8+
review:
9+
name: Gemini Code Review
10+
runs-on: ubuntu-latest
11+
# Skip if the PR was opened by the bot itself
12+
if: github.actor != 'github-actions[bot]'
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Install dependencies
18+
run: npm install @anthropic-ai/sdk @octokit/rest
19+
20+
- name: Run AI Review
21+
env:
22+
GITHUB_TOKEN: ${{ secrets.AUTO_PR_TOKEN }}
23+
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
24+
PR_NUMBER: ${{ github.event.pull_request.number }}
25+
run: node scripts/ai-review.mjs

‎scripts/ai-review.mjs‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import Anthropic from "@anthropic-ai/sdk";
2+
import { Octokit } from "@octokit/rest";
3+
4+
const prNumber = parseInt(process.env.PR_NUMBER);
5+
const githubToken = process.env.GITHUB_TOKEN;
6+
const [repoOwner, repoName] = (process.env.GITHUB_REPOSITORY || "").split("/");
7+
8+
const octokit = new Octokit({ auth: githubToken });
9+
10+
async function runReview() {
11+
try {
12+
console.log(`Fetching diff for PR #${prNumber}...`);
13+
const { data: prDiff } = await octokit.pulls.get({
14+
owner: repoOwner,
15+
repo: repoName,
16+
pull_number: prNumber,
17+
mediaType: { format: "diff" },
18+
});
19+
20+
if (!prDiff || prDiff.trim().length === 0) {
21+
console.log("Empty diff, skipping review.");
22+
return;
23+
}
24+
25+
const prompt = `You are a senior Python engineer reviewing a pull request for the Node9 Python SDK.
26+
Node9 is an execution security library — a @protect decorator that intercepts AI agent tool calls and asks for human approval before running them.
27+
28+
Review the following git diff and provide concise, actionable feedback. Focus on:
29+
- Correctness and edge cases
30+
- Security issues (this is a security library — be strict)
31+
- API design and usability for developers integrating with LangChain, CrewAI, etc.
32+
- Test coverage gaps
33+
- Anything that could break the daemon HTTP communication
34+
35+
If the changes look good with no issues, say so briefly.
36+
Do NOT rewrite the code. Just review it.
37+
Keep your review under 400 words.
38+
39+
## Git Diff:
40+
${prDiff}`;
41+
42+
console.log("Sending diff to Claude for review...");
43+
const client = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
44+
const message = await client.messages.create({
45+
model: "claude-sonnet-4-5",
46+
max_tokens: 1024,
47+
messages: [{ role: "user", content: prompt }],
48+
});
49+
50+
const review = message.content[0].text;
51+
52+
console.log("Posting review comment...");
53+
await octokit.issues.createComment({
54+
owner: repoOwner,
55+
repo: repoName,
56+
issue_number: prNumber,
57+
body: `## 🤖 Claude Code Review\n\n${review}\n\n---\n*Automated review by Claude Sonnet*`,
58+
});
59+
60+
console.log("Review posted successfully.");
61+
} catch (error) {
62+
console.error("Error:", error.message);
63+
process.exit(1);
64+
}
65+
}
66+
67+
runReview();

0 commit comments

Comments
 (0)