Class: QuietQuality::Annotators::GithubStdout

Inherits:
Object
  • Object
show all
Defined in:
lib/quiet_quality/annotators/github_stdout.rb

Constant Summary collapse

MAX_ANNOTATIONS =

github will only accept the first 10 annotations of each type in this form.

10

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output_stream: $stdout) ⇒ GithubStdout

Returns a new instance of GithubStdout.



7
8
9
# File 'lib/quiet_quality/annotators/github_stdout.rb', line 7

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

Class Method Details

.format(message) ⇒ Object

Example annotation output from github’s docs: ::warning file=name,line=line,title=title::message See docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-a-warning-message



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/quiet_quality/annotators/github_stdout.rb', line 20

def self.format(message)
  title = message.tool_name.to_s
  title += " #{message.rule}" if message.rule
  attributes = {
    file: message.path,
    line: message.annotated_line || message.start_line,
    title: title
  }.compact

  attributes_string = attributes.map { |k, v| "#{k}=#{v}" }.join(",")
  "::warning #{attributes_string}::#{message.body}"
end

Instance Method Details

#annotate!(messages) ⇒ Object



11
12
13
14
15
# File 'lib/quiet_quality/annotators/github_stdout.rb', line 11

def annotate!(messages)
  messages.first(MAX_ANNOTATIONS).each do |message|
    output_stream.puts self.class.format(message)
  end
end