mirror of
https://github.com/vbatts/git-validation.git
synced 2025-06-04 02:52:28 +00:00
message_regexp: regular expression rule for messages
Fixes: #30 now you can add a regular expression to the rules to be run i.e. `git-validation -run "dco,message_regexp='^JIRA-[0-9]+ [A-Z].*$'"` Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
d9bf419b44
commit
00823a324b
8 changed files with 89 additions and 10 deletions
|
@ -9,7 +9,7 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
// RegisteredRules are the standard validation to perform on git commits
|
||||
// RegisteredRules are the avaible validation to perform on git commits
|
||||
RegisteredRules = []Rule{}
|
||||
registerRuleLock = sync.Mutex{}
|
||||
)
|
||||
|
@ -26,14 +26,15 @@ type Rule struct {
|
|||
Name string // short name for reference in in the `-run=...` flag
|
||||
Value string // value to configure for the rule (i.e. a regexp to check for in the commit message)
|
||||
Description string // longer Description for readability
|
||||
Run func(git.CommitEntry) Result
|
||||
Run func(Rule, git.CommitEntry) Result
|
||||
Default bool // whether the registered rule is run by default
|
||||
}
|
||||
|
||||
// Commit processes the given rules on the provided commit, and returns the result set.
|
||||
func Commit(c git.CommitEntry, rules []Rule) Results {
|
||||
results := Results{}
|
||||
for _, r := range rules {
|
||||
results = append(results, r.Run(c))
|
||||
results = append(results, r.Run(r, c))
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ func TestSliceHelpers(t *testing.T) {
|
|||
for i := range set {
|
||||
got := StringsSliceEqual(set[i].A, set[i].B)
|
||||
if got != set[i].Equal {
|
||||
t.Errorf("expected %d A and B comparison to be %q, but got %q", i, set[i].Equal, got)
|
||||
t.Errorf("expected %d A and B comparison to be %t, but got %t", i, set[i].Equal, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue