Class: Gitlab::QA::Reporter

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

Class Method Summary collapse

Class Method Details

.invoke(args) ⇒ Object

rubocop:disable Metrics/AbcSize



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/gitlab/qa/reporter.rb', line 7

def self.invoke(args)
  report_options = {}
  slack_options = {}

  options = OptionParser.new do |opts|
    opts.banner = 'Usage: gitlab-qa-reporter [options]'

    opts.on('--prepare-stage-reports FILES', 'Prepare separate reports for each Stage from the provided JUnit XML files') do |files|
      report_options[:prepare_stage_reports] = true
      report_options[:input_files] = files if files
    end

    opts.on('--report-in-issues FILES', String, 'Report test results from JUnit XML files in GitLab issues') do |files|
      report_options[:report_in_issues] = true
      report_options[:input_files] = files if files
    end

    opts.on('-p', '--project PROJECT_ID', String, 'A valid project ID. Can be an integer or a group/project string. Required by --report-in-issues') do |value|
      report_options[:project] = value
    end

    opts.on('-t', '--token ACCESS_TOKEN', String, 'A valid access token. Used by --report-in-issues') do |value|
      report_options[:token] = value
    end

    opts.on('--post-to-slack MSG', 'Post message to slack') do |msg|
      slack_options[:post_to_slack] = true
      slack_options[:message] = msg
    end

    opts.on('--include-summary-table FILES', 'Create a results summary table to post to slack. To be used with --post-to-slack.') do |files|
      raise 'This option should be used with --post-to-slack.' unless slack_options[:post_to_slack]

      slack_options[:message] = slack_options[:message] + "\n\n" + Gitlab::QA::Report::SummaryTable.create(input_files: files)
    end

    opts.on_tail('-v', '--version', 'Show the version') do
      require 'gitlab/qa/version'
      puts "#{$PROGRAM_NAME} : #{VERSION}"
      exit
    end

    opts.on_tail('-h', '--help', 'Show the usage') do
      puts opts
      exit
    end

    opts.parse(args)
  end

  if args.any?
    if report_options[:prepare_stage_reports]
      report_options.delete(:prepare_stage_reports)
      Gitlab::QA::Report::PrepareStageReports.new(**report_options).invoke!

      exit
    end

    if report_options[:report_in_issues]
      report_options.delete(:report_in_issues)
      report_options[:token] = Runtime::TokenFinder.find_token!(report_options[:token])
      Gitlab::QA::Report::ResultsInIssues.new(**report_options).invoke!

      exit
    end

    if slack_options[:post_to_slack]
      slack_options.delete(:post_to_slack)
      Gitlab::QA::Slack::PostToSlack.new(**slack_options).invoke!

      exit
    end
  else
    puts options
    exit 1
  end
end