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:
@@ -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
|
||||
|
||||
@@ -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", "", ""},
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user