Sha256: 3cdff8ec1a72f5b4e9d5e21161045f15b84850a0cf902a448da9867a2ed9e80f

Contents?: true

Size: 929 Bytes

Versions: 5

Compression:

Stored size: 929 Bytes

Contents

# frozen_string_literal: true

module Git
  module Lint
    module Analyzers
      # Analyzes commit subject uses standard prefix.
      class CommitSubjectPrefix < Abstract
        def valid?
          return true if locally_prefixed?
          return true if filter_list.empty?

          commit.subject.match?(/\A#{Regexp.union filter_list}/)
        end

        def issue
          return {} if valid?

          {hint: %(Use: #{filter_list.to_usage "or"}.)}
        end

        protected

        def load_filter_list
          configuration.commits_subject_prefix_includes
                       .map { |prefix| "#{prefix}#{delimiter}" }
                       .then { |list| Kit::FilterList.new list }
        end

        def locally_prefixed? = !ci? && commit.directive?

        def ci? = environment["CI"] == "true"

        def delimiter = configuration.commits_subject_prefix_delimiter
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
git-lint-7.5.0 lib/git/lint/analyzers/commit_subject_prefix.rb
git-lint-7.3.0 lib/git/lint/analyzers/commit_subject_prefix.rb
git-lint-7.2.0 lib/git/lint/analyzers/commit_subject_prefix.rb
git-lint-7.1.0 lib/git/lint/analyzers/commit_subject_prefix.rb
git-lint-7.0.0 lib/git/lint/analyzers/commit_subject_prefix.rb