-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support regex in conventional commit scope
This allows for regular expressions to be used in the scope of a conventional commit. Signed-off-by: Andrew Rynhard <[email protected]>
- Loading branch information
1 parent
ec5e365
commit 72708f2
Showing
2 changed files
with
72 additions
and
2 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 |
---|---|---|
|
@@ -128,6 +128,7 @@ func TestValidateDCO(t *testing.T) { | |
} | ||
} | ||
|
||
// nolint: dupl | ||
func TestValidConventionalCommitPolicy(t *testing.T) { | ||
dir, err := ioutil.TempDir("", "test") | ||
if err != nil { | ||
|
@@ -211,11 +212,67 @@ func TestEmptyConventionalCommitPolicy(t *testing.T) { | |
} | ||
} | ||
|
||
// nolint: dupl | ||
func TestValidConventionalCommitPolicyRegex(t *testing.T) { | ||
dir, err := ioutil.TempDir("", "test") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer RemoveAll(dir) | ||
err = os.Chdir(dir) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
err = initRepo() | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
err = createValidCommitRegex() | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
report, err := runCompliance() | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
if !report.Valid() { | ||
t.Error("Report is invalid with valid conventional commit") | ||
} | ||
} | ||
|
||
// nolint: dupl | ||
func TestInvalidConventionalCommitPolicyRegex(t *testing.T) { | ||
dir, err := ioutil.TempDir("", "test") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer RemoveAll(dir) | ||
err = os.Chdir(dir) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
err = initRepo() | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
err = createInvalidCommitRegex() | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
report, err := runCompliance() | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
if report.Valid() { | ||
t.Error("Report is valid with invalid conventional commit") | ||
} | ||
} | ||
|
||
func runCompliance() (*policy.Report, error) { | ||
c := &Commit{ | ||
Conventional: &Conventional{ | ||
Types: []string{"type"}, | ||
Scopes: []string{"scope"}, | ||
Scopes: []string{"scope", "^valid"}, | ||
}, | ||
} | ||
|
||
|
@@ -253,3 +310,15 @@ func createEmptyCommit() error { | |
|
||
return err | ||
} | ||
|
||
func createValidCommitRegex() error { | ||
_, err := exec.Command("git", "-c", "user.name='test'", "-c", "user.email='[email protected]'", "commit", "-m", "type(valid-1): description").Output() | ||
|
||
return err | ||
} | ||
|
||
func createInvalidCommitRegex() error { | ||
_, err := exec.Command("git", "-c", "user.name='test'", "-c", "user.email='[email protected]'", "commit", "-m", "type(invalid-1): description").Output() | ||
|
||
return err | ||
} |