gitlab_quality-test_tooling 1.8.1 → 1.9.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: 4c8eda4a61584293cfb2f20a4ece0c5afd8963be75c56c5c3a1f71cbbf04a2ed
4
- data.tar.gz: 72ea08e5a2fac3b5d9f0d5dada3bb71c7b655acbd7c03f4533e0bbe951be954e
3
+ metadata.gz: d7c32e6b11eb72bf1f453827d3c8c0dd98a8d37788c22000566fac4fe9b0daab
4
+ data.tar.gz: 573ea110d2d1bea41f217f135f6dfe57a814ecc261142813e4dbbda17f813e0e
5
5
  SHA512:
6
- metadata.gz: fe64d9f93ff1343c36d1d478f63e9a4614587897b6414ec3a1f4c28fdd90ee1d245134e9350f546373350acf1f1355dd50d31da162a899d096ceb1114029767e
7
- data.tar.gz: d4dd2ba2714e54c766592734481f7ba373692375f4c2011578f1b22da36fae3b8d58e721677e47ba214805d3798737c5ad6dec7711d586a46727029e555fb72e
6
+ metadata.gz: b7f5b809cd506c860edba93bc45c932183106da000b2eb14ae7149aa5d7a820502971fd5a26747664be1921334af3b1041a668fb128f8b4c739507ac63f850f2
7
+ data.tar.gz: 1a428ce49770515622c810bfaf2e918df2223b7ed23f38958d994de6bef4c591c5fd10efc7be071d1fdf6cde38eacc8598126b612fde62c300a01c0e9608c83a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gitlab_quality-test_tooling (1.8.1)
4
+ gitlab_quality-test_tooling (1.9.0)
5
5
  activesupport (>= 6.1, < 7.2)
6
6
  amatch (~> 0.4.1)
7
7
  gitlab (~> 4.19)
data/exe/post-to-slack CHANGED
@@ -8,6 +8,9 @@ require_relative "../lib/gitlab_quality/test_tooling"
8
8
 
9
9
  params = {}
10
10
 
11
+ messages = []
12
+ gitlab_api_token = nil
13
+
11
14
  options = OptionParser.new do |opts|
12
15
  opts.banner = "Usage: #{$PROGRAM_NAME} [options]"
13
16
 
@@ -15,16 +18,34 @@ options = OptionParser.new do |opts|
15
18
  params[:slack_webhook_url] = slack_webhook_url
16
19
  end
17
20
 
21
+ opts.on('-a', '--gitlab-api-token TOKEN', String, 'GitLab API token') do |token|
22
+ gitlab_api_token = token unless token.empty?
23
+ end
24
+
18
25
  opts.on('-c', '--channel CHANNEL', String, 'Slack channel to post the message to') do |channel|
19
26
  params[:channel] = channel
20
27
  end
21
28
 
22
29
  opts.on('-m', '--message MESSAGE', String, 'Post message to Slack') do |message|
23
- params[:message] = message
30
+ messages << message
24
31
  end
25
32
 
26
33
  opts.on('-t', '--include-summary-table FILES', String, 'Add a test summary table based on RSpec report files (JUnit XML)') do |files|
27
- params[:message] += "\n\n#{GitlabQuality::TestTooling::SummaryTable.create(input_files: files)}"
34
+ messages << GitlabQuality::TestTooling::SummaryTable.create(input_files: files)
35
+ end
36
+
37
+ opts.on('-j', '--include-failed-jobs-table', 'Add a list of failed jobs in the pipeline') do
38
+ next puts("Failed jobs table requires api token to be set via --gitlab-api-token option, skipping failed jobs table") unless gitlab_api_token
39
+
40
+ project_id = ENV['CI_PROJECT_ID']&.to_i || (next puts("CI_PROJECT_ID not set, skipping failed jobs table"))
41
+ pipeline_id = ENV['CI_PIPELINE_ID']&.to_i || (next puts("CI_PIPELINE_ID not set, skipping failed jobs table"))
42
+
43
+ jobs = GitlabQuality::TestTooling::GitlabClient::FailedJobs.new(token: gitlab_api_token, project_id: project_id, pipeline_id: pipeline_id).fetch
44
+ next if jobs.empty?
45
+
46
+ messages << GitlabQuality::TestTooling::FailedJobsTable.create(jobs: jobs)
47
+ rescue StandardError => e
48
+ puts "Failed to fetch failed jobs. #{e.class}: #{e.message}"
28
49
  end
29
50
 
30
51
  opts.on('-u', '--username USERNAME', String, 'Username to use for the Slack message') do |username|
@@ -50,6 +71,8 @@ options = OptionParser.new do |opts|
50
71
  opts.parse(ARGV)
51
72
  end
52
73
 
74
+ params[:message] = messages.join("\n\n")
75
+
53
76
  if params.any?
54
77
  GitlabQuality::TestTooling::Slack::PostToSlack.new(**params).invoke!
55
78
  else
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'table_print'
4
+
5
+ module GitlabQuality
6
+ module TestTooling
7
+ module FailedJobsTable
8
+ class << self
9
+ # Create table with formatted list of failed jobs
10
+ #
11
+ # @param [Array<Gitlab::ObjectifiedHash>] jobs
12
+ # @return [String]
13
+ def create(jobs:)
14
+ "```\n#{TablePrint::Printer.table_print(collect_results(jobs))}\n```\n"
15
+ end
16
+
17
+ private
18
+
19
+ # Format list of failed jobs
20
+ #
21
+ # @param [Array<Gitlab::ObjectifiedHash>] jobs
22
+ # @return [Array]
23
+ def collect_results(jobs)
24
+ jobs.sort_by(&:stage).map do |job|
25
+ {
26
+ "Job" => job.name,
27
+ "Stage" => job.stage,
28
+ "Failure Reason" => job.failure_reason
29
+ }
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'gitlab'
4
+
5
+ module GitlabQuality
6
+ module TestTooling
7
+ module GitlabClient
8
+ class FailedJobs
9
+ def initialize(token:, project_id:, pipeline_id:)
10
+ @token = token
11
+ @project_id = project_id
12
+ @pipeline_id = pipeline_id
13
+ end
14
+
15
+ def fetch
16
+ client.pipeline_jobs(project_id, pipeline_id, scope: 'failed')
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :token, :project_id, :pipeline_id
22
+
23
+ def client
24
+ @client ||= Gitlab.client(
25
+ endpoint: Runtime::Env.gitlab_api_base,
26
+ private_token: token
27
+ )
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module GitlabQuality
4
4
  module TestTooling
5
- VERSION = "1.8.1"
5
+ VERSION = "1.9.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab_quality-test_tooling
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.1
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitLab Quality
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-12-05 00:00:00.000000000 Z
11
+ date: 2023-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: climate_control
@@ -383,6 +383,8 @@ files:
383
383
  - exe/update-screenshot-paths
384
384
  - lefthook.yml
385
385
  - lib/gitlab_quality/test_tooling.rb
386
+ - lib/gitlab_quality/test_tooling/failed_jobs_table.rb
387
+ - lib/gitlab_quality/test_tooling/gitlab_client/failed_jobs.rb
386
388
  - lib/gitlab_quality/test_tooling/gitlab_client/merge_request.rb
387
389
  - lib/gitlab_quality/test_tooling/gitlab_client/merge_request_dry_client.rb
388
390
  - lib/gitlab_quality/test_tooling/gitlab_issue_client.rb