|
| 1 | +--- |
| 2 | +name: plane-close |
| 3 | +description: Post-merge cleanup. Updates the linked Plane.so issue to Done, posts a closing comment with merge SHA, and checks if blocked issues are now unblocked. Use when the user wants to close out a Plane issue after a PR is merged. |
| 4 | +argument-hint: "[PR number, URL, or blank for current branch]" |
| 5 | +allowed-tools: [Bash, Read, AskUserQuestion, mcp__plane__retrieve_work_item_by_identifier, mcp__plane__retrieve_work_item, mcp__plane__update_work_item, mcp__plane__create_work_item_comment, mcp__plane__list_work_item_relations, mcp__plane__list_states, mcp__plane__list_projects] |
| 6 | +--- |
| 7 | + |
| 8 | +# Plane Post-Merge Close |
| 9 | + |
| 10 | +After a PR is merged, update the linked Plane.so issue to Done, post a closing comment, and check if any blocked issues are now unblocked. |
| 11 | + |
| 12 | +## Input |
| 13 | + |
| 14 | +`$ARGUMENTS` may contain: |
| 15 | +- A PR number (e.g., `42`) |
| 16 | +- A PR URL (e.g., `https://github.com/org/repo/pull/42`) |
| 17 | +- `--issue ZEN-42` — skip PR lookup, close the issue directly |
| 18 | +- Empty — auto-detect the most recently merged PR for the current branch |
| 19 | + |
| 20 | +--- |
| 21 | + |
| 22 | +## Phase 1: Identify the Merged PR |
| 23 | + |
| 24 | +### Step 1: Resolve the PR |
| 25 | + |
| 26 | +If `$ARGUMENTS` contains a number or URL, use it directly. Otherwise, detect from the current branch: |
| 27 | + |
| 28 | +```bash |
| 29 | +gh pr view $(git branch --show-current) --json number,title,body,url,state,mergeCommit,headRefName |
| 30 | +``` |
| 31 | + |
| 32 | +If no PR found, try listing recent merged PRs: |
| 33 | + |
| 34 | +```bash |
| 35 | +gh pr list --state merged --limit 5 --json number,title,headRefName,mergedAt,url |
| 36 | +``` |
| 37 | + |
| 38 | +Present the list and use `AskUserQuestion` to let the user pick one. |
| 39 | + |
| 40 | +### Step 2: Verify the PR is merged |
| 41 | + |
| 42 | +```bash |
| 43 | +gh pr view <number> --json number,title,body,url,state,mergeCommit,headRefName,mergedAt |
| 44 | +``` |
| 45 | + |
| 46 | +If `state` is NOT `MERGED`, **stop immediately**: |
| 47 | +> "PR #<number> is not merged (state: <state>). This skill only processes merged PRs." |
| 48 | +
|
| 49 | +Extract and store: PR number, title, body, URL, merge SHA (short form), branch name, merged date. |
| 50 | + |
| 51 | +--- |
| 52 | + |
| 53 | +## Phase 2: Extract and Fetch the Plane Issue |
| 54 | + |
| 55 | +### Step 1: Extract the Plane identifier |
| 56 | + |
| 57 | +Search for `[A-Z]+-\d+` in this order: |
| 58 | +1. PR title |
| 59 | +2. PR body (look for `Plane Issue:`, `Issue:`, `Refs:`) |
| 60 | +3. Branch name |
| 61 | + |
| 62 | +If `$ARGUMENTS` contains `--issue <IDENTIFIER>`, use that directly. |
| 63 | + |
| 64 | +If no identifier found, use `AskUserQuestion`: |
| 65 | +> "No Plane issue identifier found. Provide the identifier (e.g., ZEN-42), or type 'skip' to skip Plane updates." |
| 66 | +
|
| 67 | +If `skip`, report no Plane updates made and stop. |
| 68 | + |
| 69 | +### Step 2: Fetch the Plane issue |
| 70 | + |
| 71 | +1. Parse identifier into `project_identifier` and `issue_identifier` |
| 72 | +2. Call `mcp__plane__retrieve_work_item_by_identifier` with `expand: "assignees,labels,state"` |
| 73 | +3. Store `project_id`, `work_item_id`, current state, and state_group |
| 74 | + |
| 75 | +### Step 3: Check if already done |
| 76 | + |
| 77 | +If the issue's `state_group` is already `completed`: |
| 78 | +- Report: "Issue <IDENTIFIER> is already Done. Skipping state update." |
| 79 | +- Skip the state update in Phase 3 but continue with closing comment and blocker check |
| 80 | + |
| 81 | +--- |
| 82 | + |
| 83 | +## Phase 3: Update the Plane Issue |
| 84 | + |
| 85 | +### Step 1: Resolve the Done state |
| 86 | + |
| 87 | +Call `mcp__plane__list_states` with the `project_id`. |
| 88 | +Find the state with `group: "completed"` — prefer one named "Done" if multiple exist. |
| 89 | + |
| 90 | +### Step 2: Confirm the state change |
| 91 | + |
| 92 | +Present: |
| 93 | + |
| 94 | +``` |
| 95 | +## Plane Issue Update |
| 96 | +
|
| 97 | +Issue: <IDENTIFIER> — <title> |
| 98 | +Current state: <state name> (<state_group>) |
| 99 | +New state: Done (completed) |
| 100 | +Merge SHA: <short SHA> |
| 101 | +PR: #<number> — <url> |
| 102 | +``` |
| 103 | + |
| 104 | +Use `AskUserQuestion` to confirm. If declined, skip state update but offer to continue with comment and blocker check. |
| 105 | + |
| 106 | +### Step 3: Update the state |
| 107 | + |
| 108 | +Call `mcp__plane__update_work_item` with: |
| 109 | +- `project_id`, `work_item_id`, `state`: Done state UUID |
| 110 | + |
| 111 | +### Step 4: Post closing comment |
| 112 | + |
| 113 | +Call `mcp__plane__create_work_item_comment` with `comment_html`: |
| 114 | + |
| 115 | +```html |
| 116 | +<p>Closed via <a href="<PR URL>">PR #<number></a> (merge SHA: <code><short SHA></code>)</p> |
| 117 | +<p><strong>Branch</strong>: <code><branch name></code></p> |
| 118 | +<p><strong>Merged</strong>: <merged date></p> |
| 119 | +``` |
| 120 | + |
| 121 | +--- |
| 122 | + |
| 123 | +## Phase 4: Check Blocked Issues |
| 124 | + |
| 125 | +### Step 1: Fetch relations |
| 126 | + |
| 127 | +Call `mcp__plane__list_work_item_relations` with `project_id` and `work_item_id`. |
| 128 | + |
| 129 | +Look at the `blocking` list — issues that THIS item was blocking. If empty, skip to Phase 5. |
| 130 | + |
| 131 | +### Step 2: Check if blocked issues are fully unblocked |
| 132 | + |
| 133 | +For each issue in the `blocking` list (run in parallel): |
| 134 | + |
| 135 | +1. Call `mcp__plane__retrieve_work_item` with `expand: "state"` |
| 136 | +2. Call `mcp__plane__list_work_item_relations` for the blocked issue |
| 137 | +3. Check its `blocked_by` list — for each blocker, check if state_group is `completed` |
| 138 | +4. If ALL blockers are now `completed`, this issue is **fully unblocked** |
| 139 | + |
| 140 | +### Step 3: Collect results |
| 141 | + |
| 142 | +For each fully unblocked issue, note: identifier, title, current state, priority. |
| 143 | + |
| 144 | +--- |
| 145 | + |
| 146 | +## Phase 5: Present Summary |
| 147 | + |
| 148 | +``` |
| 149 | +## Post-Merge Cleanup Complete |
| 150 | +
|
| 151 | +### PR |
| 152 | +- PR: #<number> — <url> |
| 153 | +- Merge SHA: <short SHA> |
| 154 | +- Branch: <branch name> |
| 155 | +
|
| 156 | +### Plane Issue |
| 157 | +- Issue: <IDENTIFIER> — <title> |
| 158 | +- State: <previous state> -> Done |
| 159 | +- Closing comment posted |
| 160 | +
|
| 161 | +### Unblocked Issues |
| 162 | +- <IDENTIFIER> — <title> [<priority>] — now fully unblocked and ready to work on |
| 163 | +- <IDENTIFIER> — <title> [<priority>] — still blocked by <other IDENTIFIER> |
| 164 | +
|
| 165 | +(If no blocked issues: "This issue was not blocking any other items.") |
| 166 | +``` |
| 167 | + |
| 168 | +--- |
| 169 | + |
| 170 | +## Constraints |
| 171 | + |
| 172 | +- **Never close an issue if the PR is not merged** — always verify `state: MERGED` before any Plane updates |
| 173 | +- **Never change Plane state without confirmation** — always use `AskUserQuestion` |
| 174 | +- **If the issue is already Done**, skip the state update — do not error, just report and continue |
| 175 | +- **Never delete or create work items** — only update state and post comments |
| 176 | +- **Never merge or close PRs** — only read PR data |
| 177 | +- **Do not automatically update blocked issues** — only report which are unblocked |
| 178 | +- **Always include merge SHA and PR link** in the closing comment for traceability |
| 179 | +- **If `gh` CLI is unavailable**, report the error and provide the manual command |
| 180 | +- **If any Plane MCP call fails**, report the error and continue with remaining steps |
0 commit comments