diff options
| -rw-r--r-- | cmd/git-extract-issue/main.go | 3 | ||||
| -rw-r--r-- | cmd/git-extract-issue/main_test.go | 1 | ||||
| -rw-r--r-- | justfile | 3 |
3 files changed, 6 insertions, 1 deletions
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"}, @@ -1,5 +1,8 @@ build: go build ./... +fmt: + go fmt ./... + test: go test ./... |
