confiner 0.1.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1f422b15043676a7b0404bdf5ab6c632bf51fe142d28700953fa8c84516f0ae1
4
- data.tar.gz: ff789be11d0c34fdfd4cd218540b5ec3d489b965ac228fbc21836ad15044ee50
3
+ metadata.gz: 2aec5b597e2386e03ac5df865c2a0adc622a13ec580047e9a320a5ddf80d486b
4
+ data.tar.gz: 41d27a7ae0f3e5fb86a8d19d00593a043bd08eefb9d9304d531f4ab46e81c726
5
5
  SHA512:
6
- metadata.gz: 79765878d4d9e6d259223857a506c7c2e29c702456be764fc9b4c6cf09e3b7fc0cbad4be7b244d1c3e62d80b07c9204bf46eb2d6ad2507111b01d70030175ec8
7
- data.tar.gz: a3657b3f2c129067ba22946691c138d5248dfd9d2b62fcb17b9bb3d3ddb56cd2a0c7d1a6d1ce9e9a66c22855b7569ccd4f38120f6636474a85591ed76796ec9a
6
+ metadata.gz: a265ca1e725d8075bdd17dfb67ffb2e74fccc171581255b71789f6491e9da2cdb7ee0737073d7dbe3cf02dc9e0cbc85ae9f05538e7021ef5d8eb2ffef53e4961
7
+ data.tar.gz: 35ba5a29c7bed14503fb81db7d791b392167630fe7f8780eb8e93277e0a4dde156d8d358abc68dfe2910eb7ee12fb4338f91d7b627ea5c86f639a2d98c56131d
data/lib/confiner/cli.rb CHANGED
@@ -17,7 +17,7 @@ module Confiner
17
17
  @rules = []
18
18
 
19
19
  # default logging to standard out
20
- Logger.log_to $stdout
20
+ Logger.log_to = $stdout
21
21
 
22
22
  if options.include?('--')
23
23
  @plugin_options = options[options.index('--')..]
@@ -65,7 +65,7 @@ module Confiner
65
65
  end
66
66
 
67
67
  opts.on('-o OUTPUT', '--output-to OUTPUT', 'File to output the log to') do |output_to|
68
- log_to(output_to)
68
+ Logger.log_to = output_to
69
69
  end
70
70
  end
71
71
 
@@ -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'])
@@ -4,17 +4,26 @@ 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\e[0;35m#{level.to_s.upcase}#{' ' * (12 - level.size)}\e[m#{"\t" * indentation}#{message}"
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
- Logger.log_to(File.open(Logger.log_to.strip, 'a+t')) if Logger.log_to.is_a?(String)
12
15
  Logger.log_to.puts(output)
13
16
  end
14
17
 
15
18
  # Where to output the log
16
- def self.log_to(file = $stdout)
17
- @out_file ||= file
19
+ def self.log_to
20
+ @out_file
21
+ end
22
+
23
+ def self.log_to=(file)
24
+ file = File.open(file.strip, 'a+t') if file.is_a?(String)
25
+
26
+ @out_file = file
18
27
  end
19
28
 
20
29
  def run(action)
@@ -21,8 +21,11 @@ module Confiner
21
21
  arg.each do |a, default_value|
22
22
  attr_writer a
23
23
 
24
+ default = default_value
25
+ default = ENV[default_value[1..]] if default_value[0] == '$'
26
+
24
27
  define_method(a) do
25
- instance_variable_get("@#{a}") || instance_variable_set("@#{a}", default_value)
28
+ instance_variable_get("@#{a}") || instance_variable_set("@#{a}", default)
26
29
  end
27
30
  end
28
31
  else
@@ -34,6 +37,8 @@ module Confiner
34
37
 
35
38
  def initialize(**args)
36
39
  args.each do |k, v|
40
+ v = ENV[v[1..]] if v[0] == '$' # get environment variable
41
+
37
42
  self.public_send(:"#{k}=", v)
38
43
  end
39
44
  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 => 'master' # the default Git ref used when updating
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
 
@@ -184,7 +186,7 @@ module Confiner
184
186
  # @param [Gitlab::ObjectifiedHash] failure_issue the existing failure issue
185
187
  # @return [Gitlab::ObjectifiedHash] the new branch
186
188
  def create_branch(failure_issue, example)
187
- branch = @gitlab_client.create_branch(target_project, "#{failure_issue['iid']}-quarantine-#{example.name.tr(' ', '-')}", ref)
189
+ branch = @gitlab_client.create_branch(target_project, "#{failure_issue['iid']}-quarantine-#{example.name.gsub(/\W/, '-')}", ref)
188
190
 
189
191
  log :branch, "Created branch #{branch['name']} (#{branch['web_url']})", 4
190
192
 
@@ -228,13 +230,15 @@ module Confiner
228
230
  end
229
231
  end
230
232
 
233
+ meets_or_exceeds_threshold = occurrences.size > threshold ? 'exceeds' : 'meets'
234
+
231
235
  description = <<~MARKDOWN
232
236
  ## What does this MR do?
233
237
 
234
- Quarantines the test `#{example.name}` (#{example.file}:#{changed_line_number})
238
+ Quarantines the test `#{example.name}` (https://gitlab.com/#{target_project}/-/blob/#{ref}/#{example.file}#L#{changed_line_number})
235
239
 
236
- This test has been found by [Confiner](https://gitlab.com/gitlab-org/quality/confiner) to have been failing for
237
- more than (or equal to) #{threshold} times. This test has failed #{occurrences.size} times.
240
+ This test has been found by [Confiner](https://gitlab.com/gitlab-org/quality/confiner) to have failed
241
+ #{occurrences.size} times, which #{meets_or_exceeds_threshold} the threshold of #{threshold} times.
238
242
 
239
243
  #{markdown_occurrences.join("\n")}
240
244
 
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Confiner
4
+ VERSION = '0.2.2'
5
+ end
data/lib/confiner.rb CHANGED
@@ -7,5 +7,5 @@ loader.push_dir(__dir__)
7
7
  loader.setup
8
8
 
9
9
  module Confiner
10
- VERSION = '0.1.1'
10
+ module Plugins; end
11
11
  end
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.1.1
4
+ version: 0.2.2
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-01-07 00:00:00.000000000 Z
11
+ date: 2022-03-04 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