Skip to content

Commit dee896e

Browse files
author
Oppodelldog
committed
removed pcre since cannot compile for windows, for now.
Therefore had to simplify some regex expressions.
1 parent 4a1c988 commit dee896e

File tree

11 files changed

+29
-56
lines changed

11 files changed

+29
-56
lines changed

Gopkg.lock

Lines changed: 2 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,7 @@
1-
# Gopkg.toml example
2-
#
3-
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
4-
# for detailed Gopkg.toml documentation.
5-
#
6-
# required = ["github.com/user/thing/cmd/thing"]
7-
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
8-
#
9-
# [[constraint]]
10-
# name = "github.com/user/project"
11-
# version = "1.0.0"
12-
#
13-
# [[constraint]]
14-
# name = "github.com/user/project2"
15-
# branch = "dev"
16-
# source = "github.com/myfork/project2"
17-
#
18-
# [[override]]
19-
# name = "github.com/x/y"
20-
# version = "2.4.0"
21-
22-
231
[[constraint]]
242
name = "github.com/Oppodelldog/filediscovery"
253
version = "0.1.0"
264

27-
[[constraint]]
28-
branch = "master"
29-
name = "github.com/glenn-brown/golang-pkg-pcre"
30-
315
[[constraint]]
326
name = "github.com/pkg/errors"
337
version = "0.8.0"

