Skip to content

Commit

Permalink
feat: move body options to dedicated field
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
andrewrynhard committed Apr 10, 2020
1 parent fa7df19 commit b2f63c1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .conform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ policies:
imperative: true
case: lower
invalidLastCharacters: .
body:
required: true
dco: true
gpg: false
maximumOfOneCommit: true
requireCommitBody: true
conventional:
types:
- chore
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ policies:
imperative: true
case: lower
invalidLastCharacters: .
body:
required: true
dco: true
gpg: false
maximumOfOneCommit: true
requireCommitBody: true
conventional:
types:
- "type"
Expand Down
16 changes: 12 additions & 4 deletions internal/policy/commit/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b2f63c1

Please sign in to comment.