From 94e37ae4b4412543bc6300153ef4152b2043d9f8 Mon Sep 17 00:00:00 2001 From: Sascha Andres Date: Wed, 25 Jul 2018 08:33:02 +0200 Subject: [PATCH 1/4] feat: update vendoring add go-hookhelper to vendoring --- Gopkg.lock | 8 ++++++- Gopkg.toml | 4 ++++ .../livingit.de/code/go-hookhelper/README.md | 9 +++++++ .../code/go-hookhelper/optimistic_version.go | 24 +++++++++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 vendor/livingit.de/code/go-hookhelper/README.md create mode 100644 vendor/livingit.de/code/go-hookhelper/optimistic_version.go diff --git a/Gopkg.lock b/Gopkg.lock index cdfcf05..6c01b27 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -25,6 +25,12 @@ revision = "5420a8b6744d3b0345ab293f6fcba19c978f1183" version = "v2.2.1" +[[projects]] + name = "livingit.de/code/go-hookhelper" + packages = ["."] + revision = "8271b504d319691690f673cd07e05be638d95df4" + version = "0.1.0" + [[projects]] name = "livingit.de/code/versioned" packages = ["."] @@ -34,6 +40,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "67d9f4ba14859b517224764934a28345465d5fcb14925413d070c02d6a3d19c0" + inputs-digest = "91c02958be7074fa146ce76e315828829f294a46ff85ebcb52c3262539443bb7" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index 4dc3569..c4125ca 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -41,6 +41,10 @@ name = "gopkg.in/yaml.v2" version = "2.2.1" +[[constraint]] + name = "livingit.de/code/go-hookhelper" + version = "0.1.0" + [prune] go-tests = true unused-packages = true diff --git a/vendor/livingit.de/code/go-hookhelper/README.md b/vendor/livingit.de/code/go-hookhelper/README.md new file mode 100644 index 0000000..026800e --- /dev/null +++ b/vendor/livingit.de/code/go-hookhelper/README.md @@ -0,0 +1,9 @@ +# helper methods for git-hook projects + +some common helper methods used across git hook projects + +## History + +|Version|Description| +|---|---| +|0.1.0|Initial version| \ No newline at end of file diff --git a/vendor/livingit.de/code/go-hookhelper/optimistic_version.go b/vendor/livingit.de/code/go-hookhelper/optimistic_version.go new file mode 100644 index 0000000..cde4d68 --- /dev/null +++ b/vendor/livingit.de/code/go-hookhelper/optimistic_version.go @@ -0,0 +1,24 @@ +package hookhelper + +import "errors" + +// OptimisticVersion returns the calculated optimistic version +func OptimisticVersion(global, local []byte, globalVersion, localVersion string) (string, error) { + if nil != global { + if nil != local && localVersion != "" { + if localVersion == globalVersion && globalVersion == "" { + return "", errors.New("you have to provide versions for global and local config") + } + if localVersion != globalVersion { + return "", errors.New("version mismatch for global and project version") + } + } + return globalVersion, nil + } + + if nil != local { + return localVersion, nil + } + + return "", errors.New("no suitable versioned configuration found") +} From 2949e6d32ec1c2271f829bc67292bfa67d908d97 Mon Sep 17 00:00:00 2001 From: Sascha Andres Date: Mon, 4 Mar 2019 09:22:54 +0100 Subject: [PATCH 2/4] feat: add co-author support Co-authored-by lines can easily be longer than the usually enforced line length limit --- .idea/encodings.xml | 4 ++++ hook/v2/validate_body.go | 9 ++++++++- hook/v2/validate_body_test.go | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 .idea/encodings.xml create mode 100644 hook/v2/validate_body_test.go diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..15a15b2 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/hook/v2/validate_body.go b/hook/v2/validate_body.go index f41a953..c7789c5 100644 --- a/hook/v2/validate_body.go +++ b/hook/v2/validate_body.go @@ -1,11 +1,18 @@ package v2 -import "fmt" +import ( + "fmt" + "strings" +) // validateBody runs all rules for a commit message body func (cfg *Configuration) validateBody(commitMessage []string) bool { result := true for _, line := range commitMessage { + if strings.HasPrefix(line, "Co-authored-by") { + fmt.Println("Co-authored-by found, not checking line length") + continue + } if len(line) > cfg.BodyLineLength { if cfg.EnforceBodyLineLength { result = false diff --git a/hook/v2/validate_body_test.go b/hook/v2/validate_body_test.go new file mode 100644 index 0000000..5ec3cc8 --- /dev/null +++ b/hook/v2/validate_body_test.go @@ -0,0 +1 @@ +package v2 From 2634b7bde57fa9f2cd9d3429b6a7152d4407bb18 Mon Sep 17 00:00:00 2001 From: Sascha Andres Date: Mon, 4 Mar 2019 09:23:03 +0100 Subject: [PATCH 3/4] feat: add tests --- hook/v2/validate_body_test.go | 47 +++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/hook/v2/validate_body_test.go b/hook/v2/validate_body_test.go index 5ec3cc8..f2db558 100644 --- a/hook/v2/validate_body_test.go +++ b/hook/v2/validate_body_test.go @@ -1 +1,48 @@ package v2 + +import "testing" + +func TestLineLengthLastLine(t *testing.T) { + body := []string{ + "this is a normal length line", + "01234567890123456789012345678901234567890123456789012345678901234567890123456789", + } + cfg := &Configuration{ + BodyLineLength: 72, + EnforceBodyLineLength: true, + } + if cfg.validateBody(body) { + t.Log("line is too long, validation did not get it") + t.Fail() + } +} + +func TestLineLengthFirstLine(t *testing.T) { + body := []string{ + "01234567890123456789012345678901234567890123456789012345678901234567890123456789", + "this is a normal length line", + } + cfg := &Configuration{ + BodyLineLength: 72, + EnforceBodyLineLength: true, + } + if cfg.validateBody(body) { + t.Log("line is too long, validation did not get it") + t.Fail() + } +} + +func TestLineLengthCoAuthored(t *testing.T) { + body := []string{ + "this is a normal length line", + "Co-authored-by: This is the name ", + } + cfg := &Configuration{ + BodyLineLength: 72, + EnforceBodyLineLength: true, + } + if !cfg.validateBody(body) { + t.Log("co-authored lines should not be enforced to be max characters long") + t.Fail() + } +} From 5f6621db546ec9f24d79836db617e03ae899aa83 Mon Sep 17 00:00:00 2001 From: Sascha Andres Date: Mon, 4 Mar 2019 09:24:30 +0100 Subject: [PATCH 4/4] chore: update version info --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 6b89cea..52d9c05 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ Essentially this just removes the hook, so it would remove any other hook also. |Version|Description| |---|---| +|0.8.0|add support for Co-authored-by| |0.7.0|rename binary| |0.6.2|code quality improvements| |0.6.1|code quality improvements|