This repository has been archived by the owner on Jun 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
255 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: Go | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
test: | ||
strategy: | ||
matrix: | ||
go-version: [1.12.9, 1.13] | ||
platform: [ubuntu-latest, macos-latest, windows-latest] | ||
runs-on: ${{ matrix.platform }} | ||
steps: | ||
- name: Install Go | ||
uses: actions/setup-go@v1 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
- name: Checkout code | ||
uses: actions/checkout@v1 | ||
- name: Test | ||
run: go test ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,3 +70,4 @@ fabric.properties | |
.build/ | ||
dist/ | ||
coverage.txt | ||
coverage.tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package v2 | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
|
||
"livingit.de/code/gitconfd" | ||
) | ||
|
||
// ExecuteConfDDirectories run scrips in .commit-msg.d/ directory | ||
func (cfg *Configuration) ExecuteConfDDirectories() bool { | ||
if !cfg.ConfDDirectoriesEnabled { | ||
return true | ||
} | ||
|
||
path := filepath.Dir(os.Args[1]) | ||
|
||
return gitconfd.Execute(path, os.Args[0]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// +build !windows | ||
|
||
package v2 | ||
|
||
import "testing" | ||
|
||
func TestExternalTool(t *testing.T) { | ||
tests := map[string]struct { | ||
command string | ||
severity string | ||
result bool | ||
}{ | ||
"success": {"/bin/true", ErrorSeverity, true}, | ||
"warning": {"/bin/false", "warning", false}, | ||
"failure": {"/bin/false", ErrorSeverity, false}, | ||
} | ||
|
||
for k, v := range tests { | ||
t.Run(k, func(t *testing.T) { | ||
tools := make([]*Tool, 0) | ||
commands := make([]string, 0) | ||
commands = append(commands, v.command) | ||
tools = append(tools, &Tool{ | ||
Name: v.command, | ||
Severity: v.severity, | ||
Command: commands, | ||
}) | ||
cfg := &Configuration{ | ||
Externals: tools, | ||
} | ||
if result := cfg.runExternalTools(); result != v.result { | ||
t.Logf("for %s expected %t, received %t", k, v.result, result) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package v2 | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func runLinting(cfg Configuration, name string, res bool) { | ||
It(fmt.Sprintf("should return %v for \"%v\"", res, name), func() { | ||
Expect(cfg.validateGitLabCI()).To(Equal(res)) | ||
}) | ||
} | ||
|
||
var _ = Describe("GitLab CI linter", func() { | ||
runLinting(Configuration{LintGitLabCI: false}, "linter disabled", true) | ||
runLinting(Configuration{LintGitLabCI: true}, "linter enabled || not yet created", true) | ||
// runLinting(Configuration{LintGitLabCI: true, GitLabCIFile: "test.yml"}, "linter enabled || other config file", false) | ||
// runLinting(Configuration{LintGitLabCI: true, GitLabCIFile: "testdata/empty.yml"}, "linter enabled || empty file", true) | ||
}) | ||
|
||
func TestGitLabCILinter(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "GitLab CI linter") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package v2 | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestTicket(t *testing.T) { | ||
commitMessages := map[string]struct { | ||
expected bool | ||
value string | ||
}{ | ||
"in-subject": {true, `this is a normal length line TICKET-1 | ||
Hello`}, | ||
"in-body": {true, `this is a normal length line | ||
Hello TICKET-1`}, | ||
"not found": {false, "01234567890123456789012345678901234567890123456789012345678901234567890123456789"}, | ||
} | ||
|
||
expr := make([]*ExpressionWithSeverity, 0) | ||
|
||
expr = append(expr, &ExpressionWithSeverity{ | ||
Name: "find ticket", | ||
Expression: "^TICKET-\\d{1,3}:.*", | ||
}) | ||
|
||
cfg := &Configuration{ | ||
FindOccurrenceExpressions: expr, | ||
} | ||
|
||
err := cfg.setupRegularExpressions() | ||
if err != nil { | ||
t.Fatalf("error with regex: %s", err) | ||
} | ||
|
||
for k, v := range commitMessages { | ||
msg := strings.Split(v.value, "\n") | ||
t.Run(k, func(t *testing.T) { | ||
if result := cfg.validateOccurs(msg); result != v.expected { | ||
t.Logf("test %s failed: it is %t but should be %t", k, result, v.expected) | ||
} | ||
}) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package v2 | ||
|
||
import "testing" | ||
|
||
func TestSubjectLineLength(t *testing.T) { | ||
subjectLines := map[string]struct { | ||
expected bool | ||
value string | ||
}{ | ||
"right-length": {true, "this is a normal length line"}, | ||
"too-long": {false, "01234567890123456789012345678901234567890123456789012345678901234567890123456789"}, | ||
"no-subject-line": {false, ""}, | ||
} | ||
|
||
cfg := &Configuration{ | ||
SubjectLineLength: 50, | ||
} | ||
|
||
for k, v := range subjectLines { | ||
t.Run(k, func(t *testing.T) { | ||
if result := cfg.validateSubjectLine(v.value); result != v.expected { | ||
t.Logf("test %s failed: it is %t but should be %t", k, result, v.expected) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestOccurs(t *testing.T) { | ||
subjectLines := map[string]struct { | ||
expected bool | ||
value string | ||
}{ | ||
"found ticket": {true, "TICKET-1: hello world"}, | ||
"no ticket number": {false, "hello world without ticket"}, | ||
} | ||
|
||
expr := make([]*ExpressionWithSeverity, 0) | ||
|
||
expr = append(expr, &ExpressionWithSeverity{ | ||
Name: "find ticket", | ||
Expression: "^TICKET-\\d{1,3}:.*", | ||
}) | ||
|
||
cfg := &Configuration{ | ||
SubjectExpressions: expr, | ||
SubjectLineLength: 50, | ||
} | ||
|
||
err := cfg.setupRegularExpressions() | ||
if err != nil { | ||
t.Fatalf("error with regex: %s", err) | ||
} | ||
|
||
for k, v := range subjectLines { | ||
t.Run(k, func(t *testing.T) { | ||
if result := cfg.validateSubjectLine(v.value); result != v.expected { | ||
t.Logf("test %s failed: it is %t but should be %t", k, result, v.expected) | ||
} | ||
}) | ||
} | ||
} |