Class: Mergify::RSpec::Quarantine

Inherits:
Object
  • Object
show all
Defined in:
lib/mergify/rspec/quarantine.rb

Overview

Fetches quarantined test names from the Mergify API and tracks which are used.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_url:, token:, repo_name:, branch_name:) ⇒ Quarantine

Returns a new instance of Quarantine.



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/mergify/rspec/quarantine.rb', line 15

def initialize(api_url:, token:, repo_name:, branch_name:)
  @repo_name = repo_name
  @branch_name = branch_name
  @quarantined_tests = []
  @used_tests = Set.new
  @init_error_msg = nil

  owner, repo = Utils.split_full_repo_name(repo_name)
  fetch_quarantined_tests(api_url, token, owner, repo, branch_name)
rescue Utils::InvalidRepositoryFullNameError => e
  @init_error_msg = e.message
end

Instance Attribute Details

#init_error_msgObject (readonly)

Returns the value of attribute init_error_msg.



13
14
15
# File 'lib/mergify/rspec/quarantine.rb', line 13

def init_error_msg
  @init_error_msg
end

#quarantined_testsObject (readonly)

Returns the value of attribute quarantined_tests.



13
14
15
# File 'lib/mergify/rspec/quarantine.rb', line 13

def quarantined_tests
  @quarantined_tests
end

Instance Method Details

#include?(example_id) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/mergify/rspec/quarantine.rb', line 28

def include?(example_id)
  @quarantined_tests.include?(example_id)
end

#mark_as_used(example_id) ⇒ Object



32
33
34
# File 'lib/mergify/rspec/quarantine.rb', line 32

def mark_as_used(example_id)
  @used_tests.add(example_id)
end

#reportObject

rubocop:disable Metrics/MethodLength,Metrics/AbcSize



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/mergify/rspec/quarantine.rb', line 37

def report
  used, unused = @quarantined_tests.partition { |t| @used_tests.include?(t) }

  lines = []
  lines << 'Mergify Quarantine Report'
  lines << "  Repository : #{@repo_name}"
  lines << "  Branch     : #{@branch_name}"
  lines << "  Quarantined tests from API: #{@quarantined_tests.size}"
  lines << ''
  lines << "  Quarantined tests run (#{used.size}):"
  used.each { |t| lines << "    - #{t}" }
  lines << ''
  lines << "  Unused quarantined tests (#{unused.size}):"
  unused.each { |t| lines << "    - #{t}" }
  lines.join("\n")
end