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"
|
// extractIssuePrefix extracts the prefix from an issue ID like "bd-123" -> "bd"
|
||||||
func extractIssuePrefix(issueID string) string {
|
func extractIssuePrefix(issueID string) string {
|
||||||
parts := strings.SplitN(issueID, "-", 2)
|
idx := strings.LastIndex(issueID, "-")
|
||||||
if len(parts) < 2 {
|
if idx <= 0 {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return parts[0]
|
return issueID[:idx]
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeIssuesToJSONL writes all issues from memory storage to JSONL file atomically
|
// 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"},
|
{"standard ID", "bd-123", "bd"},
|
||||||
{"custom prefix", "myproject-456", "myproject"},
|
{"custom prefix", "myproject-456", "myproject"},
|
||||||
{"hash ID", "bd-abc123def", "bd"},
|
{"hash ID", "bd-abc123def", "bd"},
|
||||||
|
{"hyphenated prefix", "alpha-beta-1", "alpha-beta"},
|
||||||
{"no hyphen", "nohyphen", ""},
|
{"no hyphen", "nohyphen", ""},
|
||||||
{"empty", "", ""},
|
{"empty", "", ""},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -321,6 +321,11 @@ func TestExtractIssuePrefix(t *testing.T) {
|
|||||||
issueID: "bd-",
|
issueID: "bd-",
|
||||||
expected: "bd",
|
expected: "bd",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "hyphenated prefix",
|
||||||
|
issueID: "alpha-beta-1",
|
||||||
|
expected: "alpha-beta",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
@@ -379,6 +384,11 @@ func TestExtractIssueNumber(t *testing.T) {
|
|||||||
issueID: "bd-123abc",
|
issueID: "bd-123abc",
|
||||||
expected: 123,
|
expected: 123,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "hyphenated prefix with number",
|
||||||
|
issueID: "alpha-beta-7",
|
||||||
|
expected: 7,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
|||||||
@@ -7,20 +7,20 @@ import (
|
|||||||
|
|
||||||
// ExtractIssuePrefix extracts the prefix from an issue ID like "bd-123" -> "bd"
|
// ExtractIssuePrefix extracts the prefix from an issue ID like "bd-123" -> "bd"
|
||||||
func ExtractIssuePrefix(issueID string) string {
|
func ExtractIssuePrefix(issueID string) string {
|
||||||
parts := strings.SplitN(issueID, "-", 2)
|
idx := strings.LastIndex(issueID, "-")
|
||||||
if len(parts) < 2 {
|
if idx <= 0 {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return parts[0]
|
return issueID[:idx]
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExtractIssueNumber extracts the number from an issue ID like "bd-123" -> 123
|
// ExtractIssueNumber extracts the number from an issue ID like "bd-123" -> 123
|
||||||
func ExtractIssueNumber(issueID string) int {
|
func ExtractIssueNumber(issueID string) int {
|
||||||
parts := strings.SplitN(issueID, "-", 2)
|
idx := strings.LastIndex(issueID, "-")
|
||||||
if len(parts) < 2 {
|
if idx < 0 || idx == len(issueID)-1 {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
var num int
|
var num int
|
||||||
fmt.Sscanf(parts[1], "%d", &num)
|
fmt.Sscanf(issueID[idx+1:], "%d", &num)
|
||||||
return num
|
return num
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user