From b9413c60c83d6f25d8979292d09ddceff0cde111 Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Mon, 5 Oct 2015 19:02:31 -0400 Subject: [PATCH] shortsubject: add a subject length check Signed-off-by: Vincent Batts --- main.go | 1 + rules/shortsubject/rule.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 rules/shortsubject/rule.go diff --git a/main.go b/main.go index 09ac685..e6e843b 100644 --- a/main.go +++ b/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" ) diff --git a/rules/shortsubject/rule.go b/rules/shortsubject/rule.go new file mode 100644 index 0000000..adebe64 --- /dev/null +++ b/rules/shortsubject/rule.go @@ -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 +}