|
| 1 | +--- |
| 2 | +allowed-tools: Bash(git *), Bash(gh *), Read, Edit, Write, Glob, Grep, Agent |
| 3 | +description: Babysit a PR - monitor, fix review bot suggestions, resolve conflicts, and merge when ready |
| 4 | +--- |
| 5 | + |
| 6 | +# Babysit PR |
| 7 | + |
| 8 | +Continuously monitor a pull request, read AI review bot comments (CodeRabbit, Sourcery, Gemini), fix suggested issues, resolve merge conflicts, and merge when ready. Reports total effort at completion. |
| 9 | + |
| 10 | +## Usage |
| 11 | + |
| 12 | +```bash |
| 13 | +/github:babysit-pr |
| 14 | +/github:babysit-pr --pr 123 |
| 15 | +/github:babysit-pr --auto-merge |
| 16 | +/github:babysit-pr --max-iterations 10 |
| 17 | +/github:babysit-pr --dry-run |
| 18 | +``` |
| 19 | + |
| 20 | +## Options |
| 21 | + |
| 22 | +- `--pr <number>`: Specific PR number (default: current branch's PR) |
| 23 | +- `--auto-merge`: Merge PR when CI passes and all review comments are resolved |
| 24 | +- `--max-iterations <n>`: Maximum fix iterations (default: 10) |
| 25 | +- `--dry-run`: Preview what would happen without making changes |
| 26 | + |
| 27 | +## How It Works |
| 28 | + |
| 29 | +### 1. Initial Setup |
| 30 | +- Verify we're on a feature branch (not main/master) |
| 31 | +- Find the PR for current branch (or use `--pr`) |
| 32 | +- Record start time for effort tracking |
| 33 | + |
| 34 | +### 2. Babysit Loop |
| 35 | + |
| 36 | +For each iteration: |
| 37 | + |
| 38 | +#### Step A: Wait for CI and Reviews |
| 39 | +- Poll CI status until all checks complete (or timeout after 15 min) |
| 40 | +- Wait for review bots to post their comments (30s grace period after CI) |
| 41 | + |
| 42 | +#### Step B: Fetch ALL Review Comments |
| 43 | +Read all review comments — both from AI bots and human reviewers: |
| 44 | + |
| 45 | +**Known AI Review Bots:** |
| 46 | + |
| 47 | +| Bot | Username Pattern | Comment Style | |
| 48 | +|-----|-----------------|---------------| |
| 49 | +| CodeRabbit | `coderabbitai[bot]` | Structured markdown with file paths, actionable suggestions, and code blocks | |
| 50 | +| Sourcery | `sourcery-ai[bot]` | Inline suggestions with refactoring advice and quality scores | |
| 51 | +| Gemini | `gemini-code-assist[bot]` | Code review with inline suggestions and summary | |
| 52 | + |
| 53 | +**Fetch all comments (bots + humans):** |
| 54 | +```bash |
| 55 | +# Top-level PR comments (summaries, discussion) |
| 56 | +gh api repos/{owner}/{repo}/issues/{pr}/comments |
| 57 | + |
| 58 | +# Inline review comments (line-specific suggestions from all reviewers) |
| 59 | +gh api repos/{owner}/{repo}/pulls/{pr}/comments |
| 60 | + |
| 61 | +# Review threads with verdicts |
| 62 | +gh api repos/{owner}/{repo}/pulls/{pr}/reviews |
| 63 | + |
| 64 | +# Human review requests with changes requested |
| 65 | +gh pr view $PR_NUMBER --json reviews --jq '.reviews[] | select(.state == "CHANGES_REQUESTED")' |
| 66 | +``` |
| 67 | + |
| 68 | +Both AI bot suggestions and human reviewer feedback are processed. AI bot comments are parsed for structured suggestions; human comments are read as instructions and addressed with code understanding. |
| 69 | + |
| 70 | +#### Step C: Check for Merge Conflicts |
| 71 | +```bash |
| 72 | +# Fetch latest base branch |
| 73 | +git fetch origin $(gh pr view --json baseRefName --jq '.baseRefName') |
| 74 | + |
| 75 | +# Check if merge is possible |
| 76 | +git merge-tree $(git merge-base HEAD origin/main) HEAD origin/main |
| 77 | +``` |
| 78 | + |
| 79 | +If conflicts exist: |
| 80 | +1. Attempt automatic resolution |
| 81 | +2. If auto-resolution fails, analyze conflict markers and resolve using code understanding |
| 82 | +3. Commit resolution |
| 83 | + |
| 84 | +#### Step D: Apply Fixes from ALL Review Suggestions |
| 85 | +For each unresolved review comment (bot or human): |
| 86 | +1. Parse the file path and line number from the comment |
| 87 | +2. Read the suggested change or instruction |
| 88 | +3. For bot comments: extract structured suggestions (code blocks, diffs) |
| 89 | +4. For human comments: read the instruction and apply using code understanding |
| 90 | +5. Apply the fix (not blind text replacement — understand intent) |
| 91 | +6. Track the fix in effort report |
| 92 | + |
| 93 | +#### Step E: Commit and Push |
| 94 | +```bash |
| 95 | +git add -A |
| 96 | +git commit -m "fix(pr): address review bot suggestions |
| 97 | +
|
| 98 | +- Applied N fixes from CodeRabbit/Sourcery/Gemini |
| 99 | +- Resolved merge conflicts (if any) |
| 100 | +
|
| 101 | +Co-Authored-By: duyetbot <duyetbot@users.noreply.github.com>" |
| 102 | + |
| 103 | +git push |
| 104 | +``` |
| 105 | + |
| 106 | +#### Step F: Check Completion |
| 107 | +Exit loop if: |
| 108 | +- CI passes AND no unresolved review comments → ready to merge |
| 109 | +- Max iterations reached → report and stop |
| 110 | + |
| 111 | +### 3. Merge (if `--auto-merge`) |
| 112 | +```bash |
| 113 | +gh pr merge $PR_NUMBER --squash --delete-branch |
| 114 | +``` |
| 115 | + |
| 116 | +### 4. Effort Report |
| 117 | + |
| 118 | +Print summary at completion: |
| 119 | + |
| 120 | +``` |
| 121 | +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ |
| 122 | +PR #123: Feature title |
| 123 | +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ |
| 124 | +
|
| 125 | +Effort Summary: |
| 126 | + Iterations: 3 |
| 127 | + Fixes applied: 7 |
| 128 | + CodeRabbit: 4 |
| 129 | + Sourcery: 2 |
| 130 | + Gemini: 1 |
| 131 | + Conflicts resolved: 1 |
| 132 | + Total duration: 12m 34s |
| 133 | +
|
| 134 | +Result: ✅ Merged successfully |
| 135 | +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ |
| 136 | +``` |
| 137 | + |
| 138 | +## Exit Conditions |
| 139 | + |
| 140 | +The loop exits when: |
| 141 | +- ✅ CI passes AND all review suggestions (bot + human) addressed → merge (if `--auto-merge`) |
| 142 | +- ⚠️ Max iterations reached → report status and stop |
| 143 | +- ⚠️ Unresolvable conflict or error → report and stop |
| 144 | +- ⚠️ Manual interrupt (Ctrl+C) |
| 145 | + |
| 146 | +## Supported Review Bots |
| 147 | + |
| 148 | +### CodeRabbit (`coderabbitai[bot]`) |
| 149 | +- Posts a summary comment with overall review |
| 150 | +- Leaves inline comments on specific lines with code suggestions |
| 151 | +- Uses collapsible sections for detailed analysis |
| 152 | +- Suggestions often include replacement code blocks |
| 153 | + |
| 154 | +### Sourcery (`sourcery-ai[bot]`) |
| 155 | +- Posts inline suggestions with refactoring advice |
| 156 | +- Provides quality metrics (complexity, readability) |
| 157 | +- Suggestions include "before" and "after" code |
| 158 | +- Labels suggestions by type: bug, refactoring, style |
| 159 | + |
| 160 | +### Gemini (`gemini-code-assist[bot]`) |
| 161 | +- Posts review summary with severity levels |
| 162 | +- Leaves inline comments with suggested fixes |
| 163 | +- Groups findings by category (security, performance, style) |
| 164 | + |
| 165 | +## Examples |
| 166 | + |
| 167 | +### Basic babysit |
| 168 | +```bash |
| 169 | +# On a feature branch with an open PR |
| 170 | +git checkout feat/new-feature |
| 171 | +/github:babysit-pr |
| 172 | +``` |
| 173 | + |
| 174 | +### Babysit and auto-merge |
| 175 | +```bash |
| 176 | +/github:babysit-pr --auto-merge |
| 177 | +``` |
| 178 | + |
| 179 | +### Babysit specific PR with limited iterations |
| 180 | +```bash |
| 181 | +/github:babysit-pr --pr 456 --max-iterations 3 |
| 182 | +``` |
| 183 | + |
| 184 | +### Preview mode |
| 185 | +```bash |
| 186 | +/github:babysit-pr --dry-run |
| 187 | +``` |
| 188 | + |
| 189 | +## Continuous Monitoring with /loop |
| 190 | + |
| 191 | +For long-running PRs, combine with `/loop` for periodic checks: |
| 192 | + |
| 193 | +```bash |
| 194 | +# Check every 10 minutes, auto-merge when ready |
| 195 | +/loop 10m /github:babysit-pr --auto-merge |
| 196 | + |
| 197 | +# Check every 5 minutes for a specific PR |
| 198 | +/loop 5m /github:babysit-pr --pr 123 --auto-merge |
| 199 | +``` |
| 200 | + |
| 201 | +## Related Commands |
| 202 | + |
| 203 | +- `/github:watch-and-fix` - Simpler CI-focused watch loop (no bot parsing) |
| 204 | +- `/fix:and-update-pr` - Single-iteration fix and push |
| 205 | +- `/github:bulk-merge-prs` - Merge multiple approved PRs |
0 commit comments