Skip to content

Commit 0f0c8e6

Browse files
claudeduyetbot
andcommitted
feat(github): add review-and-merge command for bulk PR processing
Scans all open PRs, reads CodeRabbit/bot comments, fixes issues, resolves conflicts, and merges in parallel using sub-agents. Co-Authored-By: duyetbot <duyetbot@users.noreply.github.com>
1 parent 56472cd commit 0f0c8e6

1 file changed

Lines changed: 183 additions & 0 deletions

File tree

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
---
2+
allowed-tools: Bash(git *), Bash(gh *), Bash(sleep *), Bash(pkill *), Bash(bun *), Read, Edit, Write, Glob, Grep, Agent
3+
description: Review all open PRs, fix CodeRabbit/bot comments, resolve conflicts, and merge in parallel
4+
---
5+
6+
# Review and Merge All PRs
7+
8+
Scan all open pull requests, read AI review bot comments (CodeRabbit, Sourcery, Gemini), fix issues, resolve merge conflicts, and merge when ready. Processes PRs in parallel using sub-agents.
9+
10+
## Usage
11+
12+
```bash
13+
/github:review-and-merge
14+
/github:review-and-merge --pr 123,456
15+
/github:review-and-merge --skip 789
16+
/github:review-and-merge --dry-run
17+
```
18+
19+
## Options
20+
21+
- `--pr <numbers>`: Only process specific PRs (comma-separated)
22+
- `--skip <numbers>`: Skip specific PRs
23+
- `--dry-run`: Preview actions without making changes
24+
- `--no-merge`: Fix issues but don't merge
25+
26+
## Process
27+
28+
### Phase 1: Triage All Open PRs
29+
30+
```bash
31+
# List all open PRs with review status
32+
gh pr list --state open --json number,title,headRefName,reviewDecision,mergeable,mergeStateStatus,statusCheckRollup,reviews
33+
34+
# Categorize each PR:
35+
# A) CHANGES_REQUESTED by CodeRabbit → needs fixes
36+
# B) Build/CI failures → investigate
37+
# C) Merge conflicts → needs rebase
38+
# D) Only known failures (Workers Builds, e2e) → can merge with --admin
39+
# E) Clean and approved → merge immediately
40+
```
41+
42+
Display a triage table:
43+
```
44+
| PR | Title | Review | Mergeable | Action |
45+
|----|-------|--------|-----------|--------|
46+
```
47+
48+
### Phase 2: Process PRs in Parallel
49+
50+
Launch sub-agents for each category. Use `run_in_background: true` for parallel execution.
51+
52+
#### Category A: Fix CodeRabbit Issues
53+
54+
For each PR with CHANGES_REQUESTED:
55+
56+
```bash
57+
# Get CodeRabbit review comments
58+
gh api repos/{owner}/{repo}/pulls/{pr}/reviews \
59+
--jq '.[] | select(.user.login == "coderabbitai[bot]") | {state: .state, body: .body}'
60+
61+
gh api repos/{owner}/{repo}/pulls/{pr}/comments \
62+
--jq '.[] | select(.user.login == "coderabbitai[bot]") | {path: .path, line: .line, body: .body}'
63+
```
64+
65+
Spawn an agent per PR:
66+
- Checkout the branch
67+
- Read the CodeRabbit comments
68+
- Read the affected files
69+
- Fix ALL issues raised
70+
- Run build verification (`bun run build` or project-specific)
71+
- Commit with semantic format + co-authorship
72+
- Push changes
73+
74+
#### Category B: Investigate Build Failures
75+
76+
For each PR with real build failures (not known CI issues):
77+
78+
```bash
79+
# Get failed check logs
80+
gh run view <run_id> --log-failed | grep -i "error\|Error\|FAIL" | head -30
81+
```
82+
83+
- Identify if failure is code issue vs CI infrastructure
84+
- If code issue: spawn fix agent
85+
- If CI issue (missing secrets, flaky test): note and proceed to merge with --admin
86+
87+
#### Category C: Resolve Merge Conflicts
88+
89+
For PRs that are CONFLICTING:
90+
91+
```bash
92+
git fetch origin
93+
git checkout <branch>
94+
git rebase origin/main
95+
# Resolve conflicts: keep BOTH sides merged
96+
git rebase --continue
97+
bun run check:fix # Fix lint/format
98+
git push --force-with-lease
99+
```
100+
101+
If multiple PRs conflict on the same files (cascade pattern):
102+
- Merge non-overlapping PRs first
103+
- Then process overlapping PRs sequentially (each merge changes the base)
104+
105+
#### Category D: Merge Clean PRs
106+
107+
PRs with only known CI failures and no review issues:
108+
109+
```bash
110+
gh pr merge <number> --squash --admin \
111+
--subject "<semantic title> (#<number>)"
112+
```
113+
114+
Known failures to ignore:
115+
- `Workers Builds` — always fails on non-main branches
116+
- `e2e-test` — cancelled/flaky
117+
- `unit-tests` — known Jest hanging issue
118+
- `claude-review` — config issues
119+
120+
### Phase 3: Post-Fix Verification
121+
122+
After agents push fixes:
123+
1. Check if CodeRabbit re-reviewed and approved
124+
2. Check if merge conflicts appeared (cascade from other merges)
125+
3. Rebase if needed
126+
4. Merge with `--admin` when ready
127+
128+
### Phase 4: Report
129+
130+
Print summary of all actions taken:
131+
132+
```
133+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
134+
PR Review & Merge Summary
135+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
136+
137+
Merged:
138+
#938 feat(agents): add ask_user tool
139+
#939 feat(agents): add detect_anomalies tool
140+
...
141+
142+
Fixed & Merged:
143+
#932 fix(explain): CodeRabbit issues resolved
144+
#936 feat(mcp): CodeRabbit issues resolved
145+
146+
Still Open:
147+
#123 reason: unresolvable conflict
148+
149+
Total: 15 merged, 2 fixed, 1 remaining
150+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
151+
```
152+
153+
## Key Patterns
154+
155+
### Cascade Conflict Strategy
156+
157+
When multiple PRs modify the same files:
158+
1. Identify overlapping file sets across all PRs
159+
2. Group by conflict clusters
160+
3. Merge non-overlapping PRs first (in parallel)
161+
4. Process overlapping PRs sequentially (oldest first)
162+
5. After each merge, rebase remaining PRs in the cluster
163+
164+
### Agent Delegation
165+
166+
- Use `team-agents:senior-engineer` for CodeRabbit fixes and conflict resolution
167+
- Use `run_in_background: true` for parallel processing
168+
- Limit to 3-4 concurrent agents to avoid OOM on builds
169+
- Each agent: checkout → fix → build → commit → push
170+
171+
### Commit Convention
172+
173+
All fix commits must include:
174+
```
175+
Co-Authored-By: duyetbot <duyetbot@users.noreply.github.com>
176+
```
177+
178+
### Safety
179+
180+
- Always use `--admin` flag for merging (bypasses known-broken checks)
181+
- Never force-push to main
182+
- Use `--force-with-lease` for branch pushes (prevents overwriting others' work)
183+
- Check mergeability before attempting merge

0 commit comments

Comments
 (0)