Class: Danger::DangerSemanticCommit

Inherits:
Plugin
  • Object
show all
Defined in:
lib/semantic_commit/plugin.rb

Overview

Run each commit in the PR through a message linting.

Semantic commit lint will validate each commit in the PR to ensure the
following is true:

* Commit subject begins with a type
* Commit subject is no longer than 70 characters (`length`)

By default, Semantic Commit Lint fails, but you can configure this behavior.

Examples:

Lint all commits using defaults


semantic_commit.validate

Warn instead of fail


semantic_commit.validate warn: :all

Disable a particular validator


semantic_commit.validate disable: [:length]

Configure semantic types


semantic_commit.validate types: ["feat", "fix", "docs"]

Configure length


semantic_commit.validate length: 100

See Also:

  • danger/danger

Instance Method Summary collapse

Instance Method Details

#validate(config = {}) ⇒ void

This method returns an undefined value.

Validates the commits with whatever config the user passes.

Passing in a hash which contain the following keys:

* `disable` - array of checks to skip
* `fail` - array of checks to fail on
* `warn` - array of checks to warn on

The current check types are:

* `length`

Note: you can pass :all instead of an array to target all checks.

Parameters:

  • config (Hash) (defaults to: {})


57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/semantic_commit/plugin.rb', line 57

def validate(config = {})
  self.config = config

  commits.each do |commit|
    enabled_validators.each do |validator|
      if !validator.valid?(commit)
        message = validator.message(commit)
        messaging.fail([message, commit.fetch(:sha)].join("\n"))
      end
    end
  end
end