Class: BuildkiteGraphqlRuby::Commands::BranchStatus

Inherits:
Object
  • Object
show all
Defined in:
lib/buildkite_graphql_ruby/commands/branch_status.rb

Instance Method Summary collapse

Instance Method Details

#report_result(result:, options:) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/buildkite_graphql_ruby/commands/branch_status.rb', line 13

def report_result(result:, options:)
  builds_for_branch = result['data']['viewer']['user']['builds']
  total_builds = builds_for_branch['count']

  return if report_if_no_builds(total_builds, options)

  builds = builds_for_branch["edges"].map{|build_response| ResultsParsers::Build.from_response(build_response['node']) }
  
  return if report_if_no_finished_builds(builds, options)

  latest_build = builds.select(&:finished?).sort_by(&:finished_at).last

  return if report_if_latest_build_passed(latest_build, options)

  # For each failing job, print out the label of the job and its status
  puts border
  puts Rainbow("Branch #{options.branch.inspect} has a failing build").red
  puts Rainbow("URL: #{latest_build.url}").red
  puts ""

  failing_jobs = latest_build.jobs.reject(&:passed)
  failing_jobs.each do |failing_job|
    puts Rainbow("Failing Job: #{failing_job.label}").red
    # This only works if rspec is configured to upload a file called `tmp/rspec_json_results.json` for
    # rspec output.
    artifacts_with_results = failing_job.artifacts.select{|a| a.path == 'tmp/rspec_json_results.json'}

    artifacts_with_results.each do |artifact|
      rspec_result = ResultsParsers::RspecResults.from_response(artifact.download)
      puts rspec_result['summary_line']
      puts "Failing tests:"
      rspec_result.examples.reject(&:passed?).each do |e|
        puts e.file_path
      end
    end
  end

  puts border
end

#run!(options:) ⇒ Object



8
9
10
11
# File 'lib/buildkite_graphql_ruby/commands/branch_status.rb', line 8

def run!(options:)
  query = BuildkiteGraphqlRuby::QueryBuilder.new.branch_status(branch: options.branch)
  query_runner = BuildkiteGraphqlRuby::QueryRunner.new.run_query(query: query, options: options)
end