From b2f63c178998589d9f6f0273842ca38cc425a84d Mon Sep 17 00:00:00 2001 From: Andrew Rynhard Date: Fri, 10 Apr 2020 16:02:46 -0700 Subject: [PATCH] feat: move body options to dedicated field This adds a `body` field for options related to the commit body. BREAKING CHANGE: This moves `spec.requireCommitBody` to `spec.body.required`. Signed-off-by: Andrew Rynhard --- .conform.yaml | 3 ++- README.md | 3 ++- internal/policy/commit/commit.go | 16 ++++++++++++---- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.conform.yaml b/.conform.yaml index 277f3871..e6a729a1 100644 --- a/.conform.yaml +++ b/.conform.yaml @@ -6,10 +6,11 @@ policies: imperative: true case: lower invalidLastCharacters: . + body: + required: true dco: true gpg: false maximumOfOneCommit: true - requireCommitBody: true conventional: types: - chore diff --git a/README.md b/README.md index cacc5e83..1163b34b 100644 --- a/README.md +++ b/README.md @@ -47,10 +47,11 @@ policies: imperative: true case: lower invalidLastCharacters: . + body: + required: true dco: true gpg: false maximumOfOneCommit: true - requireCommitBody: true conventional: types: - "type" diff --git a/internal/policy/commit/commit.go b/internal/policy/commit/commit.go index 096ee274..cb90aea5 100644 --- a/internal/policy/commit/commit.go +++ b/internal/policy/commit/commit.go @@ -27,6 +27,12 @@ type HeaderChecks struct { InvalidLastCharacters string `mapstructure:"invalidLastCharacters"` } +// BodyChecks is the configuration for checks on the body of a commit. +type BodyChecks struct { + // Required enforces that the current commit has a body. + Required bool `mapstructure:"required"` +} + // Commit implements the policy.Policy interface and enforces commit // messages to conform the Conventional Commit standard. type Commit struct { @@ -37,12 +43,12 @@ type Commit struct { // MaximumOfOneCommit enforces that the current commit is only one commit // ahead of a specified ref. MaximumOfOneCommit bool `mapstructure:"maximumOfOneCommit"` - // RequireCommitBody enforces that the current commit has a body. - RequireCommitBody bool `mapstructure:"requireCommitBody"` // Conventional is the user specified settings for conventional commits. Conventional *Conventional `mapstructure:"conventional"` // Header is the user specified settings for the header of each commit. Header *HeaderChecks `mapstructure:"header"` + // Header is the user specified settings for the body of each commit. + Body *BodyChecks `mapstructure:"body"` msg string } @@ -111,8 +117,10 @@ func (c *Commit) Compliance(options *policy.Options) (*policy.Report, error) { report.AddCheck(c.ValidateNumberOfCommits(g, "refs/heads/master")) } - if c.RequireCommitBody { - report.AddCheck(c.ValidateBody()) + if c.Body != nil { + if c.Body.Required { + report.AddCheck(c.ValidateBody()) + } } return report, nil