Sha256: f0848b063c9eb5da5238fde622bac87bb606f04647d2b7c14c916f4d77d07009

Contents?: true

Size: 1.81 KB

Versions: 8

Compression:

Stored size: 1.81 KB

Contents

# frozen_string_literal: true

module Git
  module Lint
    module Reporters
      # Reports issues related to a single branch.
      class Branch
        include Import[:color]
        using ::Refinements::Strings

        def initialize(collector: Collector.new, **)
          super(**)
          @collector = collector
        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

        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
            color["0 issues", :green] + " detected"
          end
        end

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

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

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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
git-lint-6.2.1 lib/git/lint/reporters/branch.rb
git-lint-6.2.0 lib/git/lint/reporters/branch.rb
git-lint-6.1.0 lib/git/lint/reporters/branch.rb
git-lint-6.0.2 lib/git/lint/reporters/branch.rb
git-lint-6.0.1 lib/git/lint/reporters/branch.rb
git-lint-6.0.0 lib/git/lint/reporters/branch.rb
git-lint-5.3.0 lib/git/lint/reporters/branch.rb
git-lint-5.2.0 lib/git/lint/reporters/branch.rb