aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-11-27 02:52:28 +0900
committernsfisis <nsfisis@gmail.com>2025-11-27 02:52:28 +0900
commit0dc4922fd188cfc3846be29fd2e2d777297e034c (patch)
tree562b53638bdfc2f172854f9429adadbb4d960d27
parentb61815b7499e7286e88d7de9fe667af08ab66f55 (diff)
downloadgit-helpers-0dc4922fd188cfc3846be29fd2e2d777297e034c.tar.gz
git-helpers-0dc4922fd188cfc3846be29fd2e2d777297e034c.tar.zst
git-helpers-0dc4922fd188cfc3846be29fd2e2d777297e034c.zip
fix handling of number suffixv0.1.1
-rw-r--r--cmd/git-extract-issue/main.go3
-rw-r--r--cmd/git-extract-issue/main_test.go1
-rw-r--r--justfile3
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"},
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 ./...