Class: Flaky::Commands::History

Inherits:
Object
  • Object
show all
Defined in:
lib/flaky/commands/history.rb

Instance Method Summary collapse

Constructor Details

#initialize(spec_location:) ⇒ History

Returns a new instance of History.



8
9
10
11
# File 'lib/flaky/commands/history.rb', line 8

def initialize(spec_location:)
  @spec_location = spec_location
  @repo = Repository.new
end

Instance Method Details

#executeObject



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
# File 'lib/flaky/commands/history.rb', line 13

def execute
  file, line = parse_location(@spec_location)
  rows = @repo.failure_history(file: file, line: line)

  if rows.empty?
    puts "No failures found matching '#{@spec_location}'."
    return
  end

  first = rows.first
  puts "Failure history for #{first['spec_file']}:#{first['line_number']}"
  puts "  #{first['description']}\n\n"
  puts format("%-20s %-8s %-10s %-30s %s", "Date", "Seed", "Commit", "Job", "Workflow")
  puts "-" * 110

  rows.each do |row|
    sha = row["commit_sha"] ? row["commit_sha"][0..6] : "       "
    puts format("%-20s %-8d %-10s %-30s %s", row["failed_at"], row["seed"], sha, row["job_name"], row["workflow_id"])
  end

  puts "\nTotal failures: #{rows.length}"

  seeds = rows.map { |r| r["seed"] }.uniq
  puts "Unique seeds: #{seeds.join(', ')}"
  puts "\nTo reproduce: SPEC=#{first['spec_file']}:#{first['line_number']} SEED=#{seeds.first} CI=true bin/rails flaky:stress"
ensure
  @repo.close
end