From 21ab565819b53c5882d13589cfc62f5032a591fa Mon Sep 17 00:00:00 2001 From: Midworld Kim Date: Sun, 2 Nov 2025 11:57:37 +0900 Subject: [PATCH] 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 --- cmd/bd/nodb.go | 6 +++--- cmd/bd/nodb_test.go | 1 + internal/utils/id_parser_test.go | 10 ++++++++++ internal/utils/issue_id.go | 12 ++++++------ 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/cmd/bd/nodb.go b/cmd/bd/nodb.go index e35b7195..84ac4268 100644 --- a/cmd/bd/nodb.go +++ b/cmd/bd/nodb.go @@ -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 diff --git a/cmd/bd/nodb_test.go b/cmd/bd/nodb_test.go index c5b5a2b9..4bc24003 100644 --- a/cmd/bd/nodb_test.go +++ b/cmd/bd/nodb_test.go @@ -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", "", ""}, } diff --git a/internal/utils/id_parser_test.go b/internal/utils/id_parser_test.go index 7f6262da..08f1d7af 100644 --- a/internal/utils/id_parser_test.go +++ b/internal/utils/id_parser_test.go @@ -321,6 +321,11 @@ func TestExtractIssuePrefix(t *testing.T) { issueID: "bd-", expected: "bd", }, + { + name: "hyphenated prefix", + issueID: "alpha-beta-1", + expected: "alpha-beta", + }, } for _, tt := range tests { @@ -379,6 +384,11 @@ func TestExtractIssueNumber(t *testing.T) { issueID: "bd-123abc", expected: 123, }, + { + name: "hyphenated prefix with number", + issueID: "alpha-beta-7", + expected: 7, + }, } for _, tt := range tests { diff --git a/internal/utils/issue_id.go b/internal/utils/issue_id.go index 0ef25551..a5684f31 100644 --- a/internal/utils/issue_id.go +++ b/internal/utils/issue_id.go @@ -7,20 +7,20 @@ import ( // 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] } // ExtractIssueNumber extracts the number from an issue ID like "bd-123" -> 123 func ExtractIssueNumber(issueID string) int { - parts := strings.SplitN(issueID, "-", 2) - if len(parts) < 2 { + idx := strings.LastIndex(issueID, "-") + if idx < 0 || idx == len(issueID)-1 { return 0 } var num int - fmt.Sscanf(parts[1], "%d", &num) + fmt.Sscanf(issueID[idx+1:], "%d", &num) return num }