-
Notifications
You must be signed in to change notification settings - Fork 0
Add JSON, color, verbose output modes, add text output for default UX, configure logger AddSource dynamically #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7bb8a71
test: Add config load tests
thumbrise 4d6d856
chore: Add build task
thumbrise 581c448
test: Add composed scope case in scope_parser_test.go
thumbrise 5ad6d14
fix: No more early return if config not found - apply default config …
thumbrise d75cecb
feat: Change Validator logs to debug level
thumbrise e7d0903
feat: Add JSON, color, verbose output modes, add text output for defa…
thumbrise 3c9d4ba
fix: Merge json outputs in one json
thumbrise bc25007
test: Replace os.Chdir defer with t.Cleanup in config_test.go
thumbrise 55b7126
test: Add malformed config test case in config_test.go
thumbrise File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| .idea | ||
| node_modules | ||
| commitlint-scope | ||
| build/* |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -24,3 +24,9 @@ tasks: | |
| - gen | ||
| cmds: | ||
| - go tool mockery | ||
|
|
||
| build: | ||
| desc: Build | ||
| cmds: | ||
| - mkdir -p build | ||
| - go build -o build/ | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,104 @@ | ||
| package validator_test | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| "github.com/thumbrise/commitlint-scope/pkg/validator" | ||
| ) | ||
|
|
||
| func TestLoadConfig(t *testing.T) { | ||
| defaultRegexStr := `^[a-z]+(?:\((?P<scope>[^)]+)\))?!?:\s` | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| yaml string | ||
| wantRegexNil bool | ||
| wantRegex string | ||
| wantPatterns map[string][]string | ||
| wantErr error | ||
| }{ | ||
| { | ||
| name: "no config file", | ||
| wantRegex: defaultRegexStr, | ||
| }, | ||
| { | ||
| name: "patterns with default regex", | ||
| yaml: `patterns: | ||
| api: | ||
| - api/* | ||
| core: | ||
| - core/** | ||
| `, | ||
| wantRegex: defaultRegexStr, | ||
| wantPatterns: map[string][]string{ | ||
| "api": {"api/*"}, | ||
| "core": {"core/**"}, | ||
| }, | ||
| }, | ||
| { | ||
| name: "custom scopeRegex only", | ||
| yaml: `scopeRegex: '^(feat|fix):' | ||
| `, | ||
| wantRegex: `^(feat|fix):`, | ||
| }, | ||
| { | ||
| name: "both patterns and custom scopeRegex", | ||
| yaml: `scopeRegex: '^(feat|fix):' | ||
| patterns: | ||
| api: | ||
| - api/* | ||
| `, | ||
| wantRegex: `^(feat|fix):`, | ||
| wantPatterns: map[string][]string{ | ||
| "api": {"api/*"}, | ||
| }, | ||
| }, | ||
| { | ||
| name: "malformed config", | ||
| yaml: "[[invalid", | ||
| wantErr: validator.ErrConfigRead, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| dir := t.TempDir() | ||
| origDir, err := os.Getwd() | ||
| require.NoError(t, err) | ||
|
|
||
| t.Cleanup(func() { | ||
| require.NoError(t, os.Chdir(origDir)) | ||
| }) | ||
|
|
||
| require.NoError(t, os.Chdir(dir)) | ||
|
|
||
| if tt.yaml != "" { | ||
| err = os.WriteFile(filepath.Join(dir, ".commitlint-scope.yaml"), []byte(tt.yaml), 0o644) | ||
| require.NoError(t, err) | ||
| } | ||
|
|
||
| cfg, err := validator.LoadConfig() | ||
| if tt.wantErr != nil { | ||
| require.Error(t, err) | ||
| assert.ErrorIs(t, err, tt.wantErr) | ||
|
|
||
| return | ||
| } | ||
|
|
||
| require.NoError(t, err) | ||
|
|
||
| if tt.wantRegexNil { | ||
| assert.Nil(t, cfg.ScopeRegex) | ||
| } else { | ||
| require.NotNil(t, cfg.ScopeRegex) | ||
| assert.Equal(t, tt.wantRegex, cfg.ScopeRegex.String()) | ||
| } | ||
|
|
||
| assert.Equal(t, tt.wantPatterns, cfg.Patterns) | ||
| }) | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.