fix: support multi-part prefixes in issue ID extraction (#398)
This commit is contained in:
@@ -353,9 +353,19 @@ func TestExtractIssuePrefix(t *testing.T) {
|
||||
expected: "bd",
|
||||
},
|
||||
{
|
||||
name: "multi-part suffix",
|
||||
name: "multi-part prefix with numeric suffix",
|
||||
issueID: "alpha-beta-1",
|
||||
expected: "alpha", // Only first hyphen (bd-fasa)
|
||||
expected: "alpha-beta", // Last hyphen before numeric suffix
|
||||
},
|
||||
{
|
||||
name: "multi-part non-numeric suffix",
|
||||
issueID: "vc-baseline-test",
|
||||
expected: "vc", // Falls back to first hyphen for non-numeric suffix
|
||||
},
|
||||
{
|
||||
name: "beads-vscode style prefix",
|
||||
issueID: "beads-vscode-1",
|
||||
expected: "beads-vscode", // Last hyphen before numeric suffix
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -6,13 +6,36 @@ import (
|
||||
)
|
||||
|
||||
// ExtractIssuePrefix extracts the prefix from an issue ID like "bd-123" -> "bd"
|
||||
// Only considers the first hyphen, so "vc-baseline-test" -> "vc"
|
||||
// Uses the last hyphen before a numeric suffix, so "beads-vscode-1" -> "beads-vscode"
|
||||
// For non-numeric suffixes like "vc-baseline-test", returns the first segment "vc"
|
||||
func ExtractIssuePrefix(issueID string) string {
|
||||
idx := strings.Index(issueID, "-")
|
||||
if idx <= 0 {
|
||||
// Try last hyphen first (handles multi-part prefixes like "beads-vscode-1")
|
||||
lastIdx := strings.LastIndex(issueID, "-")
|
||||
if lastIdx <= 0 {
|
||||
return ""
|
||||
}
|
||||
return issueID[:idx]
|
||||
|
||||
suffix := issueID[lastIdx+1:]
|
||||
// Check if suffix is numeric (or starts with a number for hierarchical IDs like "bd-123.1")
|
||||
if len(suffix) > 0 {
|
||||
// Extract just the numeric part (handle "123.1.2" -> check "123")
|
||||
numPart := suffix
|
||||
if dotIdx := strings.Index(suffix, "."); dotIdx > 0 {
|
||||
numPart = suffix[:dotIdx]
|
||||
}
|
||||
var num int
|
||||
if _, err := fmt.Sscanf(numPart, "%d", &num); err == nil {
|
||||
// Suffix is numeric, use last hyphen
|
||||
return issueID[:lastIdx]
|
||||
}
|
||||
}
|
||||
|
||||
// Suffix is not numeric (e.g., "vc-baseline-test"), fall back to first hyphen
|
||||
firstIdx := strings.Index(issueID, "-")
|
||||
if firstIdx <= 0 {
|
||||
return ""
|
||||
}
|
||||
return issueID[:firstIdx]
|
||||
}
|
||||
|
||||
// ExtractIssueNumber extracts the number from an issue ID like "bd-123" -> 123
|
||||
|
||||
Reference in New Issue
Block a user