Class: Dri::Commands::Add::FastQuarantine

Inherits:
Dri::Command show all
Defined in:
lib/dri/commands/add/fast_quarantine.rb

Instance Method Summary collapse

Methods inherited from Dri::Command

#add_color, #api_client, #bold, #command, #config, #cursor, #editor, #emoji, #handover_report_path, #logger, #ops_token, #pastel, #profile, #prompt, #spinner, #timezone, #token, #username, #verify_config_exists

Constructor Details

#initialize(options) ⇒ FastQuarantine

Returns a new instance of FastQuarantine.



9
10
11
# File 'lib/dri/commands/add/fast_quarantine.rb', line 9

def initialize(options)
  @options = options
end

Instance Method Details

#executeObject

rubocop:disable Metrics/AbcSize, Metrics/MethodLength



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
52
53
54
55
56
57
58
# File 'lib/dri/commands/add/fast_quarantine.rb', line 13

def execute(*) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
  verify_config_exists

  logger.info "Adding to fast quarantined tests..."
  current_content = api_client.get_fast_quarantine_tests
  current_content += "\n" unless current_content.end_with?("\n")

  if @options[:failure_url]
    failure_url = @options[:failure_url]
    issue_id = extract_issue_id_from_url(failure_url)

    issue_title = api_client.get_failure_issue_title(issue_id)
    test_path = extract_file_path(issue_title)

    full_path = "qa/specs/features/#{test_path}"
    new_file_content = "#{current_content}#{full_path}\n"

    new_branch = "fast-quarantine-failure-#{issue_id}"

    merge_request = api_client.add_test_to_fast_quarantine(
      failure_url,
      new_branch,
      test_path,
      new_file_content
    )

    logger.info "Opened an MR to review at #{merge_request.web_url}"

    api_client.add_note_failure_issue(issue_id, merge_request)
    logger.success "Note added to failure issue with link to fastquarantine merge request"
  elsif @options[:test_id]
    test_id = @options[:test_id]
    parsed_test_name = test_id.match(%r{([^/]+)_spec})[1]
    new_branch = "fast-quarantine-failure-#{parsed_test_name.tr('_', '-')}"

    new_file_content = "#{current_content}#{test_id}\n"
    merge_request = api_client.add_test_to_fast_quarantine(
      "N/A",
      new_branch,
      test_id,
      new_file_content
    )

    logger.info "Opened an MR to review at #{merge_request.web_url}"
  end
end