Class: Danger::DangerAngularCommitLint::SubjectPatternCheck

Inherits:
CommitCheck
  • Object
show all
Defined in:
lib/angular_commit_lint/subject_pattern_check.rb

Overview

:nodoc:

Constant Summary collapse

DEFAULT_TYPES =
%w[fix feat docs style refactor test chore].freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CommitCheck

fail?

Constructor Details

#initialize(message, config = {}) ⇒ SubjectPatternCheck

Returns a new instance of SubjectPatternCheck.



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/angular_commit_lint/subject_pattern_check.rb', line 25

def initialize(message, config = {})
  @commit_types = config.fetch(:commit_types, DEFAULT_TYPES)
  @use_scope = config.fetch(:use_scope, true)
  @min_scope = config.fetch(:min_scope, 1)
  @require_scope = config.fetch(:require_scope, false)
  scope_regex = ''
  if @use_scope
    scope_regex = "(\\([a-zA-Z0-9-]{#{@min_scope},}\\)|\\(\\)#{@require_scope ? '' : '|'})"
  end
  @regex_string = "^(#{@commit_types.join '|'})#{scope_regex}: .+$"
  @subject = message[:subject]
end

Class Method Details

.typeObject



21
22
23
# File 'lib/angular_commit_lint/subject_pattern_check.rb', line 21

def self.type
  :subject_pattern
end

Instance Method Details

#fail?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/angular_commit_lint/subject_pattern_check.rb', line 38

def fail?
  (@subject =~ Regexp.new(@regex_string)).nil?
end

#messageObject



12
13
14
15
16
17
18
19
# File 'lib/angular_commit_lint/subject_pattern_check.rb', line 12

def message
  scope_option = @use_scope ? '(<scope>)' : ''
  scope_required = ''
  if @use_scope
    scope_required = "\n<scope> must be at least #{@min_scope} characters#{@scope_required ? 'or ommitted' : ''}"
  end
  "Please follow the commit format `<type>#{scope_option}: <subject>`.#{scope_required}\n`<type>` must be one of #{@commit_types.join ', '}".freeze
end