Sha256: 02a2b6a7dc3f027a5494fa68e16ce1f2cb4f7652f9663c096eaa8e2bae9c87b7

Contents?: true

Size: 1.75 KB

Versions: 5

Compression:

Stored size: 1.75 KB

Contents

# frozen_string_literal: true

require "pastel"

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

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

        def to_s
          "Running #{Identity::LABEL}...#{branch_report}\n" \
          "#{commit_total}. #{issue_totals}.\n"
        end

        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: commit, analyzers: analyzers).to_s
          end
        end

        def commit_total
          %(#{"commit".pluralize count: collector.total_commits} 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
          colorizer.public_send color, "issue".pluralize(count: collector.total_issues)
        end

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

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
git-lint-2.4.0 lib/git/lint/reporters/branch.rb
git-lint-2.3.3 lib/git/lint/reporters/branch.rb
git-lint-2.3.2 lib/git/lint/reporters/branch.rb
git-lint-2.3.1 lib/git/lint/reporters/branch.rb
git-lint-2.3.0 lib/git/lint/reporters/branch.rb