Module: Gitlab::QA::Report::ResultsReporterShared

Included in:
ResultsInIssues, ResultsInTestCases
Defined in:
lib/gitlab/qa/report/results_reporter_shared.rb

Constant Summary collapse

TEST_CASE_RESULTS_SECTION_TEMPLATE =
"\n\n### DO NOT EDIT BELOW THIS LINE\n\nActive and historical test results:"

Instance Method Summary collapse

Instance Method Details

#find_issue(test) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/gitlab/qa/report/results_reporter_shared.rb', line 11

def find_issue(test)
  issues = search_for_issues(test)

  warn(%(Too many #{issue_type}s found with the file path "#{test.file}" and name "#{test.name}")) if issues.many?
  puts "Found existing #{issue_type}: #{issues.first.web_url}" unless issues.empty?

  issues.first
end

#find_issue_by_iid(iid) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/gitlab/qa/report/results_reporter_shared.rb', line 20

def find_issue_by_iid(iid)
  issues = gitlab.find_issues(iid: iid) do |issue|
    issue.state == 'opened' && issue.issue_type == issue_type
  end

  warn(%(#{issue_type} iid "#{iid}" not valid)) if issues.empty?

  issues.first
end

#issue_title_needs_updating?(issue, test) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/gitlab/qa/report/results_reporter_shared.rb', line 30

def issue_title_needs_updating?(issue, test)
  issue.title.strip != title_from_test(test) && !%w[canary production preprod release].include?(pipeline)
end

#new_issue_labels(test) ⇒ Object



34
35
36
# File 'lib/gitlab/qa/report/results_reporter_shared.rb', line 34

def new_issue_labels(test)
  ['Quality', "devops::#{test.stage}", 'status::automated']
end

#search_term(test) ⇒ Object



38
39
40
# File 'lib/gitlab/qa/report/results_reporter_shared.rb', line 38

def search_term(test)
  %("#{partial_file_path(test.file)}" "#{search_safe(test.name)}")
end

#up_to_date_labels(test:, issue: nil, new_labels: Set.new) ⇒ Object



42
43
44
45
46
47
# File 'lib/gitlab/qa/report/results_reporter_shared.rb', line 42

def up_to_date_labels(test:, issue: nil, new_labels: Set.new)
  labels = super
  labels |= new_issue_labels(test).to_set
  labels.delete_if { |label| label.start_with?("#{pipeline}::") }
  labels << (test.failures.empty? ? "#{pipeline}::passed" : "#{pipeline}::failed")
end

#update_issue_title(issue, test) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/gitlab/qa/report/results_reporter_shared.rb', line 49

def update_issue_title(issue, test)
  old_title = issue.title.strip
  new_title = title_from_test(test)

  warn(%(#{issue_type} title needs to be updated from '#{old_title}' to '#{new_title}'))

  new_description = updated_description(issue, test)

  gitlab.edit_issue(iid: issue.iid, options: { title: new_title, description: new_description })
end