Class: Kamal::Lint::Formatters::Github

Inherits:
Object
  • Object
show all
Defined in:
lib/kamal/lint/formatters/github.rb

Overview

Constant Summary collapse

LEVEL =
{
  error: "error",
  warning: "warning",
  info: "notice"
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(io: $stdout) ⇒ Github

Returns a new instance of Github.



15
16
17
# File 'lib/kamal/lint/formatters/github.rb', line 15

def initialize(io: $stdout)
  @io = io
end

Instance Method Details

#render(result) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/kamal/lint/formatters/github.rb', line 19

def render(result)
  result.findings.each do |finding|
    level = LEVEL[finding.severity] || "notice"
    attrs = {
      file: finding.file,
      line: finding.line,
      col: finding.column,
      title: "kamal-lint: #{finding.check_id}"
    }.compact

    attr_str = attrs.map { |k, v| "#{k}=#{escape_property(v.to_s)}" }.join(",")
    message = escape_message(finding.message)
    @io.puts "::#{level} #{attr_str}::#{message}"
  end
end

#render_fix_summary(result) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/kamal/lint/formatters/github.rb', line 35

def render_fix_summary(result)
  return if result.fixed.empty?

  result.fixed.each do |finding|
    @io.puts "::notice file=#{finding.file},title=kamal-lint autofix::Fixed #{finding.check_id}"
  end
end