Class: Danger::SemanticCommit::TypeValidator

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

Instance Method Summary collapse

Constructor Details

#initialize(types) ⇒ TypeValidator

Returns a new instance of TypeValidator.



4
5
6
# File 'lib/semantic_commit/type_validator.rb', line 4

def initialize(types)
  @types = types || default_types
end

Instance Method Details

#message(_commit) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/semantic_commit/type_validator.rb', line 14

def message(_commit)
  <<~MSG
    Commit is missing a type.  Start your commit with one of the following:
    #{types.join(',')}

    For more information see: [http://karma-runner.github.io/1.0/dev/git-commit-msg.html](http://karma-runner.github.io/1.0/dev/git-commit-msg.html)
  MSG
end

#valid?(commit) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
12
# File 'lib/semantic_commit/type_validator.rb', line 8

def valid?(commit)
  subject = commit.fetch(:subject)

  type_from(subject) && types.include?(type_from(subject))
end