cmd/main_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ func restoreOriginals() {
5656

5757
func TestMain_HappyPath(t *testing.T) {
5858
defer restoreOriginals()
59+
defer testhelper.CleanupTestEnvironment(t)
60+
testhelper.CleanupTestEnvironment(t)
5961

6062
initGitRepositoryWithBranchAndConfig(t, featureBranch)
6163
setCommitMessage(t, "initial commit")

config/parsing_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestParse(t *testing.T) {
1717
Path: "/home/nils/projects/xyz/.git",
1818
BranchTypes: map[string]BranchTypePattern{
1919
"master": `^(origin\/)*master`,
20-
"feature": `^((?!master|release|develop).)*$`,
20+
"feature": `^(origin\/)*feature/.*$`,
2121
"develop": `^(origin\/)*develop$`,
2222
"release": `^(origin\/)*release\/v([0-9]*\.*)*$`,
2323
"hotfix": `^(origin\/)*hotfix\/v([0-9]*\.*)*$`,
@@ -27,7 +27,7 @@ func TestParse(t *testing.T) {
2727
},
2828
Validation: map[string]BranchValidationConfiguration{
2929
"*": {
30-
`(?m)(?:\s|^|/)(([A-Z](_)*)+-[0-9]+)([\s,;:!.-]|$)`: "valid ticket ID",
30+
`(?m)(?:\s|^|/)(([A-Z](_)*)+-[0-9]+)([\s,;:!.-]|$)`: "valid ticket ID (fallback validator)",
3131
},
3232
"develop": {
3333
`(?m)(?:\s|^|/)(([A-Z](_)*)+-[0-9]+)([\s,;:!.-]|$)`: "valid ticket ID",

config/project.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package config
22

33
import (
4-
"github.com/glenn-brown/golang-pkg-pcre/src/pkg/pcre"
4+
"github.com/Oppodelldog/git-commit-hook/regexadapter"
55
)
66

77
type (
@@ -23,7 +23,7 @@ type (
2323
func (projConf *Project) GetBranchType(branchName string) string {
2424

2525
for branchType, branchTypePattern := range projConf.BranchTypes {
26-
if regexMatchesString(string(branchTypePattern), branchName) {
26+
if regexadapter.RegexMatchesString(string(branchTypePattern), branchName) {
2727
return branchType
2828
}
2929
}
@@ -43,7 +43,3 @@ func (projConf *Project) GetValidator(branchType string) map[string]string {
4343

4444
return foundValidators
4545
}
46-
47-
func regexMatchesString(pattern string, branchName string) bool {
48-
return pcre.MustCompile(pattern, 0).MatcherString(branchName, 0).Matches()
49-
}

config/project_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import (
99
func TestGetBranchType(t *testing.T) {
1010

1111
testDataSet := []struct{ BranchName, ExpectedBranchType string }{
12-
{BranchName: "FEATURE-123", ExpectedBranchType: "feature"},
13-
{BranchName: "noissue_fix_something", ExpectedBranchType: "feature"},
12+
{BranchName: "feature/FEATURE-123", ExpectedBranchType: "feature"},
1413
{BranchName: "release/v1.0.0", ExpectedBranchType: "release"},
1514
{BranchName: "release/v1.0.0-fix", ExpectedBranchType: "release"},
1615
{BranchName: "master", ExpectedBranchType: ""},
@@ -22,8 +21,8 @@ func TestGetBranchType(t *testing.T) {
2221

2322
cfg := &Project{
2423
BranchTypes: map[string]BranchTypePattern{
25-
"feature": `(?m)^()((?!master|release|develop).)*$`,
26-
"release": `(?m)^(origin\/)*release\/v([0-9]*\.*)*(-fix)*$`,
24+
"feature": `^(origin\/)*feature/.*$`,
25+
"release": `^(origin\/)*release\/v([0-9]*\.*)*(-fix)*$`,
2726
},
2827
}
2928

config/test-data.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# define types of branch and a pattern to identify the type for the current branch you are working on
77
branch:
88
master: "^(origin\\/)*master"
9-
feature: "^((?!master|release|develop).)*$"
9+
feature: "^(origin\\/)*feature/.*$"
1010
develop: "^(origin\\/)*develop$"
1111
release: "^(origin\\/)*release\\/v([0-9]*\\.*)*$"
1212
hotfix: "^(origin\\/)*hotfix\\/v([0-9]*\\.*)*$"

hook/modifier_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func TestModifyGitCommitMessage(t *testing.T) {
6060

6161
prjCfg := config.Project{
6262
BranchTypes: map[string]config.BranchTypePattern{
63-
"feature": `(?m)^((?!master|release|develop).)*$`,
63+
"feature": `(?m)^((origin\/)*feature\/.*)|(?:\s|^|/)(([A-Z](_)*)+-[0-9]+)([\s,;:!.-]|$)`,
6464
"release": `(?m)^(origin\/)*release\/v([0-9]*\.*)*(-fix)*$`,
6565
},
6666
Templates: map[string]config.BranchTypeTemplate{

hook/renderer_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func TestRenderCommitMessage(t *testing.T) {
1414
}
1515
cfg := &config.Project{
1616
BranchTypes: map[string]config.BranchTypePattern{
17-
"feature": `(?m)^()((?!master|release|develop).)*$`,
17+
"feature": `^(origin\/)*feature/.*$`,
1818
},
1919
Templates: map[string]config.BranchTypeTemplate{
2020
"feature": "{{.BranchName}}: {{.CommitMessage}}",
@@ -34,7 +34,7 @@ func TestRenderCommitMessage_InvalidTemplate_ReturnsError(t *testing.T) {
3434
viewModel := ViewModel{}
3535
cfg := &config.Project{
3636
BranchTypes: map[string]config.BranchTypePattern{
37-
"feature": `(?m)^()((?!master|release|develop).)*$`,
37+
"feature": `.*`,
3838
},
3939
Templates: map[string]config.BranchTypeTemplate{
4040
"feature": config.BranchTypeTemplate(invalidTemplate),
@@ -53,7 +53,7 @@ func TestRenderCommitMessage_NoTemplateFound_PassesBackTheGivenCommitMessage(t *
5353
}
5454
cfg := &config.Project{
5555
BranchTypes: map[string]config.BranchTypePattern{
56-
"feature": `(?m)^()((?!master|release|develop).)*$`,
56+
"feature": `.*`,
5757
},
5858
Templates: map[string]config.BranchTypeTemplate{}}
5959

hook/validator.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"fmt"
77

88
"github.com/Oppodelldog/git-commit-hook/config"
9-
"github.com/glenn-brown/golang-pkg-pcre/src/pkg/pcre"
9+
"github.com/Oppodelldog/git-commit-hook/regexadapter"
1010
)
1111

1212
type (
@@ -38,7 +38,7 @@ func (v *commitMessageValidator) Validate(branchName, commitMessage string) erro
3838
}
3939

4040
for validationPattern := range validators {
41-
if regexMatchesString(validationPattern, commitMessage) {
41+
if regexadapter.RegexMatchesString(validationPattern, commitMessage) {
4242
return nil
4343
}
4444
}
@@ -60,6 +60,3 @@ func prepareError(branchName string, validators map[string]string) error {
6060
return errors.New(buffer.String())
6161
}
6262

63-
func regexMatchesString(pattern string, branchName string) bool {
64-
return pcre.MustCompile(pattern, 0).MatcherString(branchName, 0).Matches()
65-
}

0 commit comments

Comments
 (0)