Class: GitlabQuality::TestTooling::Report::ResultsInTestCases

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

Overview

Uses the API to create or update GitLab test cases 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 Attribute Summary collapse

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) ⇒ ResultsInTestCases

Returns a new instance of ResultsInTestCases.



14
15
16
17
# File 'lib/gitlab_quality/test_tooling/report/results_in_test_cases.rb', line 14

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

Instance Attribute Details

#gitlabObject (readonly)

Returns the value of attribute gitlab.



12
13
14
# File 'lib/gitlab_quality/test_tooling/report/results_in_test_cases.rb', line 12

def gitlab
  @gitlab
end

#issue_typeObject (readonly)

Returns the value of attribute issue_type.



12
13
14
# File 'lib/gitlab_quality/test_tooling/report/results_in_test_cases.rb', line 12

def issue_type
  @issue_type
end

Instance Method Details



23
24
25
26
27
28
29
30
# File 'lib/gitlab_quality/test_tooling/report/results_in_test_cases.rb', line 23

def add_result_issue_link_to_testcase(testcase, result_issue, test)
  results_section = testcase.description.include?(TEST_CASE_RESULTS_SECTION_TEMPLATE) ? '' : TEST_CASE_RESULTS_SECTION_TEMPLATE

  gitlab.edit_issue(iid: testcase.iid,
    options: { description: (testcase.description + results_section + "\n\n#{result_issue.web_url}") })
  # We are using test.testcase for the url here instead of testcase.web_url since it has the updated test case path
  puts "Added results issue #{result_issue.web_url} link to test case #{test.testcase}"
end

#find_or_create_testcase(test) ⇒ Object



19
20
21
# File 'lib/gitlab_quality/test_tooling/report/results_in_test_cases.rb', line 19

def find_or_create_testcase(test)
  find_testcase(test) || create_issue(test)
end

#update_testcase(testcase, test) ⇒ Object



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

def update_testcase(testcase, test)
  puts "Labels updated for test case #{test.testcase}." if update_labels(testcase, test)
  puts "Quarantine section updated for test case #{test.testcase}." if update_quarantine_section(testcase, test)
end