gitlab-qa 5.0.3 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4bada173257833055a80ce95da0bdedff9f80e491996d4ffc2afa08045c05fec
4
- data.tar.gz: f1c39835f8183544ebba39c1eb81c0cdc73820dfc66e67f9e74ee61ff5dad3d5
3
+ metadata.gz: 77a9207808fc033a918c2096734e3511fe8cf5126ddc791f16477c4062c13e8f
4
+ data.tar.gz: 62c66c8604fcb5a73825a0e0e8e8c34aec1eca0e58e20c5effe17d2078fc82c6
5
5
  SHA512:
6
- metadata.gz: d2e190ef3baadd7620d8798e7f37be50a41a0ca12abd5f4672233d0fe5939c7bd448f59d881a9792a6157708b06f503c4623a8c03f6a6d6065cad537b6c0712a
7
- data.tar.gz: 673340d27e71c31787185d7f50868ab2cf3828a036b4de530d20b30816ef53932b60ca94ddfecb08a55a25e90919249da8de2b68b87b6dd8cf630bb968305bd1
6
+ metadata.gz: db859779d4aba13388c527e9183998d80e64422fa30fabd1446af46d2a6af540165ae3d0b5932059159c245104ecb528213977d281684fb75034e240efe48807
7
+ data.tar.gz: 5f3160b6db99a7c4f0ae247b4990971a162b4728560c353842b79cf872a348c915ecf836be1549547aedd29ea4d0c2ea358276fe03a1e3df2c7fa3008f9a7d93
data/gitlab-qa.gemspec CHANGED
@@ -29,5 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.add_development_dependency 'webmock', '3.7.0'
30
30
  spec.add_runtime_dependency 'activesupport', '~> 6.0.2'
31
31
  spec.add_runtime_dependency 'gitlab', '~> 4.11.0'
32
+ spec.add_runtime_dependency 'http', '4.3.0'
32
33
  spec.add_runtime_dependency 'nokogiri', '~> 1.10'
34
+ spec.add_runtime_dependency 'table_print', '1.5.6'
33
35
  end
data/lib/gitlab/qa.rb CHANGED
@@ -75,6 +75,7 @@ module Gitlab
75
75
 
76
76
  module Support
77
77
  autoload :GetRequest, 'gitlab/qa/support/get_request'
78
+ autoload :HttpRequest, 'gitlab/qa/support/http_request'
78
79
  autoload :DevEEQAImage, 'gitlab/qa/support/dev_ee_qa_image'
79
80
  autoload :InvalidResponseError, 'gitlab/qa/support/invalid_response_error'
80
81
  end
@@ -89,6 +90,11 @@ module Gitlab
89
90
  module Report
90
91
  autoload :PrepareStageReports, 'gitlab/qa/report/prepare_stage_reports'
91
92
  autoload :ResultsInIssues, 'gitlab/qa/report/results_in_issues'
93
+ autoload :SummaryTable, 'gitlab/qa/report/summary_table'
94
+ end
95
+
96
+ module Slack
97
+ autoload :PostToSlack, 'gitlab/qa/slack/post_to_slack'
92
98
  end
93
99
  end
94
100
  end
@@ -0,0 +1,41 @@
1
+ require 'nokogiri'
2
+ require 'table_print'
3
+
4
+ module Gitlab
5
+ module QA
6
+ module Report
7
+ class SummaryTable
8
+ def self.create(input_files:)
9
+ "```\n#{TablePrint::Printer.table_print(collect_results(input_files))}```\n"
10
+ end
11
+
12
+ # rubocop:disable Metrics/AbcSize
13
+ def self.collect_results(input_files)
14
+ stage_wise_results = []
15
+
16
+ Dir.glob(input_files).each do |report_file|
17
+ stage_hash = {}
18
+ stage_hash["Dev Stage"] = File.basename(report_file, ".*").capitalize
19
+
20
+ report_stats = Nokogiri::XML(File.open(report_file)).children[0].attributes
21
+
22
+ stage_hash["Total"] = report_stats["tests"].value
23
+ stage_hash["Failures"] = report_stats["failures"].value
24
+ stage_hash["Errors"] = report_stats["errors"].value
25
+ stage_hash["Skipped"] = report_stats["skipped"].value
26
+ stage_hash["Result"] = result_emoji(report_stats)
27
+
28
+ stage_wise_results << stage_hash
29
+ end
30
+
31
+ stage_wise_results
32
+ end
33
+ # rubocop:enable Metrics/AbcSize
34
+
35
+ def self.result_emoji(report_stats)
36
+ report_stats["failures"].value.to_i.positive? || report_stats["errors"].value.to_i.positive? ? "❌" : "✅"
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -6,6 +6,7 @@ module Gitlab
6
6
  # rubocop:disable Metrics/AbcSize
