Skip to content

Commit ce85e41

Browse files
committed
CLDSRV-862: add automated PR review skill and CI workflow
1 parent 9b836b8 commit ce85e41

3 files changed

Lines changed: 151 additions & 0 deletions

File tree

.claude/skills/review-pr/SKILL.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
---
2+
name: review-pr
3+
description: Review a PR on cloudserver (S3-compatible object storage server in Node.js)
4+
argument-hint: <pr-number-or-url>
5+
disable-model-invocation: true
6+
allowed-tools: Bash(gh repo view *), Bash(gh pr view *), Bash(gh pr diff *), Bash(gh pr comment *), Bash(gh api *), Bash(git diff *), Bash(git log *), Bash(git show *)
7+
---
8+
9+
# Review GitHub PR
10+
11+
You are an expert code reviewer. Review this PR: $ARGUMENTS
12+
13+
## Determine PR target
14+
15+
Parse `$ARGUMENTS` to extract the repo and PR number:
16+
17+
- If arguments contain `REPO:` and `PR_NUMBER:` (CI mode), use those values directly.
18+
- If the argument is a GitHub URL (starts with `https://github.com/`), extract `owner/repo` and the PR number from it.
19+
- If the argument is just a number, use the current repo from `gh repo view --json nameWithOwner -q .nameWithOwner`.
20+
21+
## Output mode
22+
23+
- **CI mode** (arguments contain `REPO:` and `PR_NUMBER:`): post inline comments and summary to GitHub.
24+
- **Local mode** (all other cases): output the review as text directly. Do NOT post anything to GitHub.
25+
26+
## Steps
27+
28+
1. **Fetch PR details:**
29+
30+
```bash
31+
gh pr view <number> --repo <owner/repo> --json title,body,headRefOid,author,files
32+
gh pr diff <number> --repo <owner/repo>
33+
```
34+
35+
2. **Read changed files** to understand the full context around each change (not just the diff hunks).
36+
37+
3. **Analyze the changes** against these criteria:
38+
39+
| Area | What to check |
40+
|------|---------------|
41+
| Async error handling | Uncaught promise rejections, missing error callbacks, swallowed errors in streams. Double callbacks in try/catch blocks (callback called in try then again in catch). |
42+
| Async/await migration | When code is migrated from callbacks to async/await, verify: no leftover `callback` or `next` params, no mixed callback + promise patterns, proper try/catch around awaited calls, errors are re-thrown or handled (not silently swallowed). Watch for the anti-pattern: `try { ... cb(); } catch(err) { cb(err); }` where an exception after the first `cb()` triggers a second call. |
43+
| S3/API contract | Breaking changes to request/response formats, new error codes, header handling, missing XML response fields |
44+
| Dependency pinning | Git-based deps (arsenal, vaultclient, bucketclient, werelogs, utapi, scubaclient) must pin to a tag, not a branch |
45+
| Logging | Proper use of werelogs logger, no `console.log` in production code, log levels match severity |
46+
| Stream handling | Backpressure, proper cleanup on error (`.destroy()`), no leaked file descriptors, missing error event handlers |
47+
| Config changes | Backward compatibility with existing env vars and `config.json`, default values |
48+
| Security | Command injection, header injection, XML external entity attacks, path traversal, SSRF in multi-backend requests |
49+
| Breaking changes | Changes to public S3 API behavior, metadata schema changes, env var renames without backward compat |
50+
| Test quality | No `.only()` tests (eslint enforces this), assertions match the behavior being tested, `require()`/`import` at top of file (never inside `describe` or functions) |
51+
52+
4. **Deliver your review:**
53+
54+
### If CI mode: post to GitHub
55+
56+
#### Part A: Inline file comments
57+
58+
For each specific issue, post a comment on the exact file and line:
59+
60+
```bash
61+
gh api -X POST -H "Accept: application/vnd.github+json" "repos/<owner/repo>/pulls/<number>/comments" -f body="Your comment<br><br>— Claude Code" -f path="path/to/file" -F line=<line_number> -f side="RIGHT" -f commit_id="<headRefOid>"
62+
```
63+
64+
**The command must stay on a single bash line.** Never use newlines in bash commands — use `<br>` for line breaks in comment bodies. Never put `<br>` inside code blocks or suggestion blocks.
65+
66+
Each inline comment must:
67+
- Be short and direct — say what's wrong, why it's wrong, and how to fix it in 1-3 sentences
68+
- No filler, no complex words, no long explanations
69+
- When the fix is a concrete line change (not architectural), include a GitHub suggestion block so the author can apply it in one click:
70+
````
71+
```suggestion
72+
corrected-line-here
73+
```
74+
````
75+
Only suggest when you can show the exact replacement. For architectural or design issues, just describe the problem.
76+
Example with a suggestion block:
77+
```bash
78+
gh api ... -f body=$'Missing the shared-guidelines update command.<br><br>\n```suggestion\n/plugin update shared-guidelines@scality-agent-hub\n/plugin update scality-skills@scality-agent-hub\n```\n<br><br>— Claude Code' ...
79+
```
80+
- When the comment contains a suggestion block, use `$'...'` quoting with `\n` for code fence boundaries. Escape single quotes as `\'` (e.g., `don\'t`)
81+
- End with: `— Claude Code`
82+
83+
Use the line number from the **new version** of the file (the line number you'd see after the PR is merged), which corresponds to the `line` parameter in the GitHub API.
84+
85+
#### Part B: Summary comment
86+
87+
```bash
88+
gh pr comment <number> --repo <owner/repo> --body "LGTM<br><br>Review by Claude Code"
89+
```
90+
91+
**The command must stay on a single bash line.** Never use newlines in bash commands — use `<br>` for line breaks in comment bodies.
92+
93+
Do not describe or summarize the PR. For each issue, state the problem on one line, then list one or more suggestions below it:
94+
95+
```
96+
- <issue>
97+
- <suggestion>
98+
- <suggestion>
99+
```
100+
101+
If no issues: just say "LGTM". End with: `Review by Claude Code`
102+
103+
### If local mode: output the review as text
104+
105+
Do NOT post anything to GitHub. Instead, output the review directly as text.
106+
107+
For each issue found, output:
108+
109+
```
110+
**<file_path>:<line_number>** — <what's wrong and how to fix it>
111+
```
112+
113+
When the fix is a concrete line change, include a fenced code block showing the suggested replacement.
114+
115+
At the end, output a summary section listing all issues. If no issues: just say "LGTM".
116+
117+
End with: `Review by Claude Code`
118+
119+
## What NOT to do
120+
121+
- Do not comment on markdown formatting preferences
122+
- Do not suggest refactors unrelated to the PR's purpose
123+
- Do not praise code — only flag problems or stay silent
124+
- If no issues are found, post only a summary saying "LGTM"
125+
- Do not flag style issues already covered by the project's linter (eslint, biome, pylint, golangci-lint)

.github/workflows/review.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Code Review
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize]
6+
7+
jobs:
8+
review:
9+
uses: scality/workflows/.github/workflows/claude-code-review.yml@v2
10+
secrets:
11+
GCP_WORKLOAD_IDENTITY_PROVIDER: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}
12+
GCP_SERVICE_ACCOUNT: ${{ secrets.GCP_SERVICE_ACCOUNT }}
13+
ANTHROPIC_VERTEX_PROJECT_ID: ${{ secrets.ANTHROPIC_VERTEX_PROJECT_ID }}
14+
CLOUD_ML_REGION: ${{ secrets.CLOUD_ML_REGION }}

CLAUDE.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
# cloudserver
2+
3+
This is a **Node.js implementation of the S3 protocol**. It contains:
4+
5+
- S3 API route handlers (`lib/api/`) — 80+ operations
6+
- Authentication and authorization layers (`lib/auth/`)
7+
- Stream-based data path for object storage (`lib/data/`)
8+
- Multi-backend support: file, memory, AWS S3, Azure, GCP, Sproxyd
9+
- Metadata abstraction: LevelDB, MongoDB, bucketd (`lib/metadata/`)
10+
- Git-based internal deps: arsenal, vaultclient, bucketclient, werelogs, utapi, scubaclient
11+
- CommonJS modules, callback-based async (migrating to async/await), Mocha tests
12+
113
# CLAUDE.md
214

315
This file provides guidance to Claude Code (claude.ai/code) when working with

0 commit comments

Comments
 (0)