fix: handle multi-hyphen prefixes with hash IDs (#419)

Fixed bug where issue IDs with multiple hyphens in the prefix and hash
suffixes were incorrectly parsed. For example, `web-app-a3f8e9` was
being parsed with prefix `web-` instead of `web-app`.

Root cause: ExtractIssuePrefix() only checked for numeric suffixes.
When it encountered a hash suffix, it fell back to using the first
hyphen instead of the last hyphen.

Changes:
- Added isLikelyHash() helper to detect hexadecimal hash suffixes (4-8 chars)
- Updated ExtractIssuePrefix() to handle both numeric and hash suffixes
- Added comprehensive test cases for various prefix patterns

Test coverage includes:
- web-app-123 (numeric suffix)
- web-app-a3f8e9 (hash suffix)
- my-cool-app-a3f8e9 (three-part prefix with hash)
- super-long-project-name-1a2b (four-part prefix)
- Various hash lengths and case variations

Co-authored-by: dubstylee <dubstylee@users.noreply.github.com>

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2025-11-29 15:05:10 -08:00
parent f321857f18
commit 8becf0d9b9
3 changed files with 69 additions and 5 deletions

View File

@@ -367,6 +367,41 @@ func TestExtractIssuePrefix(t *testing.T) {
issueID: "beads-vscode-1",
expected: "beads-vscode", // Last hyphen before numeric suffix
},
{
name: "web-app style prefix",
issueID: "web-app-123",
expected: "web-app", // Should extract "web-app", not "web-"
},
{
name: "three-part prefix with hash",
issueID: "my-cool-app-a3f8e9",
expected: "my-cool-app", // Hash suffix should use last hyphen logic
},
{
name: "four-part prefix with 4-char hash",
issueID: "super-long-project-name-1a2b",
expected: "super-long-project-name", // 4-char hash
},
{
name: "prefix with 5-char hash",
issueID: "my-app-1a2b3",
expected: "my-app", // 5-char hash
},
{
name: "prefix with 6-char hash",
issueID: "web-app-a1b2c3",
expected: "web-app", // 6-char hash
},
{
name: "uppercase hash",
issueID: "my-app-A3F8E9",
expected: "my-app", // Uppercase hash should work
},
{
name: "mixed case hash",
issueID: "proj-AbCd12",
expected: "proj", // Mixed case hash should work
},
}
for _, tt := range tests {