Skip to content

Commit

Permalink
feat(policy): enforce 72 character limit on commit header (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrynhard authored Jul 22, 2017
1 parent 6a115cf commit 9383d3e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions conform/policy/conventionalcommit/conventionalcommit.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ type Conventional struct {
Scopes []string `mapstructure:"scopes"`
}

// MaxNumberOfCommitCharacters is the maximium number of characters allowed in
// a commit header.
const MaxNumberOfCommitCharacters = 72

// HeaderRegex is the regular expression used for Conventional Commits
// 1.0.0-beta.1.
const HeaderRegex = `^(\w*)\(([^)]+)\):\s{1}(.*)($|\n{2})`
Expand All @@ -41,6 +45,7 @@ func (c *Conventional) Compliance(metadata *metadata.Metadata, options ...policy
report.Errors = append(report.Errors, fmt.Errorf("Invalid commit format"))
return
}
ValidateHeaderLength(&report, groups)
ValidateType(&report, groups, c.Types)
ValidateScope(&report, groups, c.Scopes)
ValidateDescription(&report, groups)
Expand All @@ -58,6 +63,13 @@ func (c *Conventional) Tasks(map[string]*task.Task) policy.Option {
return func(args *policy.Options) {}
}

// ValidateHeaderLength checks the header length.
func ValidateHeaderLength(report *policy.Report, groups []string) {
if len(groups[1]) > MaxNumberOfCommitCharacters {
report.Errors = append(report.Errors, fmt.Errorf("Commit header is %d characters", len(groups[1])))
}
}

// ValidateType returns the commit type.
func ValidateType(report *policy.Report, groups []string, types []string) {
types = append(types, TypeFeat, TypeFix)
Expand Down

0 comments on commit 9383d3e

Please sign in to comment.