Files
gastown/internal/beads/beads_mr.go
gastown/crew/dennis b60f016955 refactor(beads,mail): split large files into focused modules
Break down monolithic beads.go and mail.go into smaller, single-purpose files:

beads package:
- beads_agent.go: Agent-related bead operations
- beads_delegation.go: Delegation bead handling
- beads_dog.go: Dog pool operations
- beads_merge_slot.go: Merge slot management
- beads_mr.go: Merge request operations
- beads_redirect.go: Redirect bead handling
- beads_rig.go: Rig bead operations
- beads_role.go: Role bead management

cmd package:
- mail_announce.go: Announcement subcommand
- mail_check.go: Mail check subcommand
- mail_identity.go: Identity management
- mail_inbox.go: Inbox operations
- mail_queue.go: Queue subcommand
- mail_search.go: Search functionality
- mail_send.go: Send subcommand
- mail_thread.go: Thread operations

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 23:01:55 -08:00

46 lines
1.4 KiB
Go

// Package beads provides merge request and gate utilities.
package beads
import (
"fmt"
"strings"
)
// 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",
Label: "gt: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
}
// AddGateWaiter registers an agent as a waiter on a gate bead.
// When the gate closes, the waiter will receive a wake notification via gt gate wake.
// The waiter is typically the polecat's address (e.g., "gastown/polecats/Toast").
func (b *Beads) AddGateWaiter(gateID, waiter string) error {
// Use bd gate add-waiter to register the waiter on the gate
// This adds the waiter to the gate's native waiters field
_, err := b.run("gate", "add-waiter", gateID, waiter)
if err != nil {
return fmt.Errorf("adding gate waiter: %w", err)
}
return nil
}