Add rename-prefix --repair flag and consolidate issue ID parsing

Enhances rename-prefix command with --repair flag to consolidate databases
with multiple prefixes. Creates shared issue ID utilities to eliminate code
duplication across import and rename operations.

Key changes:
- Add --repair flag to detect and consolidate multiple issue prefixes
- Create internal/utils/issue_id.go with ExtractIssuePrefix() and ExtractIssueNumber()
- Update all duplicate prefix extraction code to use shared utilities
- Add comprehensive tests for repair functionality

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
Ryan Newton + Claude
2025-10-27 18:31:01 +00:00
parent 969f3ac03b
commit e3df9cfa97
7 changed files with 364 additions and 21 deletions

View File

@@ -9,6 +9,7 @@ import (
"github.com/steveyegge/beads/internal/storage"
"github.com/steveyegge/beads/internal/types"
"github.com/steveyegge/beads/internal/utils"
)
// fieldComparator handles comparison logic for a specific field type
@@ -259,13 +260,13 @@ func importIssuesCore(ctx context.Context, dbPath string, store storage.Storage,
func renameImportedIssuePrefixes(issues []*types.Issue, targetPrefix string) error {
// Build a mapping of old IDs to new IDs
idMapping := make(map[string]string)
for _, issue := range issues {
oldPrefix := extractPrefix(issue.ID)
oldPrefix := utils.ExtractIssuePrefix(issue.ID)
if oldPrefix == "" {
return fmt.Errorf("cannot rename issue %s: malformed ID (no hyphen found)", issue.ID)
}
if oldPrefix != targetPrefix {
// Extract the numeric part
numPart := strings.TrimPrefix(issue.ID, oldPrefix+"-")