Skip to content

Commit a7cc3c7

Browse files
committed
Merge branch 'main' into feature/38-abort-finish-when-behind-remote
2 parents b44fc81 + 3f3a20c commit a7cc3c7

File tree

8 files changed

+502
-77
lines changed

8 files changed

+502
-77
lines changed
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
# Code Review Skill
2+
3+
PR code review mechanics: create reviews via GitHub API, post inline comments, respond to mentions.
4+
5+
## Input Context
6+
7+
The workflow provides:
8+
- `EVENT`: GitHub event type (`pull_request`, `issue_comment`, `pull_request_review_comment`)
9+
- `REPO`: Repository in `owner/repo` format
10+
- `PR_NUMBER`: Pull request number
11+
- `COMMENT`: Comment body (empty for `pull_request` events)
12+
13+
## Execution Context Detection
14+
15+
```bash
16+
echo "GITHUB_ACTIONS=${GITHUB_ACTIONS:-not_set} CI=${CI:-not_set}"
17+
```
18+
19+
**Execution modes:**
20+
- **CI mode**: `GITHUB_ACTIONS=true` or `CI=true` — Posts reviews to GitHub
21+
- **Local mode**: Neither set — Auto-enables dry-run, outputs review to console
22+
23+
When running locally, inform the user:
24+
> "Running in local mode — dry-run enabled automatically. Review output will be displayed but not posted to GitHub."
25+
26+
---
27+
28+
## Intent Detection
29+
30+
```
31+
If EVENT == "pull_request":
32+
→ INTENT = "review"
33+
34+
If EVENT == "issue_comment" or "pull_request_review_comment":
35+
If COMMENT contains "@claude review" or "@claude re-review":
36+
→ INTENT = "review"
37+
Else:
38+
→ INTENT = "respond"
39+
```
40+
41+
---
42+
43+
## Loading Guidelines
44+
45+
Before reviewing or responding, check for project-specific guidelines:
46+
47+
1. **Read CLAUDE.md** (if exists) - may contain review instructions
48+
2. **Follow references** - if CLAUDE.md mentions other files (e.g., "see `REVIEW_GUIDELINES.md`"), read them
49+
3. **Check common locations**: `REVIEW_GUIDELINES.md`, `.github/CONTRIBUTING.md`, `docs/code-standards.md`
50+
51+
**Use project guidelines for:**
52+
- What to focus on in reviews
53+
- Review summary format
54+
- Inline comment format
55+
- Response format/tone
56+
57+
**If no guidelines found, use defaults:**
58+
59+
1. **Test Coverage** - Sufficient tests covering success, error, and edge cases
60+
2. **Guidelines & Architecture** - Follows coding guidelines and project patterns
61+
3. **Code Quality** - No ignored errors, unnecessary complexity, or dead code
62+
4. **Security** - No injection vulnerabilities, path traversal, or exposed secrets
63+
64+
Use a concise and direct tone. Put detailed feedback in inline comments with fix prompts.
65+
66+
---
67+
68+
## Action: Review
69+
70+
### Pre-Review Check
71+
72+
Determine what needs reviewing:
73+
74+
```bash
75+
# Get Claude's previous reviews
76+
LAST_REVIEW=$(gh api repos/$REPO/pulls/$PR_NUMBER/reviews \
77+
--jq '[.[] | select(.user.login == "github-actions[bot]" or .user.login == "claude[bot]")] | sort_by(.submitted_at) | last')
78+
79+
# Get current HEAD commit
80+
CURRENT_HEAD=$(gh pr view $PR_NUMBER --json headRefOid --jq '.headRefOid')
81+
82+
# Get commit SHA from last review
83+
LAST_REVIEW_COMMIT=$(echo "$LAST_REVIEW" | jq -r '.commit_id // empty')
84+
```
85+
86+
**Decision:**
87+
- No previous review → Full review (`gh pr diff $PR_NUMBER`)
88+
- Same commit → Post "No new changes to review"
89+
- New commits in history → Incremental review
90+
- Last commit not in history → Force-push handling
91+
92+
### Incremental Review
93+
94+
```bash
95+
git diff $LAST_REVIEW_COMMIT..$CURRENT_HEAD
96+
```
97+
98+
Only comment on lines changed in new commits.
99+
100+
### Force-Push Handling
101+
102+
```bash
103+
git merge-base --is-ancestor $LAST_REVIEW_COMMIT $CURRENT_HEAD
104+
# Exit 0 = normal push, non-zero = force-push
105+
```
106+
107+
When force-push detected:
108+
1. Full review against base branch
109+
2. Fetch previous comments: `gh api repos/$REPO/pulls/$PR_NUMBER/comments`
110+
3. Skip re-commenting on same file+line+issue
111+
112+
### Submitting the Review
113+
114+
Use GitHub's Reviews API to submit review with inline comments:
115+
116+
```bash
117+
COMMIT_SHA=$(gh pr view $PR_NUMBER --json headRefOid --jq '.headRefOid')
118+
119+
cat > /tmp/review.json << 'EOF'
120+
{
121+
"body": "Review summary here (general remarks, not file-specific)",
122+
"event": "COMMENT",
123+
"commit_id": "SHA_PLACEHOLDER",
124+
"comments": [
125+
{"path": "src/file.js", "line": 42, "body": "Inline feedback here"}
126+
]
127+
}
128+
EOF
129+
130+
sed -i.bak "s/SHA_PLACEHOLDER/$COMMIT_SHA/" /tmp/review.json && rm /tmp/review.json.bak
131+
gh api repos/$REPO/pulls/$PR_NUMBER/reviews --input /tmp/review.json
132+
```
133+
134+
**Review structure:**
135+
- `body`: General remarks and proposals not tied to specific files
136+
- `comments`: Array of inline comments on specific lines
137+
- `event`: "COMMENT", "APPROVE", or "REQUEST_CHANGES"
138+
139+
**Line numbers:**
140+
- `line` = line number in new file version (right side of diff)
141+
- For deleted lines, add `"side": "LEFT"` to comment object
142+
143+
---
144+
145+
## Action: Respond
146+
147+
Handle @claude mentions that aren't review requests.
148+
149+
### Fetch Context
150+
151+
```bash
152+
# Get review comments (inline on code)
153+
gh api repos/$REPO/pulls/$PR_NUMBER/comments --paginate
154+
155+
# Get issue comments (general PR discussion)
156+
gh api repos/$REPO/issues/$PR_NUMBER/comments --paginate
157+
```
158+
159+
### Responding
160+
161+
```bash
162+
# Reply to inline review comment
163+
gh api repos/$REPO/pulls/$PR_NUMBER/comments/$COMMENT_ID/replies \
164+
-f body="Response here"
165+
166+
# Reply to general PR comment
167+
gh pr comment $PR_NUMBER --body "Response here"
168+
```
169+
170+
Respond based on the question/request. If project guidelines specify a response format, use it.
171+
172+
---
173+
174+
## Dry Run Mode
175+
176+
When `--dry-run` is passed OR running in local mode (no CI environment detected):
177+
- Analyze normally but DO NOT post to GitHub
178+
- Output what would be posted
179+
180+
```
181+
DRY RUN - No changes will be made
182+
183+
Would submit review to PR #123:
184+
Event: COMMENT
185+
Body: "..."
186+
187+
Inline comments (3):
188+
src/file.js:10 - "..."
189+
src/file.js:25 - "..."
190+
src/api.js:100 - "..."
191+
```

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

