Class: Gitlab::QA::Report::ResultsInIssues

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/qa/report/results_in_issues.rb

Overview

Uses the API to create or update GitLab issues with the results of tests from RSpec report files. The GitLab client is used for API access: github.com/NARKOZ/gitlab

Constant Summary collapse

MAINTAINER_ACCESS_LEVEL =
40
MAX_TITLE_LENGTH =
255
RETRY_BACK_OFF_DELAY =
60
MAX_RETRY_ATTEMPTS =
3

Instance Method Summary collapse

Constructor Details

#initialize(token:, input_files:, project: nil) ⇒ ResultsInIssues

Returns a new instance of ResultsInIssues.



33
34
35
36
37
38
# File 'lib/gitlab/qa/report/results_in_issues.rb', line 33

def initialize(token:, input_files:, project: nil)
  @token = token
  @files = Array(input_files)
  @project = project
  @retry_backoff = 0
end

Instance Method Details

#invoke!Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/gitlab/qa/report/results_in_issues.rb', line 40

def invoke!
  configure_gitlab_client

  validate_input!

  puts "Reporting test results in `#{files.join(',')}` as issues in project `#{project}` via the API at `#{Runtime::Env.gitlab_api_base}`."

  Dir.glob(files).each do |file|
    puts "Reporting tests in #{file}"
    extension = File.extname(file)

    case extension
    when '.json'
      test_results = Report::JsonTestResults.new(file)
    when '.xml'
      test_results = Report::JUnitTestResults.new(file)
    else
      raise "Unknown extension #{extension}"
    end

    test_results.each do |test|
      report_test(test)
    end
  end
end