fix: merged-pr-finish-cleanup - #15
Merged
Merged
Conversation
Re-running 'bflow finish' on a work branch whose PR was already merged restarted the whole flow (breaking prompt, push, new PR). Finish now asks the hosting platform for the branch's most recent PR first: if it is merged and the local tip equals the merged head SHA, bflow deletes the remote and local branch and, in a linked worktree, removes the worktree. Completion is derived from the platform's PR state - no state file - in line with the existing rule that progress is always re-derived and only underivable intent (conflict identity, stash) is persisted. - HostingPlatform::merged_pr on gh (pr list --state all) and az (repos pr list --status all), newest PR decides; open/abandoned -> None - Git: head_sha, detach_head, is_linked_worktree, remove_current_worktree (runs via -C main root and must be the flow's last git call) - New commits after the merge, or a PR closed without merging, still get a fresh PR - cleanup only ever deletes the exact merged commit Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR makes bflow finish idempotent for already-merged work branches (and release-fix/hotfix-fix): if the hosting platform reports the branch’s most recent PR is merged and the local HEAD matches the merged PR’s head SHA, finish performs cleanup (remote branch deletion if present, local branch deletion, and worktree removal when applicable) instead of opening a new PR.
Changes:
- Introduces
HostingPlatform::merged_prplus aMergedPr { url, head_sha, base }contract, with GitHub (gh) and Azure DevOps (az) implementations and parser tests. - Adds Git primitives needed for safe cleanup (
head_sha, linked-worktree detection/removal, anddetach_head) and implements them forGitCliand test mocks. - Updates finish-work flows to attempt merged-PR cleanup before prompting/parent detection, expands integration tests, and documents the new behavior.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/flows/finish_work.rs |
Adds merged-PR cleanup path and refactors PR creation to accept an explicit current branch. |
src/hosting/mod.rs |
Adds MergedPr and extends HostingPlatform with merged_pr. |
src/hosting/github.rs |
Implements merged_pr via gh pr list and adds parsing unit tests. |
src/hosting/devops.rs |
Implements merged_pr via az repos pr list and adds parsing unit tests. |
src/git/mod.rs |
Extends Git trait and adds GitCli implementations for worktree detection/removal and head_sha. |
tests/common/mod.rs |
Extends MockGit/MockHosting to support new trait methods for tests. |
tests/finish_work_test.rs |
Updates expectations for the new merged_pr call and adds coverage for cleanup behavior. |
README.md |
Documents “re-run finish after merge” cleanup semantics. |
.claude/skills/bflow/SKILL.md |
Updates skill doc to reflect merged-PR cleanup behavior. |
.claude/skills/architecture/decisions.md |
Records the architectural decision for derived completion via merged PR state + head SHA gate. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.