Class: Ask::Eval::Reporters::GitHub

Inherits:
Object
  • Object
show all
Defined in:
lib/ask/eval/reporters/github.rb

Overview

GitHub Actions reporter — produces annotations that appear as PR comments and annotations in GitHub Actions.

Output format:

::warning file={path},line={line},title={title}::{message}
::error file={path},line={line},title={title}::{message}

Instance Method Summary collapse

Constructor Details

#initialize(results, options = {}) ⇒ GitHub

Returns a new instance of GitHub.

Parameters:

  • results (Array<Hash>)

    array of result hashes

  • options (Hash) (defaults to: {})

    additional options

Options Hash (options):

  • :file (String)

    source file for annotations

  • :line (Integer)

    source line for annotations



17
18
19
20
21
# File 'lib/ask/eval/reporters/github.rb', line 17

def initialize(results, options = {})
  @results = results
  @file = options[:file]
  @line = options[:line] || 1
end

Instance Method Details

#annotationsArray<Hash>

Generate GitHub Actions annotations.

Returns:

  • (Array<Hash>)

    annotations array



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ask/eval/reporters/github.rb', line 25

def annotations
  @results.filter_map do |r|
    next if result_passed?(r)

    result = r[:result]
    reason = result.is_a?(Hash) ? result[:reason] : result.reason
    score = result.is_a?(Hash) ? result[:score] : result.score
    test_name = "#{r[:test] || 'eval'} #{r[:name]}"

    {
      path: @file || ".github/workflows/ci.yml",
      line: @line,
      message: "#{test_name}: #{reason} (score: #{score})",
      severity: score.to_f < 0.3 ? "error" : "warning"
    }
  end
end

#reportvoid

This method returns an undefined value.

Print annotations to stdout in GitHub Actions format.



45
46
47
48
49
50
# File 'lib/ask/eval/reporters/github.rb', line 45

def report
  annotations.each do |a|
    severity = a[:severity] == "error" ? "error" : "warning"
    puts "::#{severity} file=#{a[:path]},line=#{a[:line]},title=ask-eval::#{a[:message]}"
  end
end