Fix hyphenated issue prefix detection (#199)

- update prefix/number parsing to use the last hyphen across utils and nodb paths
- add regression tests covering multi-hyphen prefixes in both packages
This commit is contained in:
Midworld Kim
2025-11-02 11:57:37 +09:00
committed by GitHub
parent b5db80c412
commit 21ab565819
4 changed files with 20 additions and 9 deletions

View File

@@ -173,11 +173,11 @@ func detectPrefix(beadsDir string, memStore *memory.MemoryStorage) (string, erro
// extractIssuePrefix extracts the prefix from an issue ID like "bd-123" -> "bd"
func extractIssuePrefix(issueID string) string {
parts := strings.SplitN(issueID, "-", 2)
if len(parts) < 2 {
idx := strings.LastIndex(issueID, "-")
if idx <= 0 {
return ""
}
return parts[0]
return issueID[:idx]
}
// writeIssuesToJSONL writes all issues from memory storage to JSONL file atomically

View File

@@ -18,6 +18,7 @@ func TestExtractIssuePrefix(t *testing.T) {
{"standard ID", "bd-123", "bd"},
{"custom prefix", "myproject-456", "myproject"},
{"hash ID", "bd-abc123def", "bd"},
{"hyphenated prefix", "alpha-beta-1", "alpha-beta"},
{"no hyphen", "nohyphen", ""},
{"empty", "", ""},
}