Skip to content
This repository has been archived by the owner on Jun 9, 2023. It is now read-only.

Commit

Permalink
merge: branch 'release/0.8.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
sascha-andres committed Mar 4, 2019
2 parents 3716d5f + 5f6621d commit 8e72b7a
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
9 changes: 8 additions & 1 deletion hook/v2/validate_body.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
48 changes: 48 additions & 0 deletions hook/v2/validate_body_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +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 <this-is-a-long@email-address-to-get-over71.de>",
}
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()
}
}
9 changes: 9 additions & 0 deletions vendor/livingit.de/code/go-hookhelper/README.md
Original file line number Diff line number Diff line change
@@ -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|
24 changes: 24 additions & 0 deletions vendor/livingit.de/code/go-hookhelper/optimistic_version.go
Original file line number Diff line number Diff line change
@@ -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")
}

0 comments on commit 8e72b7a

Please sign in to comment.