Sha256: 19d56694d7fd8cb546761daf596793dd184634994c2f595e5fddc314d52f9378

Contents?: true

Size: 1.21 KB

Versions: 7

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

module Git
  module Lint
    module Analyzers
      class CommitTrailerCollaboratorKey < Abstract
        def self.defaults
          {
            enabled: true,
            severity: :error,
            includes: ["Co-Authored-By"]
          }
        end

        def initialize commit:,
                       settings: self.class.defaults,
                       parser: Parsers::Trailers::Collaborator
          super commit: commit, settings: settings
          @parser = parser
        end

        def valid?
          affected_commit_trailer_lines.empty?
        end

        def issue
          return {} if valid?

          {
            hint: "Use format: #{filter_list.to_hint}.",
            lines: affected_commit_trailer_lines
          }
        end

        protected

        def load_filter_list
          Kit::FilterList.new settings.fetch :includes
        end

        def invalid_line? line
          collaborator = parser.new line
          key = collaborator.key

          collaborator.match? && !key.empty? && !key.match?(
            /\A#{Regexp.union filter_list.to_regexp}\Z/
          )
        end

        private

        attr_reader :parser
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
git-lint-1.4.0 lib/git/lint/analyzers/commit_trailer_collaborator_key.rb
git-lint-1.3.0 lib/git/lint/analyzers/commit_trailer_collaborator_key.rb
git-lint-1.2.0 lib/git/lint/analyzers/commit_trailer_collaborator_key.rb
git-lint-1.1.1 lib/git/lint/analyzers/commit_trailer_collaborator_key.rb
git-lint-1.1.0 lib/git/lint/analyzers/commit_trailer_collaborator_key.rb
git-lint-1.0.1 lib/git/lint/analyzers/commit_trailer_collaborator_key.rb
git-lint-1.0.0 lib/git/lint/analyzers/commit_trailer_collaborator_key.rb