From 0dc4922fd188cfc3846be29fd2e2d777297e034c Mon Sep 17 00:00:00 2001 From: nsfisis Date: Thu, 27 Nov 2025 02:52:28 +0900 Subject: fix handling of number suffix --- cmd/git-extract-issue/main.go | 3 ++- cmd/git-extract-issue/main_test.go | 1 + justfile | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd/git-extract-issue/main.go b/cmd/git-extract-issue/main.go index 4681d4d..2e9255d 100644 --- a/cmd/git-extract-issue/main.go +++ b/cmd/git-extract-issue/main.go @@ -20,10 +20,11 @@ func main() { // * 123-suffix => #123 // * feature/123 => #123 // * feature/123-suffix => #123 +// * feature/123-2 => #123 // * feature/prefix-123 => prefix-123 // * feature/prefix-123-suffix => prefix-123 func extractIssueNumberFromBranchName(branchName string) string { - pattern := regexp.MustCompile(`\A(?:\w+/)?(\w+-)?(\d+)(?:-\w+)*\z`) + pattern := regexp.MustCompile(`\A(?:\w+/)?([A-Za-z][0-9A-Za-z]*-)?(\d+)(?:-\w+)*\z`) matches := pattern.FindSubmatch([]byte(branchName)) if len(matches) != 3 { return "" diff --git a/cmd/git-extract-issue/main_test.go b/cmd/git-extract-issue/main_test.go index dbf88c5..02c0fe2 100644 --- a/cmd/git-extract-issue/main_test.go +++ b/cmd/git-extract-issue/main_test.go @@ -13,6 +13,7 @@ func TestExtractIssueNumberFromBranchName(t *testing.T) { {"feature prefix", "feature/123", "#123"}, {"feature prefix with suffix", "feature/123-suffix", "#123"}, + {"feature prefix with number suffix", "feature/123-2", "#123"}, {"project prefix", "feature/prefix-123", "prefix-123"}, {"project prefix with suffix", "feature/prefix-123-suffix", "prefix-123"}, diff --git a/justfile b/justfile index a14db65..9c6bb08 100644 --- a/justfile +++ b/justfile @@ -1,5 +1,8 @@ build: go build ./... +fmt: + go fmt ./... + test: go test ./... -- cgit v1.2.3-70-g09d2