|
| 1 | +--- |
| 2 | +name: landed |
| 3 | +description: Post-merge lifecycle. Verifies merge CI, optional deployment checks, cleans up branches, and prepares next phase. |
| 4 | +allowed-tools: Bash, Read, Grep, Glob |
| 5 | +disable-model-invocation: true |
| 6 | +--- |
| 7 | + |
| 8 | +# Landed |
| 9 | + |
| 10 | +Post-merge lifecycle command. Run this after a PR is merged to verify CI, check deployments, clean up branches, and identify next steps. |
| 11 | + |
| 12 | +## Step 1: Detect Merged PR |
| 13 | + |
| 14 | +Identify the PR that was just merged. |
| 15 | + |
| 16 | +1. Run `git branch --show-current` to get the current branch |
| 17 | +2. If already on master: |
| 18 | + - Check `git reflog --oneline -20` for the previous branch name |
| 19 | + - If no branch found, ask the user for the PR number or branch name |
| 20 | +3. Look up the merged PR: |
| 21 | + |
| 22 | + ```bash |
| 23 | + gh pr list --state merged --head <branch> --json number,title,mergeCommit -L 1 |
| 24 | + ``` |
| 25 | + |
| 26 | +4. If no PR found: ask the user for the PR number directly |
| 27 | +5. Display: PR number, title, merge commit SHA |
| 28 | + |
| 29 | +**Pre-check**: Run `gh auth status` early. If not authenticated, stop and instruct the user to run `gh auth login`. |
| 30 | + |
| 31 | +## Step 2: Verify Merge CI |
| 32 | + |
| 33 | +Check that CI passed on the merge commit. |
| 34 | + |
| 35 | +1. List recent runs on master: |
| 36 | + |
| 37 | + ```bash |
| 38 | + gh run list --branch master -L 20 --json status,conclusion,databaseId,name,headSha |
| 39 | + ``` |
| 40 | + |
| 41 | +2. Filter to runs whose `headSha` matches the merge commit SHA |
| 42 | +3. Evaluate all matched runs: |
| 43 | + - **in_progress**: watch still-running run(s) with `gh run watch <id>` |
| 44 | + - **success**: all matched runs must be `completed` with `conclusion=success` to proceed |
| 45 | + - **failure**: show details via `gh run view <id> --log-failed` for each failing run |
| 46 | + - Ask: "Is this a recurring issue or specific to this PR?" |
| 47 | + - If recurring: suggest adding to `/done` validation or pre-merge CI |
| 48 | + - If specific: diagnose inline from the failed log output |
| 49 | + |
| 50 | +## Step 3: Deployment Verification (Configurable) |
| 51 | + |
| 52 | +Check for deployment status if configured. |
| 53 | + |
| 54 | +1. Check if `.claude/deploy.json` exists |
| 55 | +2. If it exists: |
| 56 | + - Read the file and iterate over configured environments |
| 57 | + - For each environment: |
| 58 | + - Watch the deployment workflow: `gh run list --workflow <workflow> --commit <merge-commit-sha> --json status,conclusion,databaseId` |
| 59 | + - If `health_check` URL is configured, fetch it and verify a 200 response |
| 60 | + - Report per-environment status (success/failure/in_progress) |
| 61 | +3. If no config file: |
| 62 | + - Ask the user: "Is there a deployment to verify? (skip if none)" |
| 63 | + - If user says no or skips: mark as "skipped" |
| 64 | + |
| 65 | +## Step 4: Branch Cleanup |
| 66 | + |
| 67 | +Switch to master and clean up the feature branch. |
| 68 | + |
| 69 | +1. `git checkout master && git pull --rebase` |
| 70 | +2. Delete local branch: `git branch -d <branch>` (safe delete, will fail if unmerged) |
| 71 | +3. Check if remote branch still exists: `git ls-remote --heads origin <branch>` |
| 72 | +4. If remote branch exists: |
| 73 | + - Ask the user before deleting: "Delete remote branch origin/<branch>?" |
| 74 | + - If approved: `git push origin --delete <branch>` |
| 75 | + - If denied: note "kept" in summary |
| 76 | +5. If remote branch already deleted (e.g., GitHub auto-delete): note "already deleted by GitHub" in summary |
| 77 | + |
| 78 | +**Edge case**: If already on master and the branch was already deleted locally, skip local deletion gracefully. |
| 79 | + |
| 80 | +## Step 5: Next Phase (P-scope Only) |
| 81 | + |
| 82 | +Check if there is more planned work. |
| 83 | + |
| 84 | +1. Read `docs/IMPLEMENTATION_PLAN.md` |
| 85 | +2. If the file exists, check the "Quick Status Summary" table near the top for any phase whose status is not "Complete": |
| 86 | + - Identify the next incomplete phase |
| 87 | + - Summarize what it covers and any noted dependencies |
| 88 | +3. If all phases show "Complete" or no plan file exists: skip this step |
| 89 | + |
| 90 | +## Step 6: Summary Report |
| 91 | + |
| 92 | +Output a summary of everything that happened: |
| 93 | + |
| 94 | +```text |
| 95 | +# Landed |
| 96 | +
|
| 97 | +PR: #N "<title>" merged into master |
| 98 | +CI: PASS (run #ID) | FAIL (run #ID) | WATCHING |
| 99 | +Deploy: verified / skipped / failed |
| 100 | +
|
| 101 | +## Cleanup |
| 102 | +- Deleted local branch: <branch> |
| 103 | +- Deleted remote branch: <branch> [or "kept" or "already deleted by GitHub"] |
| 104 | +- Now on: master (up to date) |
| 105 | +
|
| 106 | +## Next Steps |
| 107 | +- [next phase summary / "Ready for new work" / "Project complete"] |
| 108 | +``` |
| 109 | + |
| 110 | +## Edge Cases |
| 111 | + |
| 112 | +- **Already on master**: check `git reflog` for previous branch, or ask the user |
| 113 | +- **PR not found via branch name**: ask the user for the PR number |
| 114 | +- **Remote branch already deleted**: GitHub auto-delete is common; handle gracefully |
| 115 | +- **gh not authenticated**: check `gh auth status` early and stop with instructions |
| 116 | +- **No CI runs found**: report "no CI runs found for merge commit" and proceed |
0 commit comments