mirror of
https://github.com/vbatts/git-validation.git
synced 2025-01-29 22:57:33 +00:00
shortsubject: add a subject length check
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
5e74abd1b2
commit
b9413c60c8
2 changed files with 31 additions and 0 deletions
1
main.go
1
main.go
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
"github.com/vbatts/git-validation/git"
|
||||
_ "github.com/vbatts/git-validation/rules/dco"
|
||||
_ "github.com/vbatts/git-validation/rules/shortsubject"
|
||||
"github.com/vbatts/git-validation/validate"
|
||||
)
|
||||
|
||||
|
|
30
rules/shortsubject/rule.go
Normal file
30
rules/shortsubject/rule.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
package shortsubject
|
||||
|
||||
import (
|
||||
"github.com/vbatts/git-validation/git"
|
||||
"github.com/vbatts/git-validation/validate"
|
||||
)
|
||||
|
||||
var (
|
||||
// DcoRule is the rule being registered
|
||||
ShortSubjectRule = validate.Rule{
|
||||
Name: "short-subject",
|
||||
Description: "commit subjects are strictly less than 90 (github ellipsis length)",
|
||||
Run: ValidateShortSubject,
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
validate.RegisterRule(ShortSubjectRule)
|
||||
}
|
||||
|
||||
func ValidateShortSubject(c git.CommitEntry) (vr validate.Result) {
|
||||
if len(c["subject"]) >= 90 {
|
||||
vr.Pass = false
|
||||
vr.Msg = "commit subject exceeds 90 characters"
|
||||
return
|
||||
}
|
||||
vr.Pass = true
|
||||
vr.Msg = "commit subject is not more than 90 characters"
|
||||
return
|
||||
}
|
Loading…
Reference in a new issue