Sha256: 18b38098611825147955f6e58ec887f6693e98190dff9de063451924da68aa2d

Contents?: true

Size: 736 Bytes

Versions: 1

Compression:

Stored size: 736 Bytes

Contents

module Danger
  module SemanticCommit
    class TypeValidator
      def initialize(types)
        @types = types || default_types
      end

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

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

      def message(_commit)
        "Commit is missing a type"
      end

      private

      attr_reader :types

      def type_from(subject)
        if matches = subject.match(/^(?<type>\w+)(\(|:)/)
          matches[:type]
        end
      end

      def default_types
        [
          "chore",
          "docs",
          "feat",
          "fix",
          "refactor",
          "style",
          "test",
        ]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
danger-semantic-commit-0.2.0 lib/semantic_commit/type_validator.rb