Skip to content

Commit 6cbd6bf

Browse files
committed
Add Claude Code review skill, workflow, and CLAUDE.md
Set up automated PR review with Claude Code: - CLAUDE.md with repo context for arsenal - .claude/skills/review-pr/SKILL.md with review criteria - .github/workflows/review.yml calling reusable review workflow
1 parent 915163b commit 6cbd6bf

File tree

3 files changed

+183
-0
lines changed

3 files changed

+183
-0
lines changed

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

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
---
2+
name: review-pr
3+
description: Review a PR on arsenal (Scality's shared S3 utilities library for TypeScript/Node.js)
4+
argument-hint: <pr-number-or-url>
5+
disable-model-invocation: true
6+
allowed-tools: Read, 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+
| TypeScript correctness | Proper typing, no unnecessary `any`, consistent use of strict mode, correct generics usage |
42+
| Async error handling | Uncaught promise rejections, missing error callbacks, swallowed errors in streams. Double callbacks in try/catch blocks — watch for `try { cb(); } catch(err) { cb(err); }` where an exception after the first `cb()` triggers a second call |
43+
| 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) |
44+
| Stream handling | Backpressure, proper cleanup on error, no leaked file descriptors |
45+
| Dependency pinning | Git-based deps (werelogs, sproxydclient, httpagent) must pin to a tag, not a branch |
46+
| Logging | Proper use of werelogs, no `console.log` in production code, log levels match severity |
47+
| Model compatibility | Changes to data models (ObjectMD, BucketInfo, etc.) must preserve backward compatibility with older `mdModelVersion` |
48+
| Error handling | Proper use of ArsenalError, correct `.is` proxy checks, no swallowed errors |
49+
| API contract | Breaking changes to exported interfaces in `index.ts`, renamed or removed public methods |
50+
| Config changes | Backward compatibility, default values, constants changes |
51+
| Security | Injection risks, auth bypass, improper input validation, OWASP-relevant issues |
52+
| Breaking changes | Anything that changes public APIs or interfaces exported by this library |
53+
| Test coverage | New logic should have corresponding tests, existing tests should not be removed without justification |
54+
55+
4. **Deliver your review:**
56+
57+
### If CI mode: post to GitHub
58+
59+
#### Part A: Inline file comments
60+
61+
For each specific issue, post a comment on the exact file and line:
62+
63+
```bash
64+
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>"
65+
```
66+
67+
**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.
68+
69+
Each inline comment must:
70+
- Be short and direct — say what's wrong, why it's wrong, and how to fix it in 1-3 sentences
71+
- No filler, no complex words, no long explanations
72+
- When the fix is a concrete line change (not architectural), include a GitHub suggestion block so the author can apply it in one click:
73+
````
74+
```suggestion
75+
corrected-line-here
76+
```
77+
````
78+
Only suggest when you can show the exact replacement. For architectural or design issues, just describe the problem.
79+
Example with a suggestion block:
80+
```bash
81+
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' ...
82+
```
83+
- When the comment contains a suggestion block, use `$'...'` quoting with `\n` for code fence boundaries. Escape single quotes as `\'` (e.g., `don\'t`)
84+
- End with: `— Claude Code`
85+
86+
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.
87+
88+
#### Part B: Summary comment
89+
90+
```bash
91+
gh pr comment <number> --repo <owner/repo> --body "LGTM<br><br>Review by Claude Code"
92+
```
93+
94+
**The command must stay on a single bash line.** Never use newlines in bash commands — use `<br>` for line breaks in comment bodies.
95+
96+
Do not describe or summarize the PR. For each issue, state the problem on one line, then list one or more suggestions below it:
97+
98+
```
99+
- <issue>
100+
- <suggestion>
101+
- <suggestion>
102+
```
103+
104+
If no issues: just say "LGTM". End with: `Review by Claude Code`
105+
106+
### If local mode: output the review as text
107+
108+
Do NOT post anything to GitHub. Instead, output the review directly as text.
109+
110+
For each issue found, output:
111+
112+
```
113+
**<file_path>:<line_number>** — <what's wrong and how to fix it>
114+
```
115+
116+
When the fix is a concrete line change, include a fenced code block showing the suggested replacement.
117+
118+
At the end, output a summary section listing all issues. If no issues: just say "LGTM".
119+
120+
End with: `Review by Claude Code`
121+
122+
## What NOT to do
123+
124+
- Do not comment on markdown formatting preferences
125+
- Do not suggest refactors unrelated to the PR's purpose
126+
- Do not praise code — only flag problems or stay silent
127+
- If no issues are found, post only a summary saying "LGTM"
128+
- Do not flag style issues already covered by ESLint or the project's linting config

.github/workflows/review.yml

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

CLAUDE.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# arsenal
2+
3+
This is **Scality's shared utilities library** for S3 infrastructure components. It is a TypeScript/Node.js library providing foundational modules used across CloudServer, Backbeat, and other S3 platform services. It contains:
4+
5+
- Algorithms library: listing, caching, streaming, sorting (`lib/algos/`)
6+
- AWS v2/v4 authentication and Vault integration (`lib/auth/`)
7+
- Data models: BucketInfo, ObjectMD, ARN, and others (`lib/models/`)
8+
- S3 middleware: tagging, legal hold, lifecycle, conditional headers (`lib/s3middleware/`)
9+
- Storage backends: metadata (MongoDB, BucketClient, file) and data (file, AWS, Azure, GCP) (`lib/storage/`)
10+
- IAM policy evaluation (`lib/policyEvaluator/`)
11+
- S3 route definitions (`lib/s3routes/`)
12+
- Object versioning logic (`lib/versioning/`)
13+
- Custom error types with proxy-based `.is` checking (`lib/errors/`)
14+
- Git-based internal deps: werelogs, sproxydclient, httpagent
15+
16+
## Tech stack
17+
18+
- **Language:** TypeScript (compiled to ES2021/CommonJS)
19+
- **Runtime:** Node.js >= 20
20+
- **Build:** tsc + Babel
21+
- **Test:** Jest + ts-jest, Sinon, mongodb-memory-server
22+
- **Lint:** ESLint 9 flat config with @scality/eslint-config-scality
23+
- **CI:** GitHub Actions (lint, unit tests, functional tests, coverage)
24+
25+
## Key commands
26+
27+
```bash
28+
yarn install # Install deps and build (prepare hook)
29+
yarn test # Run Jest unit tests
30+
yarn lint # Run ESLint
31+
yarn build # Compile TypeScript
32+
```
33+
34+
## Conventions
35+
36+
- All imports at the top of the file, never inside functions or blocks
37+
- Strict TypeScript (`strict: true`)
38+
- Test files use `.spec.js` or `.spec.ts` suffix
39+
- Custom `ArsenalError` with `error.is.NoSuchEntity` proxy pattern
40+
- Metadata model version tracking (`mdModelVersion = 7`)

0 commit comments

Comments
 (0)