confiner 0.2.0 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/confiner/cli.rb +1 -0
- data/lib/confiner/logger.rb +5 -1
- data/lib/confiner/plugins/debug.rb +14 -0
- data/lib/confiner/plugins/gitlab.rb +20 -8
- data/lib/confiner/version.rb +5 -0
- data/lib/confiner.rb +0 -2
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e9601fa7e82b448423188a4dde817864c6f7f57f1a1efd9aae67c1b2e8708c7
|
4
|
+
data.tar.gz: 23b2a999e52c58e5081fc9f4857e45a5a0c1783c0b1eca373f4ad4b57394a97f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48ad12ecefe1473ec4d481f3ebce5d325b9a0a052af1705a9a69621ea78a6d2fb5461fa4a068a83808943dc055f71fec936f54764894bc7a94de6e810e6bbb68
|
7
|
+
data.tar.gz: f74349e0a4003152ab16e7e86b4c34b77c58376ad7550fdf1796d4f7bd9633f0fc177abc56133607c4ce3c6108ca43b4598eacaf44eaa029c6127e301f80410b
|
data/lib/confiner/cli.rb
CHANGED
@@ -110,6 +110,7 @@ module Confiner
|
|
110
110
|
def process_rule(rule)
|
111
111
|
log :rule, rule.keys.map { |k| "\t#{k}=#{rule[k]}" }.join(',')
|
112
112
|
|
113
|
+
rule['plugin']['args'] ||= {}
|
113
114
|
rule['plugin']['args'].transform_keys!(&:to_sym) # 2.5 compatability
|
114
115
|
|
115
116
|
plugin = Plugins.const_get(translate_plugin_name(rule['plugin']['name'])).new(**rule['plugin']['args'])
|
data/lib/confiner/logger.rb
CHANGED
@@ -4,9 +4,13 @@ module Confiner
|
|
4
4
|
module Logger
|
5
5
|
# Log something with a specific level
|
6
6
|
def log(level, message, indentation = 1)
|
7
|
+
color = "\e[0;35m" # default purple
|
8
|
+
color = "\e[0;33m" if %i[warn warning].include?(level) # yellow
|
9
|
+
color = "\e[0;31m" if %i[err error fatal].include?(level) # red
|
10
|
+
|
7
11
|
raise ArgumentError, 'Level must be less than 12 characters' if level.size > 12
|
8
12
|
|
9
|
-
output = "(#{Time.now.strftime('%F %H:%M:%S')})\t
|
13
|
+
output = "(#{Time.now.strftime('%F %H:%M:%S')})\t#{color}#{level.to_s.upcase}#{' ' * (12 - level.size)}\e[m#{"\t" * indentation}#{message}"
|
10
14
|
|
11
15
|
Logger.log_to.puts(output)
|
12
16
|
end
|
@@ -12,6 +12,20 @@ module Confiner
|
|
12
12
|
def action2
|
13
13
|
log :debug, arg2
|
14
14
|
end
|
15
|
+
|
16
|
+
def warn
|
17
|
+
log :warn, 'Warn'
|
18
|
+
log :warning, 'Warning'
|
19
|
+
end
|
20
|
+
|
21
|
+
def fatal
|
22
|
+
log :fatal, 'Fatal'
|
23
|
+
end
|
24
|
+
|
25
|
+
def error
|
26
|
+
log :err, 'Err'
|
27
|
+
log :error, 'Error'
|
28
|
+
end
|
15
29
|
end
|
16
30
|
end
|
17
31
|
end
|
@@ -14,7 +14,7 @@ module Confiner
|
|
14
14
|
:threshold => 3, # the failure / pass threshold
|
15
15
|
:endpoint => 'https://gitlab.com/api/v4', # the GitLab API Endpoint (e.g. https://gitlab.com/api/v4)
|
16
16
|
:pwd => '.', # the path of the working directory for the examples
|
17
|
-
:ref => '
|
17
|
+
:ref => 'main' # the default Git ref used when updating
|
18
18
|
|
19
19
|
MERGE_REQUEST_TITLE = '[QUARANTINE] %s'
|
20
20
|
QUARANTINE_METADATA = %(, quarantine: { issue: '%s', type: :investigating })
|
@@ -24,6 +24,8 @@ module Confiner
|
|
24
24
|
|
25
25
|
ENV['GITLAB_API_HTTPARTY_OPTIONS'] = ENV.fetch('GITLAB_API_HTTPARTY_OPTIONS') { "{read_timeout: #{timeout}}" }
|
26
26
|
|
27
|
+
raise ArgumentError, 'Missing private_token' if private_token.nil?
|
28
|
+
|
27
29
|
@gitlab_client = ::Gitlab.client(private_token: private_token, endpoint: endpoint)
|
28
30
|
end
|
29
31
|
|
@@ -34,11 +36,13 @@ module Confiner
|
|
34
36
|
# store the examples from the pipelines
|
35
37
|
@examples = get_examples
|
36
38
|
|
37
|
-
@examples.select(&:failed?).map(&:name).uniq.
|
39
|
+
quarantines = @examples.select(&:failed?).map(&:name).uniq.each_with_object([]) do |failed_example, quarantines|
|
38
40
|
# count the number of failures consecutively for this example
|
39
41
|
|
40
42
|
number_of_failures = @examples.select { _1.name == failed_example && _1.failed? }.size
|
41
43
|
if number_of_failures >= threshold
|
44
|
+
quarantines << failed_example
|
45
|
+
|
42
46
|
example = @examples.find { _1.name == failed_example }
|
43
47
|
|
44
48
|
log :quarantine, "Quarantining #{failed_example} (#{number_of_failures} >= #{threshold})", 3
|
@@ -67,6 +71,12 @@ module Confiner
|
|
67
71
|
end
|
68
72
|
end
|
69
73
|
|
74
|
+
if quarantines.any?
|
75
|
+
log :quarantine, "Found #{quarantines.size} candidates to be quarantined", 3
|
76
|
+
else
|
77
|
+
log :quarantine, 'Found no candidates to be quarantined', 3
|
78
|
+
end
|
79
|
+
|
70
80
|
log :gitlab, 'Done with Quarantine Process', 2
|
71
81
|
end
|
72
82
|
|
@@ -84,8 +94,8 @@ module Confiner
|
|
84
94
|
def get_last_n_runs(threshold:)
|
85
95
|
pipelines = [] # collection of both passing and failing pipelines
|
86
96
|
|
87
|
-
pipelines << @gitlab_client.pipelines(project_id, per_page: threshold, status: :success)
|
88
|
-
pipelines << @gitlab_client.pipelines(project_id, per_page: threshold, status: :failed)
|
97
|
+
pipelines << @gitlab_client.pipelines(project_id, per_page: threshold, status: :success, ref: ref)
|
98
|
+
pipelines << @gitlab_client.pipelines(project_id, per_page: threshold, status: :failed, ref: ref)
|
89
99
|
end
|
90
100
|
|
91
101
|
# Get examples from pipelines
|
@@ -184,7 +194,7 @@ module Confiner
|
|
184
194
|
# @param [Gitlab::ObjectifiedHash] failure_issue the existing failure issue
|
185
195
|
# @return [Gitlab::ObjectifiedHash] the new branch
|
186
196
|
def create_branch(failure_issue, example)
|
187
|
-
branch = @gitlab_client.create_branch(target_project, "#{failure_issue['iid']}-quarantine-#{example.name.
|
197
|
+
branch = @gitlab_client.create_branch(target_project, "#{failure_issue['iid']}-quarantine-#{example.name.gsub(/\W/, '-')}", ref)
|
188
198
|
|
189
199
|
log :branch, "Created branch #{branch['name']} (#{branch['web_url']})", 4
|
190
200
|
|
@@ -228,13 +238,15 @@ module Confiner
|
|
228
238
|
end
|
229
239
|
end
|
230
240
|
|
241
|
+
meets_or_exceeds_threshold = occurrences.size > threshold ? 'exceeds' : 'meets'
|
242
|
+
|
231
243
|
description = <<~MARKDOWN
|
232
244
|
## What does this MR do?
|
233
245
|
|
234
|
-
Quarantines the test `#{example.name}` (
|
246
|
+
Quarantines the test `#{example.name}` (https://gitlab.com/#{target_project}/-/blob/#{ref}/#{example.file}#L#{changed_line_number})
|
235
247
|
|
236
|
-
This test has been found by [Confiner](https://gitlab.com/gitlab-org/quality/confiner) to have
|
237
|
-
|
248
|
+
This test has been found by [Confiner](https://gitlab.com/gitlab-org/quality/confiner) to have failed
|
249
|
+
#{occurrences.size} times, which #{meets_or_exceeds_threshold} the threshold of #{threshold} times.
|
238
250
|
|
239
251
|
#{markdown_occurrences.join("\n")}
|
240
252
|
|
data/lib/confiner.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: confiner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GitLab Quality
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 3.10.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec-parameterized
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.5.1
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.5.1
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: zeitwerk
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -68,6 +82,7 @@ files:
|
|
68
82
|
- lib/confiner/plugin.rb
|
69
83
|
- lib/confiner/plugins/debug.rb
|
70
84
|
- lib/confiner/plugins/gitlab.rb
|
85
|
+
- lib/confiner/version.rb
|
71
86
|
homepage: https://gitlab.com/gitlab-org/quality/confiner
|
72
87
|
licenses:
|
73
88
|
- MIT
|