Module: Moult::Formatters::GateTable
- Defined in:
- lib/moult/formatters/gate_table.rb
Overview
Human-readable gate result: a PASS/FAIL banner, the scope it ran over, a per-rule table (with each rule's observed value vs threshold), and the contributing findings behind any failure. Renders from the same GateReport as the JSON/CI formatters so they cannot disagree.
The verdict is an auditable application of the recorded policy — the heading says so; nothing here claims the code is certainly wrong.
Class Method Summary collapse
- .banner(report) ⇒ Object
- .contribution_line(rule, finding) ⇒ Object
- .contributions(report) ⇒ Object
- .observed(rule) ⇒ Object
- .render(report) ⇒ String
- .result(rule) ⇒ Object
- .rule_table(report) ⇒ Object
- .scope_label(report) ⇒ Object
Class Method Details
.banner(report) ⇒ Object
22 23 24 25 |
# File 'lib/moult/formatters/gate_table.rb', line 22 def (report) verdict = report.verdict.upcase "moult gate: #{verdict} (#{scope_label(report)})" end |
.contribution_line(rule, finding) ⇒ Object
65 66 67 68 |
# File 'lib/moult/formatters/gate_table.rb', line 65 def contribution_line(rule, finding) loc = finding.line ? "#{finding.path}:#{finding.line}" : finding.path " [#{rule.rule}] #{loc} #{finding.category} (#{finding.value})" end |
.contributions(report) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/moult/formatters/gate_table.rb', line 57 def contributions(report) failed = report.rules.select { |r| r.evaluated && r.passed == false } return "" if failed.empty? lines = failed.flat_map { |rule| rule.findings.map { |f| contribution_line(rule, f) } } ["", "Contributing findings:", *lines].join("\n") end |
.observed(rule) ⇒ Object
45 46 47 48 49 |
# File 'lib/moult/formatters/gate_table.rb', line 45 def observed(rule) return "-" if rule.observed.nil? rule.observed.to_s end |
.render(report) ⇒ String
17 18 19 20 |
# File 'lib/moult/formatters/gate_table.rb', line 17 def render(report) [(report), "", rule_table(report), contributions(report)] .reject(&:empty?).join("\n") end |
.result(rule) ⇒ Object
51 52 53 54 55 |
# File 'lib/moult/formatters/gate_table.rb', line 51 def result(rule) return "skipped" unless rule.evaluated rule.passed ? "pass" : "FAIL" end |
.rule_table(report) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/moult/formatters/gate_table.rb', line 37 def rule_table(report) headers = %w[RULE OBSERVED THRESHOLD RESULT] rows = report.rules.map do |rule| [rule.rule, observed(rule), rule.threshold.to_s, result(rule)] end TextTable.render(headers, rows) end |
.scope_label(report) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/moult/formatters/gate_table.rb', line 27 def scope_label(report) if report.scope == :all || report.scope == "all" "scope: all (whole codebase)" else base = report.base_ref || "base" mb = report.merge_base ? " @ #{report.merge_base[0, 7]}" : "" "scope: diff vs #{base}#{mb}" end end |