gitlab_quality-test_tooling 1.5.2 → 1.5.3

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: ecfb78e3fc7f1f23f118c98b16cdf1c104774734d08c4ff04dd6e4c7b25ae703
4
+ data.tar.gz: 4ef1ed6d2f559f427f0c26e92b90f631b5f407b7b604914c3b17786563675966
5
5
  SHA512:
6
- metadata.gz: 7cdbc73cd4ac08dc3f78a27b4575ec3a6005b7cfd95577bd61c8868d6836b3f1d549b1744d27d6cc2939e08d9b777eb74e84e4fb473952c7a9c982dc7a9b719e
7
- data.tar.gz: ddd08dc76c0a45cae09283f0a2c8b91a731a203ffa624cac641254b4933b49585d585b5ada0169f85cccd4c59af562ffca9b16df5d733ee98d38f0c15af08334
6
+ metadata.gz: 345e33ac54c7a917bb735a715e63bb8fcbe23464186aab1d02697ae1904f894a31ee4c04e2fb793262a04a4e768518e21eb5d0214616a337ca4f526a3a14af42
7
+ data.tar.gz: 5cf0dff6f8b7ff0f9526027fb3cc1efef03cf2ca1cf655d29054ff8075217e7221936b666e619e18cc09eaa003d3b70a65f1927124c6efb8c2f1516da9f00f27
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.3)
5
5
  activesupport (>= 6.1, < 7.2)
6
6
  amatch (~> 0.4.1)
7
7
  gitlab (~> 4.19)
@@ -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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module GitlabQuality
4
4
  module TestTooling
5
- VERSION = "1.5.2"
5
+ VERSION = "1.5.3"
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.3
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-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: climate_control