Skip to content

fix: merged-pr-finish-cleanup - #15

Merged
jopmiddelkamp merged 1 commit into
developfrom
fix/merged-pr-finish-cleanup
Jul 29, 2026
Merged

fix: merged-pr-finish-cleanup#15
jopmiddelkamp merged 1 commit into
developfrom
fix/merged-pr-finish-cleanup

Conversation

@jopmiddelkamp

Copy link
Copy Markdown
Contributor

No description provided.

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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_pr plus a MergedPr { 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, and detach_head) and implements them for GitCli and 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.

@claude

claude Bot commented Jul 29, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@jopmiddelkamp
jopmiddelkamp merged commit 081b349 into develop Jul 29, 2026
9 checks passed
@jopmiddelkamp
jopmiddelkamp deleted the fix/merged-pr-finish-cleanup branch July 29, 2026 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants