Sha256: 5d61b388b6dfea19d50fa1877ab53e071b010df9c4b928930a304af4ea3c31fe

Contents?: true

Size: 1.89 KB

Versions: 17

Compression:

Stored size: 1.89 KB

Contents

# frozen_string_literal: true

require "pastel"

module Git
  module Lint
    module Reporters
      # Reports issues related to a single branch.
      class Branch
        using ::Refinements::Strings

        def initialize collector: Collector.new, colorizer: Pastel.new
          @collector = collector
          @colorizer = colorizer
        end

        def to_s
          "Running Git Lint...#{branch_report}\n" \
          "#{commit_total}. #{issue_totals}.\n"
        end

        alias to_str to_s

        private

        attr_reader :collector, :colorizer

        def branch_report
          return "" unless collector.issues?

          "\n\n#{commit_report}".chomp
        end

        def commit_report
          collector.to_h.reduce "" do |details, (commit, analyzers)|
            details + Commit.new(commit:, analyzers:)
          end
        end

        def commit_total
          total = collector.total_commits
          %(#{total} #{"commit".pluralize "s", count: total} inspected)
        end

        def issue_totals
          if collector.issues?
            "#{issue_total} detected (#{warning_total}, #{error_total})"
          else
            colorizer.green("0 issues") + " detected"
          end
        end

        def issue_total
          color = collector.errors? ? :red : :yellow
          total = collector.total_issues
          colorizer.public_send color, "#{total} issue".pluralize("s", count: total)
        end

        def warning_total
          color = collector.warnings? ? :yellow : :green
          total = collector.total_warnings
          colorizer.public_send color, "#{total} warning".pluralize("s", count: total)
        end

        def error_total
          color = collector.errors? ? :red : :green
          total = collector.total_errors
          colorizer.public_send color, "#{total} error".pluralize("s", count: total)
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
git-lint-5.1.2 lib/git/lint/reporters/branch.rb
git-lint-5.1.1 lib/git/lint/reporters/branch.rb
git-lint-5.1.0 lib/git/lint/reporters/branch.rb
git-lint-5.0.0 lib/git/lint/reporters/branch.rb
git-lint-4.6.0 lib/git/lint/reporters/branch.rb
git-lint-4.5.0 lib/git/lint/reporters/branch.rb
git-lint-4.4.0 lib/git/lint/reporters/branch.rb
git-lint-4.3.0 lib/git/lint/reporters/branch.rb
git-lint-4.2.0 lib/git/lint/reporters/branch.rb
git-lint-4.1.0 lib/git/lint/reporters/branch.rb
git-lint-4.0.1 lib/git/lint/reporters/branch.rb
git-lint-4.0.0 lib/git/lint/reporters/branch.rb
git-lint-3.3.2 lib/git/lint/reporters/branch.rb
git-lint-3.3.1 lib/git/lint/reporters/branch.rb
git-lint-3.3.0 lib/git/lint/reporters/branch.rb
git-lint-3.2.0 lib/git/lint/reporters/branch.rb
git-lint-3.1.0 lib/git/lint/reporters/branch.rb