Class: GitlabQuality::TestTooling::Report::ResultsInIssues

Inherits:
ReportAsIssue
  • Object
show all
Includes:
Concerns::ResultsReporter
Defined in:
lib/gitlab_quality/test_tooling/report/results_in_issues.rb

Overview

Uses the API to create or update GitLab test result issues with the results of tests from RSpec report files.

Constant Summary

Constants included from Concerns::ResultsReporter

Concerns::ResultsReporter::TEST_CASE_RESULTS_SECTION_TEMPLATE

Constants included from Concerns::Utils

Concerns::Utils::MAX_TITLE_LENGTH

Instance Method Summary collapse

Methods included from Concerns::ResultsReporter

#find_issue, #find_issue_by_iid, #issue_title_needs_updating?, #new_issue_labels, #up_to_date_labels, #update_issue

Methods included from Concerns::Utils

#label_names_to_label_quick_action, #new_issue_title, #partial_file_path, #pipeline, #readable_duration, #search_safe, #title_from_test

Methods inherited from ReportAsIssue

#invoke!

Constructor Details

#initialize(**kwargs) ⇒ ResultsInIssues

Returns a new instance of ResultsInIssues.



10
11
12
13
# File 'lib/gitlab_quality/test_tooling/report/results_in_issues.rb', line 10

def initialize(**kwargs)
  super
  @issue_type = 'issue'
end

Instance Method Details



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gitlab_quality/test_tooling/report/results_in_issues.rb', line 15

def get_related_issue(testcase, test)
  issue = find_linked_results_issue_by_iid(testcase, test)
  is_new = false

  if issue
    issue = update_issue(issue, test) if issue_title_needs_updating?(issue, test)
  else
    puts "No valid issue link found."
    issue = find_or_create_results_issue(test)
    is_new = true
  end

  [issue, is_new]
end

#post_note(issue, test) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/gitlab_quality/test_tooling/report/results_in_issues.rb', line 37

def post_note(issue, test)
  return false if test.skipped?
  return false if test.failures.empty?

  note = note_content(test)

  gitlab.find_issue_discussions(iid: issue.iid).each do |discussion|
    next unless new_note_matches_discussion?(note, discussion)

    gitlab.add_note_to_issue_discussion_as_thread(
      iid: issue.iid,
      discussion_id: discussion.id,
      note: failure_summary)
    return true
  end

  gitlab.create_issue_note(iid: issue.iid, note: note)
end

#update_issue_labels(issue, test) ⇒ Object



30
31
32
33
34
35
# File 'lib/gitlab_quality/test_tooling/report/results_in_issues.rb', line 30

def update_issue_labels(issue, test)
  new_labels = issue_labels(issue)
  new_labels |= ['Testcase Linked']

  update_labels(issue, test, new_labels)
end