Class: Gitlab::QA::Report::ReportResults

Inherits:
ReportAsIssue show all
Defined in:
lib/gitlab/qa/report/report_results.rb

Overview

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

Constant Summary collapse

IGNORE_EXCEPTIONS =
['Net::ReadTimeout'].freeze

Constants inherited from ReportAsIssue

Gitlab::QA::Report::ReportAsIssue::MAX_TITLE_LENGTH

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ReportAsIssue

#invoke!

Constructor Details

#initialize(token:, input_files:, test_case_project: nil, results_issue_project: nil, dry_run: false, **kwargs) ⇒ ReportResults

Returns a new instance of ReportResults.



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

def initialize(token:, input_files:, test_case_project: nil, results_issue_project: nil, dry_run: false, **kwargs)
  @testcase_project_reporter = Gitlab::QA::Report::ResultsInTestCases.new(token: token, input_files: input_files, project: test_case_project, dry_run: dry_run, **kwargs)
  @results_issue_project_reporter = Gitlab::QA::Report::ResultsInIssues.new(token: token, input_files: input_files, project: results_issue_project, dry_run: dry_run, **kwargs)
  @test_case_project = test_case_project
  @results_issue_project = results_issue_project
  @files = Array(input_files)
  @gitlab = testcase_project_reporter.gitlab
end

Instance Attribute Details

#filesObject

Returns the value of attribute files.



8
9
10
# File 'lib/gitlab/qa/report/report_results.rb', line 8

def files
  @files
end

#gitlabObject

Returns the value of attribute gitlab.



8
9
10
# File 'lib/gitlab/qa/report/report_results.rb', line 8

def gitlab
  @gitlab
end

#results_issue_projectObject

Returns the value of attribute results_issue_project.



8
9
10
# File 'lib/gitlab/qa/report/report_results.rb', line 8

def results_issue_project
  @results_issue_project
end

#results_issue_project_reporterObject

Returns the value of attribute results_issue_project_reporter.



8
9
10
# File 'lib/gitlab/qa/report/report_results.rb', line 8

def results_issue_project_reporter
  @results_issue_project_reporter
end

#test_case_projectObject

Returns the value of attribute test_case_project.



8
9
10
# File 'lib/gitlab/qa/report/report_results.rb', line 8

def test_case_project
  @test_case_project
end

#testcase_project_reporterObject

Returns the value of attribute testcase_project_reporter.



8
9
10
# File 'lib/gitlab/qa/report/report_results.rb', line 8

def testcase_project_reporter
  @testcase_project_reporter
end

Instance Method Details

#assert_project!Object



21
22
23
24
25
# File 'lib/gitlab/qa/report/report_results.rb', line 21

def assert_project!
  return if test_case_project && results_issue_project

  abort "Please provide valid project IDs or paths with the `--results-issue-project` and `--test-case-project` options!"
end

#run!Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/gitlab/qa/report/report_results.rb', line 27

def run!
  puts "Reporting test results in `#{files.join(',')}` as test cases in project `#{test_case_project}`"\
       " and issues in project `#{results_issue_project}` via the API at `#{Runtime::Env.gitlab_api_base}`."

  test_results_per_file do |test_results|
    puts "Reporting tests in #{test_results.path}"

    test_results.each do |test|
      puts "Reporting test: #{test.file} | #{test.name}\n"

      report_test(test) if should_report?(test)
    end

    test_results.write
  end
end