7
7
  def self.invoke(args)
8
8
  report_options = {}
9
+ slack_options = {}
9
10
 
10
11
  options = OptionParser.new do |opts|
11
12
  opts.banner = 'Usage: gitlab-qa-reporter [options]'
@@ -28,6 +29,17 @@ module Gitlab
28
29
  report_options[:token] = value
29
30
  end
30
31
 
32
+ opts.on('--post-to-slack MSG', 'Post message to slack') do |msg|
33
+ slack_options[:post_to_slack] = true
34
+ slack_options[:message] = msg
35
+ end
36
+
37
+ opts.on('--include-summary-table FILES', 'Create a results summary table to post to slack. To be used with --post-to-slack.') do |files|
38
+ raise 'This option should be used with --post-to-slack.' unless slack_options[:post_to_slack]
39
+
40
+ slack_options[:message] = slack_options[:message] + "\n\n" + Gitlab::QA::Report::SummaryTable.create(input_files: files)
41
+ end
42
+
31
43
  opts.on_tail('-v', '--version', 'Show the version') do
32
44
  require 'gitlab/qa/version'
33
45
  puts "#{$PROGRAM_NAME} : #{VERSION}"
@@ -57,6 +69,13 @@ module Gitlab
57
69
 
58
70
  exit
59
71
  end
72
+
73
+ if slack_options[:post_to_slack]
74
+ slack_options.delete(:post_to_slack)
75
+ Gitlab::QA::Slack::PostToSlack.new(**slack_options).invoke!
76
+
77
+ exit
78
+ end
60
79
  else
61
80
  puts options
62
81
  exit 1
@@ -71,7 +71,9 @@ module Gitlab
71
71
  'GITLAB_QA_1P_GITHUB_UUID' => :gitlab_qa_1p_github_uuid,
72
72
  'GITLAB_QA_LOOP_RUNNER_MINUTES' => :gitlab_qa_loop_runner_minutes,
73
73
  'QA_CAN_TEST_ADMIN_FEATURES' => :qa_can_test_admin_features,
74
- 'MAILHOG_HOSTNAME' => :mailhog_hostname
74
+ 'MAILHOG_HOSTNAME' => :mailhog_hostname,
75
+ 'SLACK_QA_CHANNEL' => :slack_qa_channel,
76
+ 'SLACK_QA_BOT_TOKEN' => :slack_qa_bot_token
75
77
  }.freeze
76
78
 
77
79
  ENV_VARIABLES.each_value do |accessor|
@@ -157,6 +159,18 @@ module Gitlab
157
159
  end
158
160
  end
159
161
 
162
+ def require_slack_qa_channel!
163
+ return unless ENV['SLACK_QA_CHANNEL'].to_s.strip.empty?
164
+
165
+ raise ArgumentError, "Please provide SLACK_QA_CHANNEL"
166
+ end
167
+
168
+ def require_slack_qa_bot_token!
169
+ return unless ENV['SLACK_QA_BOT_TOKEN'].to_s.strip.empty?
170
+
171
+ raise ArgumentError, "Please provide SLACK_QA_BOT_TOKEN"
172
+ end
173
+
160
174
  def require_kubernetes_environment!
161
175
  %w[GCLOUD_ACCOUNT_EMAIL GCLOUD_ACCOUNT_KEY CLOUDSDK_CORE_PROJECT].each do |env_key|
162
176
  raise ArgumentError, "Environment variable #{env_key} must be set to run kubernetes specs" unless ENV.key?(env_key)
