From 4a429903147a93737bf8c37953c7fe77ca6a8104 Mon Sep 17 00:00:00 2001 From: yujeong-jeon Date: Fri, 6 Mar 2026 15:24:50 +0900 Subject: [PATCH 1/2] fix: support hyphenated prefixes in branch names for template generation --- packages/commithelper-go/main.go | 4 +- packages/commithelper-go/main_test.go | 70 +++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/packages/commithelper-go/main.go b/packages/commithelper-go/main.go index 7830bc2..e4789b4 100644 --- a/packages/commithelper-go/main.go +++ b/packages/commithelper-go/main.go @@ -142,7 +142,7 @@ func loadConfig() Config { } func generatePrefix(branchName string, config Config) string { - pattern := regexp.MustCompile(`^(\w+)/(\d+).*`) + pattern := regexp.MustCompile(`^([\w-]+)/(\d+).*`) matches := pattern.FindStringSubmatch(branchName) if len(matches) < 3 { return "" @@ -164,7 +164,7 @@ func generatePrefix(branchName string, config Config) string { } func generateTemplateData(branchName string, config Config, message string) *TemplateData { - pattern := regexp.MustCompile(`^(\w+)/(\d+).*`) + pattern := regexp.MustCompile(`^([\w-]+)/(\d+).*`) matches := pattern.FindStringSubmatch(branchName) if len(matches) < 3 { return nil diff --git a/packages/commithelper-go/main_test.go b/packages/commithelper-go/main_test.go index aef4ebf..8cc4a6c 100644 --- a/packages/commithelper-go/main_test.go +++ b/packages/commithelper-go/main_test.go @@ -36,3 +36,73 @@ func TestIsProtectedBranch_InvalidPattern(t *testing.T) { t.Error("expected error for invalid pattern, got nil") } } + +func strPtr(s string) *string { return &s } + +func TestGenerateTemplateData_HyphenatedPrefix(t *testing.T) { + config := Config{ + Rules: map[string]*string{ + "fe-plan": strPtr("card-fe/plan"), + "feature": nil, + }, + } + + tests := []struct { + name string + branch string + wantNil bool + wantPrefix string + }{ + {"hyphenated prefix", "fe-plan/11", false, "card-fe/plan#11"}, + {"simple prefix", "feature/42", false, "#42"}, + {"no match", "main", true, ""}, + {"unknown prefix", "unknown/99", true, ""}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + data := generateTemplateData(tt.branch, config, "Test") + if tt.wantNil { + if data != nil { + t.Errorf("expected nil, got %+v", data) + } + return + } + if data == nil { + t.Fatal("expected non-nil TemplateData, got nil") + } + if data.Prefix != tt.wantPrefix { + t.Errorf("Prefix = %q, want %q", data.Prefix, tt.wantPrefix) + } + }) + } +} + +func TestGeneratePrefix_HyphenatedPrefix(t *testing.T) { + config := Config{ + Rules: map[string]*string{ + "fe-plan": strPtr("card-fe/plan"), + "feature": nil, + }, + } + + tests := []struct { + name string + branch string + want string + }{ + {"hyphenated prefix", "fe-plan/11", "card-fe/plan#11"}, + {"simple prefix", "feature/42", "#42"}, + {"no match", "main", ""}, + {"unknown prefix", "unknown/99", ""}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := generatePrefix(tt.branch, config) + if got != tt.want { + t.Errorf("got %q, want %q", got, tt.want) + } + }) + } +} From 860f7da48df08f5ce6434f950798584155031769 Mon Sep 17 00:00:00 2001 From: yujeong-jeon Date: Fri, 6 Mar 2026 15:28:01 +0900 Subject: [PATCH 2/2] add fix-hyphen-branch-prefix.md --- .changeset/fix-hyphen-branch-prefix.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/fix-hyphen-branch-prefix.md diff --git a/.changeset/fix-hyphen-branch-prefix.md b/.changeset/fix-hyphen-branch-prefix.md new file mode 100644 index 0000000..e08dba1 --- /dev/null +++ b/.changeset/fix-hyphen-branch-prefix.md @@ -0,0 +1,5 @@ +--- +"@naverpay/commithelper-go": patch +--- + +fix: branch prefix with hyphens not being matched