Skip to content

Commit cb71597

Browse files
committed
BB-748 add claude code review
1 parent 18f8666 commit cb71597

File tree

3 files changed

+153
-0
lines changed

3 files changed

+153
-0
lines changed

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

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
---
2+
name: review-pr
3+
description: Review a PR on backbeat (Node.js async queue and job manager for S3C and Artesca)
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+
| 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 usage | New or modified code should use async/await instead of callbacks when possible. 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+
| Kafka consumer/producer | Correct topic configuration, proper offset commits, consumer group handling, message serialization. Verify `onEntryCommittable` is always reachable. Check circuit breaker thresholds when adding new downstream topics |
44+
| Stream handling | Backpressure, proper cleanup on error, no leaked file descriptors, correct pipe chains |
45+
| Dependency pinning | Git-based deps (arsenal, vaultclient, bucketclient, werelogs, breakbeat, 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. Include enough context (bucket, object key, version, offset) for production troubleshooting |
47+
| Prometheus metrics | New metrics follow existing naming conventions (`s3_backbeat_*`), correct metric types (counter vs gauge vs histogram), bounded label cardinality — avoid per-connector or per-bucket labels that explode with scale |
48+
| Config changes | Backward compatibility, Joi schema updates match new fields, environment variable naming, default values. Env var overrides in `lib/Config.js` must stay consistent with the config file schema |
49+
| MongoDB / Redis resilience | Reconnection handling, proper timeouts on external calls, no indefinite waits. Network errors to MongoDB must not cause stuck tasks or silent data loss |
50+
| Extension architecture | Changes respect the pluggable extension pattern, no cross-extension coupling |
51+
| Security | Command injection, prototype pollution, unsafe deserialization, credential exposure in config/env vars, OWASP-relevant issues for Node.js |
52+
| Breaking changes | Anything that changes public APIs, Kafka message formats, inter-service contracts, or oplog/change stream projections |
53+
54+
4. **Deliver your review:**
55+
56+
### If CI mode: post to GitHub
57+
58+
#### Part A: Inline file comments
59+
60+
For each specific issue, post a comment on the exact file and line:
61+
62+
```bash
63+
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>"
64+
```
65+
66+
**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.
67+
68+
Each inline comment must:
69+
- Be short and direct — say what's wrong, why it's wrong, and how to fix it in 1-3 sentences
70+
- No filler, no complex words, no long explanations
71+
- When the fix is a concrete line change (not architectural), include a GitHub suggestion block so the author can apply it in one click:
72+
````
73+
```suggestion
74+
corrected-line-here
75+
```
76+
````
77+
Only suggest when you can show the exact replacement. For architectural or design issues, just describe the problem.
78+
Example with a suggestion block:
79+
```bash
80+
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' ...
81+
```
82+
- When the comment contains a suggestion block, use `$'...'` quoting with `\n` for code fence boundaries. Escape single quotes as `\'` (e.g., `don\'t`)
83+
- End with: `— Claude Code`
84+
85+
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.
86+
87+
#### Part B: Summary comment
88+
89+
```bash
90+
gh pr comment <number> --repo <owner/repo> --body "LGTM<br><br>Review by Claude Code"
91+
```
92+
93+
**The command must stay on a single bash line.** Never use newlines in bash commands — use `<br>` for line breaks in comment bodies.
94+
95+
Do not describe or summarize the PR. For each issue, state the problem on one line, then list one or more suggestions below it:
96+
97+
```
98+
- <issue>
99+
- <suggestion>
100+
- <suggestion>
101+
```
102+
103+
If no issues: just say "LGTM". End with: `Review by Claude Code`
104+
105+
### If local mode: output the review as text
106+
107+
Do NOT post anything to GitHub. Instead, output the review directly as text.
108+
109+
For each issue found, output:
110+
111+
```
112+
**<file_path>:<line_number>** — <what's wrong and how to fix it>
113+
```
114+
115+
When the fix is a concrete line change, include a fenced code block showing the suggested replacement.
116+
117+
At the end, output a summary section listing all issues. If no issues: just say "LGTM".
118+
119+
End with: `Review by Claude Code`
120+
121+
## What NOT to do
122+
123+
- Do not comment on markdown formatting preferences
124+
- Do not suggest refactors unrelated to the PR's purpose
125+
- Do not praise code — only flag problems or stay silent
126+
- If no issues are found, post only a summary saying "LGTM"
127+
- Do not flag style issues already covered by the project's linter (eslint with eslint-config-scality)

.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
@@ -0,0 +1,12 @@
1+
# Backbeat
2+
3+
This is a **Node.js asynchronous queue and job manager** for Scality's S3C and Artesca products. It processes metadata updates and dispatches background tasks via Kafka. It contains:
4+
5+
- Kafka consumers/producers (`lib/BackbeatConsumer.js`, `lib/BackbeatProducer.js`)
6+
- Pluggable extensions for replication, lifecycle, notifications, ingestion, GC (`extensions/`)
7+
- Queue population from MongoDB oplog and Metadata (raft) oplog (`lib/queuePopulator/`)
8+
- Management API and routes (`lib/api/`)
9+
- Configuration management with Joi validation (`lib/Config.js`)
10+
- Git-based internal deps: arsenal, vaultclient, bucketclient, werelogs, breakbeat, httpagent
11+
- CommonJS modules with callback-based async patterns
12+
- Mocha + Sinon test suites (`tests/unit/`, `tests/functional/`, `tests/behavior/`)

0 commit comments

Comments
 (0)