@@ -0,0 +1,25 @@
1
+ module Gitlab
2
+ module QA
3
+ module Slack
4
+ class PostToSlack
5
+ def initialize(message:)
6
+ @message = message
7
+ end
8
+
9
+ def invoke!
10
+ Runtime::Env.require_slack_qa_channel!
11
+ Runtime::Env.require_slack_qa_bot_token!
12
+
13
+ params = {}
14
+ params['token'] = Runtime::Env.slack_qa_bot_token
15
+ params['channel'] = Runtime::Env.slack_qa_channel
16
+ params['text'] = @message
17
+
18
+ url = "https://slack.com/api/chat.postMessage"
19
+
20
+ Support::HttpRequest.make_http_request(method: 'post', url: url, params: params)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,32 @@
1
+ require 'http'
2
+ require 'json'
3
+
4
+ module Gitlab
5
+ module QA
6
+ module Support
7
+ class HttpRequest
8
+ # rubocop:disable Metrics/AbcSize
9
+ def self.make_http_request(method: 'get', url: nil, params: {}, headers: {}, show_response: false, fail_on_error: true)
10
+ raise "URL not defined for making request. Exiting..." unless url
11
+
12
+ res = HTTP.follow.method(method).call(url, form: params, headers: headers)
13
+
14
+ if show_response
15
+ if res.content_type.mime_type == "application/json"
16
+ res_body = JSON.parse(res.body.to_s)
17
+ pp res_body
18
+ else
19
+ res_body = res.body.to_s
20
+ puts res_body
21
+ end
22
+ end
23
+
24
+ raise "#{method.upcase} request failed!\nCode: #{res.code}\nResponse: #{res.body}\n" if fail_on_error && !res.status.success?
25
+
26
+ res
27
+ end
28
+ # rubocop:enable Metrics/AbcSize
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,5 +1,5 @@
1
1
  module Gitlab
2
2
  module QA
3
- VERSION = '5.0.3'.freeze
3
+ VERSION = '5.1.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-qa
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.3
4
+ version: 5.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grzegorz Bizon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-17 00:00:00.000000000 Z
11
+ date: 2020-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: climate_control
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
152
  version: 4.11.0
153
+ - !ruby/object:Gem::Dependency
154
+ name: http
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '='
158
+ - !ruby/object:Gem::Version
159
+ version: 4.3.0
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '='
165
+ - !ruby/object:Gem::Version
166
+ version: 4.3.0
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: nokogiri
155
169
  requirement: !ruby/object:Gem::Requirement
@@ -164,6 +178,20 @@ dependencies:
164
178
  - - "~>"
165
179
  - !ruby/object:Gem::Version
166
180
  version: '1.10'
181
+ - !ruby/object:Gem::Dependency
182
+ name: table_print
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - '='
186
+ - !ruby/object:Gem::Version
187
+ version: 1.5.6
188
+ type: :runtime
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - '='
193
+ - !ruby/object:Gem::Version
194
+ version: 1.5.6
167
195
  description:
168
196
  email:
169
197
  - grzesiek.bizon@gmail.com
@@ -226,6 +254,7 @@ files:
226
254
  - lib/gitlab/qa/release.rb
227
255
  - lib/gitlab/qa/report/prepare_stage_reports.rb
228
256
  - lib/gitlab/qa/report/results_in_issues.rb
257
+ - lib/gitlab/qa/report/summary_table.rb
229
258
  - lib/gitlab/qa/reporter.rb
230
259
  - lib/gitlab/qa/runner.rb
231
260
  - lib/gitlab/qa/runtime/env.rb
@@ -263,8 +292,10 @@ files:
263
292
  - lib/gitlab/qa/scenario/test/omnibus/update.rb
264
293
  - lib/gitlab/qa/scenario/test/omnibus/upgrade.rb
265
294
  - lib/gitlab/qa/scenario/test/sanity/version.rb
295
+ - lib/gitlab/qa/slack/post_to_slack.rb
266
296
  - lib/gitlab/qa/support/dev_ee_qa_image.rb
267
297
  - lib/gitlab/qa/support/get_request.rb
298
+ - lib/gitlab/qa/support/http_request.rb
268
299
  - lib/gitlab/qa/support/invalid_response_error.rb
269
300
  - lib/gitlab/qa/version.rb
270
301
  - tls_certificates/gitlab/gitlab.test.crt