Module: Greenroom::CLI::Judge

Defined in:
lib/greenroom/cli/judge.rb

Defined Under Namespace

Classes: Evaluation, Patch, Verdict

Constant Summary collapse

DEFAULTS =
{
  "minimum_comparisons" => 1000,
  "consecutive_clean_nights" => 2,
  "expiry_days" => 30,
  "minimum_comparison_ratio" => 0.8
}.freeze

Class Method Summary collapse

Class Method Details

.run(arguments, stdout: $stdout, stderr: $stderr) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/greenroom/cli/judge.rb', line 25

def run(arguments, stdout: $stdout, stderr: $stderr)
  options = {repo: ".", json: false}
  parser = option_parser(options)
  parser.parse!(arguments)
  return usage(stderr, parser, "The --events option is required.") unless options[:events]
  return usage(stderr, parser, "The --config option is required.") unless options[:config]
  return usage(stderr, parser, "Unexpected arguments are present.") unless arguments.empty?

  # The host application CI owns the service credentials and pull
  # request delivery. JSON input keeps these service boundaries outside
  # the gem.
  events = JSON.parse(File.read(options[:events]))
  config = DEFAULTS.merge(YAML.safe_load_file(options[:config]) || {})
  require "rubocop-ast"
  verdicts, errors = Evaluation.new(events, config, options[:repo]).call
  print_results(stdout, verdicts, errors, options[:json])
  # The exit status reports when a person must act. A successful promotion
  # stays green because the host CI uses the JSON result to open its
  # pull request.
  (verdicts.any? { |item| %w[nogo attention expired].include?(item.verdict) }) ? 1 : 0
rescue OptionParser::ParseError, JSON::ParserError, Errno::ENOENT, Psych::Exception => error
  stderr.puts(error.message)
  2
end