Make gt done MR creation idempotent (gt-svdsy)

Add FindMRForBranch helper to check for existing MR beads before creating.
If an MR already exists for the branch, skip creation and reuse it.
This makes gt done safe to re-run if interrupted mid-execution.

Implements Option C from gt-svdsy: idempotent operations that check
if already done before doing, making it safe to retry.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
gastown/polecats/capable
2025-12-30 22:12:30 -08:00
committed by Steve Yegge
parent 49117c9a48
commit c2a33be4e6
2 changed files with 59 additions and 20 deletions

View File

@@ -1118,3 +1118,28 @@ func (b *Beads) GetRoleConfig(roleBeadID string) (*RoleConfig, error) {
return ParseRoleConfig(issue.Description), nil
}
// FindMRForBranch searches for an existing merge-request bead for the given branch.
// Returns the MR bead if found, nil if not found.
// This enables idempotent `gt done` - if an MR already exists, we skip creation.
func (b *Beads) FindMRForBranch(branch string) (*Issue, error) {
// List all merge-request beads (open status only - closed MRs are already processed)
issues, err := b.List(ListOptions{
Status: "open",
Type: "merge-request",
})
if err != nil {
return nil, err
}
// Search for one matching this branch
// MR description format: "branch: <branch>\ntarget: ..."
branchPrefix := "branch: " + branch + "\n"
for _, issue := range issues {
if strings.HasPrefix(issue.Description, branchPrefix) {
return issue, nil
}
}
return nil, nil
}