Lines changed: 8 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -24,59 +24,14 @@ Perform a comprehensive self-review of changes before creating a pull request.
2424

2525
3. **Review Against Guidelines**
2626

27-
### CODING_GUIDELINES.md Checklist
28-
29-
**Architecture**
30-
- [ ] Three-layer command pattern followed (Cobra → Wrapper → Execute)
31-
- [ ] Config loaded once and passed through
32-
- [ ] Using `internal/git/` wrappers, not direct git calls
33-
- [ ] Custom error types from `internal/errors`
34-
35-
**Code Style**
36-
- [ ] Imports organized: stdlib, third-party, local
37-
- [ ] Naming conventions followed
38-
- [ ] Exported functions documented
39-
- [ ] No ignored errors
40-
41-
**Configuration Precedence**
42-
- [ ] Three-layer hierarchy: defaults → git config → flags
43-
- [ ] Pointer types for optional booleans
44-
- [ ] Flags always win
45-
46-
**Anti-Engineering**
47-
- [ ] No unnecessary abstractions
48-
- [ ] No premature optimization
49-
- [ ] Changes focused on the task
50-
51-
### TESTING_GUIDELINES.md Checklist
52-
53-
**Test Structure**
54-
- [ ] One test case per function (no table-driven for integration)
55-
- [ ] Descriptive test names
56-
- [ ] Test comments with Steps section
57-
58-
**Test Implementation**
59-
- [ ] Using testutil helpers
60-
- [ ] Proper setup/cleanup
61-
- [ ] Testing success and error paths
62-
63-
**Working Directory**
64-
- [ ] Using `cmd.Dir`, not `os.Chdir()` where possible
65-
- [ ] If `os.Chdir()` used, proper save/restore
66-
67-
### COMMIT_GUIDELINES.md Checklist
68-
69-
- [ ] Commit messages follow format
70-
- [ ] Subject line ≤50 characters
71-
- [ ] Type matches change (feat/fix/refactor/test/docs)
72-
- [ ] Issue referenced in footer
73-
- [ ] No AI attribution lines
74-
75-
### Documentation Checklist
76-
77-
- [ ] Manpage updated if command/options changed
78-
- [ ] Config documentation updated if config changed
79-
- [ ] Help text updated
27+
Review the code against **[REVIEW_GUIDELINES.md](../../../REVIEW_GUIDELINES.md)**, which covers:
28+
- Architecture checklist
29+
- Code style checklist
30+
- Configuration precedence checklist
31+
- Anti-over-engineering checklist
32+
- Testing checklist
33+
- Commit message checklist
34+
- Documentation checklist
8035

8136
4. **Code Quality Checks**
8237
```bash
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Claude PR Review
2+
3+
on:
4+
issue_comment:
5+
types: [created]
6+
pull_request_review_comment:
7+
types: [created]
8+
pull_request:
9+
types: [opened, synchronize, labeled]
10+
11+
jobs:
12+
claude-review:
13+
runs-on: ubuntu-latest
14+
# Run when:
15+
# 1. @claude is mentioned in a comment, OR
16+
# 2. PR has 'claude-review' label (on open, push, or label added)
17+
if: >
18+
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
19+
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
20+
(github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'claude-review'))
21+
22+
permissions:
23+
contents: read
24+
pull-requests: write
25+
issues: read
26+
id-token: write
27+
28+
steps:
29+
- name: Checkout repository
30+
uses: actions/checkout@v4
31+
with:
32+
fetch-depth: 0
33+
34+
- name: Run Claude
35+
uses: anthropics/claude-code-action@v1
36+
with:
37+
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
38+
prompt: |
39+
EVENT: ${{ github.event_name }}
40+
REPO: ${{ github.repository }}
41+
PR_NUMBER: ${{ github.event.pull_request.number || github.event.issue.number }}
42+
COMMENT: ${{ github.event.comment.body }}
43+
44+
Follow .claude/skills/code-review/SKILL.md to handle this event.
45+
46+
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:*),Bash(cat:*),Bash(sed:*),Read,Write,Edit"'

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ For comprehensive development information, see:
4747
- **[CONFIGURATION.md](CONFIGURATION.md)** - Complete configuration reference and examples
4848
- **[TESTING_GUIDELINES.md](TESTING_GUIDELINES.md)** - Testing methodology and practices
4949
- **[COMMIT_GUIDELINES.md](COMMIT_GUIDELINES.md)** - Commit message standards and best practices
50+
- **[REVIEW_GUIDELINES.md](REVIEW_GUIDELINES.md)** - Code review checklist and process
5051
- **[RELEASING.md](RELEASING.md)** - Release process and versioning
5152
- **[.github/copilot-instructions.md](.github/copilot-instructions.md)** - GitHub Copilot context and patterns
5253

COMMIT_GUIDELINES.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ Use the following structure for commit messages:
2424

2525
### Body (Optional but Recommended)
2626

27-
- **Length**: Wrap at 72 characters per line
27+
- **Length**: Hard wrap lines at 72 characters
2828
- **Purpose**: Explain the "what" and "why", not the "how"
29-
- **Format**: Use flowing paragraphs without hard line breaks
29+
- **Format**: Use paragraphs separated by blank lines
3030
- **Lists**: Use bullet points for multiple related changes
3131

3232
### Footer (Optional)
@@ -119,7 +119,7 @@ Adds comprehensive documentation about git-flow default branches and settings to
119119
- **Don't exceed line limits**: Keep subject under 50 chars, body under 72
120120
- **Don't mix concerns**: Separate unrelated changes into different commits
121121
- **Don't include file lists**: Git tracks files automatically
122-
- **Don't use hard line breaks**: Let text flow naturally in paragraphs
122+
- **Don't exceed 72 characters per line**: Hard wrap the body at 72 columns
123123
- **Don't commit broken code**: Each commit should represent a working state
124124
- **Don't include AI attribution**: Avoid "Generated with Claude Code" or similar AI-generated footers
125125

CONTRIBUTING.md

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -146,22 +146,13 @@ By participating in this project, you agree to:
146146

147147
### Review Process
148148

149-
1. **Initial Review**
150-
- Code style and formatting
151-
- Test coverage and quality
152-
- Documentation completeness
153-
- Performance implications
154-
155-
2. **Approval Requirements**
156-
- At least one maintainer approval
157-
- All CI checks passing
158-
- Documentation updated
159-
- Tests passing
160-
161-
3. **Merge Process**
162-
- Squash commits if requested
163-
- Rebase on latest main branch
164-
- Clean commit history
149+
All code changes are reviewed according to [REVIEW_GUIDELINES.md](REVIEW_GUIDELINES.md), which covers:
150+
- Code review checklist (architecture, style, testing, documentation)
151+
- Issue categories (blocking, warnings, suggestions)
152+
- Approval requirements
153+
- Merge process
154+
155+
Please review your changes against these guidelines before submitting a pull request.
165156

166157
## Getting Help
167158

0 commit comments

Comments
 (0)