--- description: Review, checkout, test, and prepare PR merge for git/jj repos argument-hint: "[pr-url|number|branch|ref] [test-command]" --- # Review, checkout, test, and prepare PR merge Review PR end-to-end and prepare merge. Do **not** merge until explicit user OK. If `jj root` succeeds, use jj; otherwise use git. **PR**: $1 **Test command**: ${@:2} ## Forge CLI detection Detect from git remote URL: - `github.com` → `gh` - `codeberg.org` or any Forgejo instance → `fj` - bare git server → no forge CLI, generic git only - If forge CLI binary missing → fall back to generic git 0. **Resolve PR** - If `$1` is set, use it. - Else scan conversation history for a previously discussed PR (URL, number, branch). - If none found → stop, ask user to specify. 1. **Identify** - Detect VCS: `jj root` → jj, else git. - Detect forge CLI (above). - Resolve PR metadata: title, author, base, head, URL, status, CI, labels. - Fetch latest base/head: `jj git fetch` / `git fetch`. 2. **Protect local work** - `jj status` or `git status --short`. - Dirty unrelated work → do not overwrite. Prefer isolated jj workspace or git worktree. - Detect repo style: `jj workspace list` / `git worktree list`. 3. **Checkout** - jj: prefer `jj workspace add -r `. Otherwise `jj new ` when safe. - git: prefer worktree when dirty or isolation needed. Otherwise branch checkout when clean. - Forge CLI path: use for metadata/merge only. Use VCS-native fetch/checkout for files. - Generic path: fetch PR head ref or remote branch, then create branch/worktree/workspace. 4. **Review diff** - jj: `jj diff --from --to `. git: `git diff ...`. - Read relevant files, tests, docs, configs. - Check correctness, security, perf, API compat, migrations, UX, error handling. - Verify PR matches issue/description. 5. **Test** - If test command provided, run it. - Else infer from project files (README, package files, CI, justfile, Makefile). - Focused tests first, broader suite if reasonable. - Include lint/typecheck/build when conventional. 6. **Report** - PR summary - Checkout location + base/head SHAs/change IDs - Review findings: blockers / warnings / notes with file:line refs - Tests run: command → pass/fail - Merge readiness: READY | NOT READY - Exact merge plan/command to run after OK - If not ready, list minimal required fixes. 7. **Wait** - Stop after report. Ask for explicit OK to merge only if READY. - On OK: re-fetch, verify PR still current/mergeable, run critical checks, then merge using forge CLI or VCS-native (fast-forward preferred). Report final status. - After merge: offer to remove jj workspace or git worktree/branch.