Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(policy): Make Conventional commit description configurable #156

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ policies:
- "type"
scopes:
- "scope"
descriptionLength: 72
- type: license
spec:
skipPaths:
Expand Down
11 changes: 8 additions & 3 deletions internal/policy/commit/check_conventional_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import (
// Conventional implements the policy.Policy interface and enforces commit
// messages to conform the Conventional Commit standard.
type Conventional struct {
Types []string `mapstructure:"types"`
Scopes []string `mapstructure:"scopes"`
Types []string `mapstructure:"types"`
Scopes []string `mapstructure:"scopes"`
DescriptionLength int `mapstructure:"descriptionLength"`
}

// HeaderRegex is the regular expression used for Conventional Commits
Expand Down Expand Up @@ -94,7 +95,11 @@ func (c Commit) ValidateConventionalCommit() policy.Check {
}
}

if len(groups[4]) <= 72 && len(groups[4]) != 0 {
// Provide a good default value for DescriptionLength
if c.Conventional.DescriptionLength == 0 {
c.Conventional.DescriptionLength = 72
}
if len(groups[4]) <= c.Conventional.DescriptionLength && len(groups[4]) != 0 {
return check
}
check.errors = append(check.errors, errors.Errorf("Invalid description: %s", groups[4]))
Expand Down