class Danger::DangerAngularCommitLint
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.
@example Lint all commits using defaults
angular_commit_lint.check
@example Warn instead of fail
angular_commit_lint.check warn: :all
@example Disable a particular check
angular_commit_lint.check disable: [:subject_period]
@see danger/danger @tags commit linting
Constants
- NOOP_MESSAGE
Public Instance Methods
check(config = {})
click to toggle source
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.
@param [Hash] config
@return [void]
# File lib/angular_commit_lint/plugin.rb, line 56 def check(config = {}) @config = config if all_checks_disabled? messaging.warn NOOP_MESSAGE else check_messages end end
Private Instance Methods
all_checks_disabled?()
click to toggle source
# File lib/angular_commit_lint/plugin.rb, line 120 def all_checks_disabled? @config[:disable] == :all || disabled_checks.count == checkers.count end
check_fails(message)
click to toggle source
# File lib/angular_commit_lint/plugin.rb, line 84 def check_fails(message) for klass in failing_checkers klass_instance = klass.new(message, @config) if klass_instance.fail? issue_failure(klass_instance.message, message[:sha]) end end end
check_messages()
click to toggle source
# File lib/angular_commit_lint/plugin.rb, line 68 def check_messages for message in messages check_warnings message check_fails message end end
check_warnings(message)
click to toggle source
# File lib/angular_commit_lint/plugin.rb, line 75 def check_warnings(message) for klass in warning_checkers klass_instance = klass.new(message, @config) if klass_instance.fail? issue_warning(klass_instance.message, message[:sha]) end end end
checkers()
click to toggle source
# File lib/angular_commit_lint/plugin.rb, line 93 def checkers [ SubjectPatternCheck, SubjectCapCheck, SubjectWordsCheck, SubjectLengthCheck, SubjectPeriodCheck, EmptyLineCheck ] end
checks()
click to toggle source
# File lib/angular_commit_lint/plugin.rb, line 104 def checks checkers.map(&:type) end
disabled_checks()
click to toggle source
# File lib/angular_commit_lint/plugin.rb, line 124 def disabled_checks @config[:disable] || [] end
enabled_checkers()
click to toggle source
# File lib/angular_commit_lint/plugin.rb, line 108 def enabled_checkers checkers.reject { |klass| disabled_checks.include? klass.type } end
failing_checkers()
click to toggle source
# File lib/angular_commit_lint/plugin.rb, line 116 def failing_checkers enabled_checkers - warning_checkers end
issue_failure(message, sha)
click to toggle source
# File lib/angular_commit_lint/plugin.rb, line 148 def issue_failure(message, sha) messaging.fail [message, sha].join("\n") end
issue_warning(message, sha)
click to toggle source
# File lib/angular_commit_lint/plugin.rb, line 144 def issue_warning(message, sha) messaging.warn [message, sha].join("\n") end
messages()
click to toggle source
# File lib/angular_commit_lint/plugin.rb, line 133 def messages git.commits.map do |commit| (subject, empty_line) = commit.message.split("\n") { subject: subject, empty_line: empty_line, sha: commit.sha } end end
warning_checkers()
click to toggle source
# File lib/angular_commit_lint/plugin.rb, line 112 def warning_checkers enabled_checkers.select { |klass| warning_checks.include? klass.type } end
warning_checks()
click to toggle source
# File lib/angular_commit_lint/plugin.rb, line 128 def warning_checks return checks if @config[:warn] == :all @config[:warn] || [] end