bd-211: Remove deprecated rename functions from import_shared.go

- Removed renameImportedIssuePrefixes (wrapper, 3 LOC)
- Removed renameImportedIssuePrefixesOld (deprecated, 61 LOC)
- Removed replaceIDReferences (32 LOC)
- Removed replaceBoundaryAware (31 LOC)
- Removed isBoundary (5 LOC)
- Removed TestIsBoundary (37 LOC)
- Removed TestReplaceBoundaryAware (54 LOC)
- Total: 223 LOC removed (136 LOC code + 91 LOC tests)
- Active implementation is in internal/importer/importer.go
- All tests pass
This commit is contained in:
Steve Yegge
2025-10-27 20:38:13 -07:00
parent f3617c8abd
commit ea7eaafb06
4 changed files with 2 additions and 230 deletions

View File

@@ -4,43 +4,6 @@ import (
"testing"
)
func TestIsBoundary(t *testing.T) {
tests := []struct {
input byte
expected bool
}{
{' ', true},
{'\t', true},
{'\n', true},
{'\r', true},
{'-', false}, // hyphen is part of issue IDs
{'_', true},
{'(', true},
{')', true},
{'[', true},
{']', true},
{'{', true},
{'}', true},
{',', true},
{'.', true},
{':', true},
{';', true},
{'a', false}, // lowercase letters are part of issue IDs
{'z', false},
{'A', true}, // uppercase is a boundary
{'Z', true}, // uppercase is a boundary
{'0', false}, // digits are part of issue IDs
{'9', false},
}
for _, tt := range tests {
result := isBoundary(tt.input)
if result != tt.expected {
t.Errorf("isBoundary(%q) = %v, want %v", tt.input, result, tt.expected)
}
}
}
func TestIsNumeric(t *testing.T) {
tests := []struct {
input string

View File

@@ -256,142 +256,6 @@ func importIssuesCore(ctx context.Context, dbPath string, store storage.Storage,
return result, nil
}
// renameImportedIssuePrefixes is a wrapper around importer.RenameImportedIssuePrefixes
func renameImportedIssuePrefixes(issues []*types.Issue, targetPrefix string) error {
return importer.RenameImportedIssuePrefixes(issues, targetPrefix)
}
// Deprecated: use importer.RenameImportedIssuePrefixes
func renameImportedIssuePrefixesOld(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)
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+"-")
// Validate that the numeric part is actually numeric
if numPart == "" || !isNumeric(numPart) {
return fmt.Errorf("cannot rename issue %s: non-numeric suffix '%s'", issue.ID, numPart)
}
newID := fmt.Sprintf("%s-%s", targetPrefix, numPart)
idMapping[issue.ID] = newID
}
}
// Now update all issues and their references
for _, issue := range issues {
// Update the issue ID itself if it needs renaming
if newID, ok := idMapping[issue.ID]; ok {
issue.ID = newID
}
// Update all text references in issue fields
issue.Title = replaceIDReferences(issue.Title, idMapping)
issue.Description = replaceIDReferences(issue.Description, idMapping)
if issue.Design != "" {
issue.Design = replaceIDReferences(issue.Design, idMapping)
}
if issue.AcceptanceCriteria != "" {
issue.AcceptanceCriteria = replaceIDReferences(issue.AcceptanceCriteria, idMapping)
}
if issue.Notes != "" {
issue.Notes = replaceIDReferences(issue.Notes, idMapping)
}
// Update dependency references
for i := range issue.Dependencies {
if newID, ok := idMapping[issue.Dependencies[i].IssueID]; ok {
issue.Dependencies[i].IssueID = newID
}
if newID, ok := idMapping[issue.Dependencies[i].DependsOnID]; ok {
issue.Dependencies[i].DependsOnID = newID
}
}
// Update comment references
for i := range issue.Comments {
issue.Comments[i].Text = replaceIDReferences(issue.Comments[i].Text, idMapping)
}
}
return nil
}
// replaceIDReferences replaces all old issue ID references with new ones in text
// Uses boundary-aware matching to avoid partial replacements (e.g., wy-1 inside wy-10)
func replaceIDReferences(text string, idMapping map[string]string) string {
if len(idMapping) == 0 {
return text
}
// Sort old IDs by length descending to handle longer IDs first
// This prevents "wy-1" from being replaced inside "wy-10"
oldIDs := make([]string, 0, len(idMapping))
for oldID := range idMapping {
oldIDs = append(oldIDs, oldID)
}
sort.Slice(oldIDs, func(i, j int) bool {
return len(oldIDs[i]) > len(oldIDs[j])
})
result := text
for _, oldID := range oldIDs {
newID := idMapping[oldID]
// Replace with boundary checking
result = replaceBoundaryAware(result, oldID, newID)
}
return result
}
// replaceBoundaryAware replaces oldID with newID only when surrounded by boundaries
func replaceBoundaryAware(text, oldID, newID string) string {
if !strings.Contains(text, oldID) {
return text
}
var result strings.Builder
result.Grow(len(text))
for i := 0; i < len(text); {
// Check if we match oldID at this position
if strings.HasPrefix(text[i:], oldID) {
// Check boundaries before and after
beforeOK := i == 0 || isBoundary(text[i-1])
afterOK := (i+len(oldID) >= len(text)) || isBoundary(text[i+len(oldID)])
if beforeOK && afterOK {
// Valid match - replace
result.WriteString(newID)
i += len(oldID)
continue
}
}
// Not a match or invalid boundaries - keep original character
result.WriteByte(text[i])
i++
}
return result.String()
}
// isBoundary returns true if the character is not part of an issue ID
func isBoundary(c byte) bool {
// Issue IDs contain: lowercase letters, digits, and hyphens
// Boundaries are anything else (space, punctuation, etc.)
return (c < 'a' || c > 'z') && (c < '0' || c > '9') && c != '-'
}
// isNumeric returns true if the string contains only digits
func isNumeric(s string) bool {
for i := 0; i < len(s); i++ {

View File

@@ -45,59 +45,3 @@ func TestParseLabelArgs(t *testing.T) {
})
}
}
func TestReplaceBoundaryAware(t *testing.T) {
tests := []struct {
name string
text string
oldID string
newID string
expected string
}{
{
name: "simple replacement",
text: "See bd-1 for details",
oldID: "bd-1",
newID: "bd-100",
expected: "See bd-100 for details",
},
{
name: "multiple occurrences",
text: "bd-1 relates to bd-1",
oldID: "bd-1",
newID: "bd-999",
expected: "bd-999 relates to bd-999",
},
{
name: "no match",
text: "See bd-2 for details",
oldID: "bd-1",
newID: "bd-100",
expected: "See bd-2 for details",
},
{
name: "boundary awareness - don't replace partial match",
text: "bd-1000 is different from bd-100",
oldID: "bd-100",
newID: "bd-999",
expected: "bd-1000 is different from bd-999",
},
{
name: "in parentheses",
text: "Related issue (bd-42)",
oldID: "bd-42",
newID: "bd-1",
expected: "Related issue (bd-1)",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := replaceBoundaryAware(tt.text, tt.oldID, tt.newID)
if result != tt.expected {
t.Errorf("replaceBoundaryAware(%q, %q, %q) = %q, want %q",
tt.text, tt.oldID, tt.newID, result, tt.expected)
}
})
}
}