Class: Audition::Report::Sweep

Inherits:
Object
  • Object
show all
Defined in:
lib/audition/report/sweep.rb

Overview

Renders a bundle sweep. Its unit is a gem rather than a finding, so it gets its own renderer instead of bending Report around a shape it does not have.

Constant Summary collapse

CELLS =
{
  :not_ready => "not ready", :blocked => "blocked",
  :risky => "risky", :ready => "ready", nil => "-"
}.freeze
GLYPHS =

The severity glyphs the text report uses, so a verdict reads the same in a cell as it does in a summary.

{
  not_ready: :error, blocked: :warning,
  risky: :warning, ready: :pass
}.freeze
PAINTS =

Foreground only, and applied to the whole row: a background fill reads as a bar across the table, and a painted cell would widen its column by the invisible length of its own escape sequence. Ready gems keep the default color, so what is colored is what needs reading.

Ractor.make_shareable({
  :not_ready => [:red], :blocked => [:magenta],
  :risky => [:yellow], nil => [:faint]
})
TITLE =
"Audition bundle sweep"

Instance Method Summary collapse

Constructor Details

#initialize(rows, style) ⇒ Sweep

Returns a new instance of Sweep.

Parameters:



38
39
40
41
# File 'lib/audition/report/sweep.rb', line 38

def initialize(rows, style)
  @rows = rows
  @style = style
end

Instance Method Details

#annotations ⇒ String

Sweep rows carry no file or line, so annotations land on the run summary rather than a diff.

Returns:

  • (String) —

    annotation lines plus a summary line



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/audition/report/sweep.rb', line 63

def annotations
  lines = @rows.filter_map do |row|
    level = annotation_level(row)
    next unless level

    "::#{level} title=Audition::gem #{row.name} " \
    "#{row.version}: #{row.errors} errors, " \
    "#{row.dep_errors} dependency errors, " \
    "#{row.warnings} warnings (#{CELLS.fetch(row.verdict)})"
  end
  (lines << plain_summary).join("\n")
end

#json ⇒ Object



52
53
54
55
56
57
58
# File 'lib/audition/report/sweep.rb', line 52

def json
  JSON.pretty_generate(
    "audition" => VERSION,
    "ruby" => RUBY_VERSION,
    "bundle" => @rows.map { |r| json_row(r) }
  )
end

#markdown ⇒ String

Returns job summary page table for Actions.

Returns:

  • (String) —

    job summary page table for Actions



77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/audition/report/sweep.rb', line 77

def markdown
  lines = [
    "## #{TITLE}", "",
    "| gem | version | verdict | errors | dep errors " \
    "| warnings | fixable |",
    "| --- | --- | --- | --- | --- | --- | --- |"
  ]
  @rows.each do |r|
    lines << "| #{r.name} | #{r.version} | " \
      "#{CELLS.fetch(r.verdict)} | #{r.errors} | " \
      "#{r.dep_errors} | #{r.warnings} | #{r.fixable} |"
  end
  lines.push("", plain_summary).join("\n")
end

#render(**table_opts) ⇒ String

Returns the table plus a summary line.

Parameters:

  • table_opts (Hash) —

    what the terminal supports; see the caller for why color cannot be detected here

Returns:

  • (String) —

    the table plus a summary line



46
47
48
49
50
# File 'lib/audition/report/sweep.rb', line 46

def render(**table_opts)
  table = TableTennis.new(cells, title: TITLE, mark: paint,
    **table_opts)
  "#{table}\n#{summary}"
end