gitlab_quality-test_tooling 1.5.2 → 1.5.4

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: 421778dfb1e380d4b8e0fc3e43a8d4147d50c0a11304ac36e964aeaf99330404
4
- data.tar.gz: 1f09fb87a864818b6728364454c0f8b9043cc73c5cec1ce4aa0104261d5dbfea
3
+ metadata.gz: acc009f4f6d5f4be05fa85cd3fffc68778d415d970ca96f22ace03c8a86f9488
4
+ data.tar.gz: 5c31655a8245c632e595431fb99ec14852bfd4f9b9778d09e8b8d0ae3393dbc1
5
5
  SHA512:
6
- metadata.gz: 7cdbc73cd4ac08dc3f78a27b4575ec3a6005b7cfd95577bd61c8868d6836b3f1d549b1744d27d6cc2939e08d9b777eb74e84e4fb473952c7a9c982dc7a9b719e
7
- data.tar.gz: ddd08dc76c0a45cae09283f0a2c8b91a731a203ffa624cac641254b4933b49585d585b5ada0169f85cccd4c59af562ffca9b16df5d733ee98d38f0c15af08334
6
+ metadata.gz: 754b2ed722bc050515ceb9f4691bc49da1e63c27c1ff44b3cd97bc597d6691f947a2390b63b41e980b4229332817671bc9cad351fee4455d424ce66f1d54cf03
7
+ data.tar.gz: ff2b356903435078c53b6234e69d57e272c9f367cd01518158fda38a94372ceeb1fe1e2f2cebec16e2aaa0dd4db9c98592c36631c858119d3340cf4bcd961bda
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gitlab_quality-test_tooling (1.5.2)
4
+ gitlab_quality-test_tooling (1.5.4)
5
5
  activesupport (>= 6.1, < 7.2)
6
6
  amatch (~> 0.4.1)
7
7
  gitlab (~> 4.19)
@@ -86,7 +86,9 @@ module GitlabQuality
86
86
  begin
87
87
  issue = find_issue_and_update_reports(test)
88
88
 
89
- create_issue(test) unless issue || test.quarantine?
89
+ issue = create_issue(test) unless issue || test.quarantine?
90
+
91
+ issue
90
92
  rescue MultipleIssuesFound => e
91
93
  warn(e.message)
92
94
  end
@@ -160,7 +160,7 @@ module GitlabQuality
160
160
  when 'customers-gitlab-com'
161
161
  'found:customers.stg.gitlab.com'
162
162
  else
163
- raise "No `found:*` label for the `#{pipeline}` pipeline!"
163
+ puts " => [DEBUG] No `found:*` label for the `#{pipeline}` pipeline!"
164
164
  end
165
165
  end
166
166
 
@@ -16,6 +16,9 @@ module GitlabQuality
16
16
  NEW_ISSUE_LABELS = Set.new(['test', 'type::maintenance', 'maintenance::performance', 'priority::3', 'severity::3', 'rspec profiling', 'rspec:slow test']).freeze
17
17
  SEARCH_LABELS = %w[test maintenance::performance].freeze
18
18
 
