Skip to content

Commit 4520043

Browse files
♻️ refactor(ci): post PR reviews as inline threaded comments (#82)
Rework the Claude Code Review workflow to submit a single review with per-line inline comments (severity-tagged 🔴/🟡/🔵) and a structured summary body, instead of one monolithic PR comment. Why: - Inline comments attach feedback to the exact lines it concerns, matching the workflow already used by .claude/commands/review_pr.md. - A single review carries a clear verdict (REQUEST_CHANGES / APPROVE / COMMENT) derived from the highest-severity finding. Changes: - Replace the prompt with review criteria, inline-comment schema, a single-call submission recipe via `gh api POST /pulls/.../reviews`, and a summary-body template. - Drop redundant `gh pr view` / `gh pr diff` steps — PR context is already provided by claude-code-action; use ${{ github.repository }} and ${{ github.event.pull_request.head.sha }} instead. - Bump `pull-requests` permission from `read` to `write` so the job can POST the review. - Allow `Bash(gh api:*)` in claude_args. - Add `Bash(git checkout -b *)` to local settings allowlist. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent fe2c672 commit 4520043

2 files changed

Lines changed: 70 additions & 14 deletions

File tree

.claude/settings.local.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"Bash(git stash *)",
1010
"Bash(git fetch *)",
1111
"Bash(git pull *)",
12+
"Bash(git checkout -b *)",
1213

1314
"Bash(gh issue *)",
1415
"Bash(gh pr *)",

.github/workflows/claude-code-review.yml

Lines changed: 69 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
runs-on: ubuntu-latest
2222
permissions:
2323
contents: read
24-
pull-requests: read
24+
pull-requests: write
2525
issues: read
2626
id-token: write
2727

@@ -37,18 +37,73 @@ jobs:
3737
with:
3838
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
3939
prompt: |
40-
Please review this pull request and provide feedback on:
41-
- Code quality and best practices
42-
- Potential bugs or issues
43-
- Performance considerations
44-
- Security concerns
45-
- Test coverage
46-
47-
Use the repository's CLAUDE.md for guidance on style and conventions. Be constructive and helpful in your feedback.
48-
49-
Use `gh pr comment` with your Bash tool to leave your review as a comment on the PR.
50-
40+
Perform a thorough code review for this PR. PR context (title, body, diff, changed files)
41+
is already available to you — do not fetch it again. Follow CLAUDE.md for style/conventions.
42+
43+
## Review focus
44+
1. **Bugs & edge cases** — logic errors, unhandled exceptions, race conditions, off-by-one
45+
2. **Security** — injection, auth bypass, sensitive data exposure, insecure dependencies
46+
3. **Performance** — N+1 queries, blocking I/O, unnecessary re-computation, memory leaks
47+
4. **Code quality** — naming, duplication, complexity, consistency with existing patterns
48+
5. **Tests** — coverage of new logic, missing edge cases, weak assertions
49+
6. **Breaking changes** — API contracts, DB migrations, backward compatibility
50+
7. **Documentation** — docstrings, README, changelog if needed
51+
52+
## Inline comment format
53+
Each comment targets a specific line in the **new** file version with:
54+
- `path` — repo-relative path
55+
- `line` — line number on the RIGHT side of the diff
56+
- `side` — `"RIGHT"`
57+
- `body` — starts with a severity tag, then a brief explanation and (when useful) a concrete fix in a fenced code block:
58+
- 🔴 `[CRITICAL]` — must be fixed before merge
59+
- 🟡 `[SUGGESTION]` — improvement, not blocking
60+
- 🔵 `[QUESTION]` — needs clarification from author
61+
62+
## Submitting the review
63+
Post **one** review (never a standalone PR comment, never multiple reviews) with all inline
64+
comments plus a summary body. Use this exact call:
65+
66+
```bash
67+
gh api repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/reviews \
68+
--method POST \
69+
--input - <<'EOF'
70+
{
71+
"commit_id": "${{ github.event.pull_request.head.sha }}",
72+
"body": "<summary, see below>",
73+
"event": "<REQUEST_CHANGES | APPROVE | COMMENT>",
74+
"comments": [
75+
{ "path": "relative/path.py", "line": 42, "side": "RIGHT", "body": "🔴 [CRITICAL] ..." }
76+
]
77+
}
78+
EOF
79+
```
80+
81+
**Event rule:**
82+
- `REQUEST_CHANGES` — at least one 🔴 CRITICAL issue
83+
- `APPROVE` — nothing found worth commenting on
84+
- `COMMENT` — only 🟡 suggestions or 🔵 questions
85+
86+
## Summary body structure
87+
```
88+
## 📋 PR Review — {PR title}
89+
90+
### 🔴 Critical Issues ({N})
91+
- `path/to/file.py:42` — short description
92+
93+
### 🟡 Suggestions ({N})
94+
- `path/to/file.py:17` — short description
95+
96+
### 🔵 Questions ({N})
97+
- Question for the author
98+
99+
### ✅ What's done well
100+
- Positive observations
101+
102+
---
103+
### Verdict: REQUEST_CHANGES | APPROVE | NEEDS DISCUSSION
104+
> One-sentence overall assessment.
105+
```
106+
51107
# See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md
52108
# or https://docs.anthropic.com/en/docs/claude-code/sdk#command-line for available options
53-
claude_args: '--allowed-tools "Bash(gh issue view:*),Bash(gh search:*),Bash(gh issue list:*),Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(gh pr list:*)"'
54-
109+
claude_args: '--allowed-tools "Bash(gh issue view:*),Bash(gh search:*),Bash(gh issue list:*),Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(gh pr list:*),Bash(gh api:*)"'

0 commit comments

Comments
 (0)