Class: Danger::DangerWCC::CommitLint

Inherits:
Object
  • Object
show all
Defined in:
lib/wcc/commit_lint.rb

Overview

Run each commit in the PR through a message linting.

Commit lint will check each commit in the PR to ensure the following is
true:

* Commit subject begins with a capital letter (`subject_cap`)
* Commit subject is more than one word (`subject_word`)
* Commit subject is no longer than 50 characters (`subject_length`)
* Commit subject does not end in a period (`subject_period`)
* Commit subject and body are separated by an empty line (`empty_line`)

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

Examples:

Lint all commits using defaults


commit_lint.check

Warn instead of fail


commit_lint.check warn: :all

Disable a particular check


commit_lint.check disable: [:subject_period]

See Also:

  • danger/danger

Constant Summary collapse

NOOP_MESSAGE =
'All checks were disabled, nothing to do.'

Instance Method Summary collapse

Constructor Details

#initialize(plugin, config = {}) ⇒ CommitLint

Returns a new instance of CommitLint.



43
44
45
46
# File 'lib/wcc/commit_lint.rb', line 43

def initialize(plugin, config = {})
  @plugin = plugin
  @config = config
end

Instance Method Details

#gitObject



48
49
50
# File 'lib/wcc/commit_lint.rb', line 48

def git
  @plugin.git
end

#messagingObject



52
53
54
# File 'lib/wcc/commit_lint.rb', line 52

def messaging
  @plugin
end

#performvoid

This method returns an undefined value.

Checks 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:

* `subject_cap`
* `subject_word`
* `subject_length`
* `subject_period`
* `empty_line`

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

Parameters:

  • config (Hash)


78
79
80
81
82
83
84
# File 'lib/wcc/commit_lint.rb', line 78

def perform
  if all_checks_disabled?
    messaging.warn NOOP_MESSAGE
  else
    check_messages
  end
end