19
+ JOB_URL_REGEX = %r{(?<job_url>https://(?<host>[\w.]+)/(?<project_path>[\w\-./]+)/-/jobs/\d+)}
20
+ REPORT_ITEM_REGEX = /^1\. \d{4}-\d{2}-\d{2}: #{JOB_URL_REGEX} \((?<pipeline_url>.+)\)$/
21
+
19
22
  MultipleIssuesFound = Class.new(StandardError)
20
23
 
21
24
  private
@@ -45,9 +48,23 @@ module GitlabQuality
45
48
  to improve them. More context available about this issue in the [top slow tests guide](https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#top-slow-tests).
46
49
 
47
50
  Add `allowed_to_be_slow: true` to the RSpec test if this is a legit slow test and close the issue.
51
+
52
+ #{reports_section(test)}
48
53
  DESCRIPTION
49
54
  end
50
55
 
56
+ def reports_section(test)
57
+ <<~REPORTS
58
+ ### Reports (1)
59
+
60
+ #{report_list_item(test)}
61
+ REPORTS
62
+ end
63
+
64
+ def report_list_item(test)
65
+ "1. #{Time.new.utc.strftime('%F')}: #{test.ci_job_url} (#{ENV.fetch('CI_PIPELINE_URL', 'pipeline url is missing')})"
66
+ end
67
+
51
68
  def create_slow_issue(test)
52
69
  puts " => Finding existing issues for slow test '#{test.name}' (run time: #{test.run_time} seconds)..."
53
70
 
@@ -58,6 +75,8 @@ module GitlabQuality
58
75
  else
59
76
  issues.each do |issue|
60
77
  puts " => Existing issue link #{issue['web_url']}"
78
+
79
+ update_reports(issue, test)
61
80
  end
62
81
  end
63
82
 
@@ -65,6 +84,39 @@ module GitlabQuality
65
84
  rescue MultipleIssuesFound => e
66
85
  warn(e.message)
67
86
  end
87
+
88
+ def update_reports(issue, test)
89
+ # We reopen closed issues to not lose any history
90
+ state_event = issue.state == 'closed' ? 'reopen' : nil
91
+
92
+ issue_attrs = {
93
+ description: up_to_date_issue_description(issue.description, test)
94
+ }
95
+
96
+ issue_attrs[:state_event] = state_event if state_event
97
+
98
+ gitlab.edit_issue(iid: issue.iid, options: issue_attrs)
99
+ puts " => Added a report in '#{issue.title}': #{issue.web_url}!"
100
+ end
101
+
102
+ def up_to_date_issue_description(issue_description, test)
103
+ new_issue_description =
104
+ if issue_description.include?('### Reports')
105
+ # We count the number of existing reports.
106
+ reports_count = issue_description
107
+ .scan(REPORT_ITEM_REGEX)
108
+ .size.to_i + 1
109
+ issue_description.sub(/^### Reports.*$/, "### Reports (#{reports_count})")
110
+ else # For issue with the legacy format, we add the Reports section
111
+ reports_count = issue_description
112
+ .scan(JOB_URL_REGEX)
113
+ .size.to_i + 1
114
+
115
+ "#{issue_description}\n\n### Reports (#{reports_count})"
116
+ end
117
+
118
+ "#{new_issue_description}\n#{report_list_item(test)}"
119
+ end
68
120
  end
69
121
  end
70
122
  end
@@ -16,8 +16,8 @@ module GitlabQuality
16
16
 
17
17
  def invoke!
18
18
  Dir.glob(input_files).each do |input_file|
19
- rewrite_schreenshot_paths_in_junit_file(input_file)
20
- rewrite_schreenshot_paths_in_json_file(input_file.gsub('.xml', '.json'))
19
+ rewrite_screenshot_paths_in_junit_file(input_file)
20
+ rewrite_screenshot_paths_in_json_file(input_file.gsub('.xml', '.json'))
21
21
  end
22
22
  end
23
23
 
@@ -25,7 +25,7 @@ module GitlabQuality
25
25
 
26
26
  attr_reader :input_files
27
27
 
28
- def rewrite_schreenshot_paths_in_junit_file(junit_file)
28
+ def rewrite_screenshot_paths_in_junit_file(junit_file)
29
29
  File.write(
30
30
  junit_file,
31
31
  rewrite_each_junit_screenshot_path(junit_file).to_s
@@ -34,7 +34,7 @@ module GitlabQuality
34
34
  puts "Saved #{junit_file}"
35
35
  end
36
36
 
37
- def rewrite_schreenshot_paths_in_json_file(json_file)
37
+ def rewrite_screenshot_paths_in_json_file(json_file)
38
38
  File.write(
39
39
  json_file,
40
40
  JSON.pretty_generate(
@@ -58,7 +58,7 @@ module GitlabQuality
58
58
  examples = report['examples']
59
59
 
60
60
  examples.each do |example|
61
- next unless example['screenshot'].present?
61
+ next unless example['screenshot'].present? && example['screenshot']['image'].present?
62
62
 
63
63
  example['screenshot']['image'] =
64
64
  remove_container_absolute_path_prefix(example.dig('screenshot', 'image'), test_artifacts_directory(json_file))
@@ -2,6 +2,6 @@
2
2
 
3
3
  module GitlabQuality
4
4
  module TestTooling
5
- VERSION = "1.5.2"
5
+ VERSION = "1.5.4"
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.5.2
4
+ version: 1.5.4
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-11-14 00:00:00.000000000 Z
11
+ date: 2023-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: climate_control