Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-07-19 17:16:28 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-07-19 17:16:28 +0300
commite4384360a16dd9a19d4d2d25d0ef1f2b862ed2a6 (patch)
tree2fcdfa7dcdb9db8f5208b2562f4b4e803d671243 /tooling
parentffda4e7bcac36987f936b4ba515995a6698698f0 (diff)
Add latest changes from gitlab-org/gitlab@16-2-stable-eev16.2.0-rc42
Diffstat (limited to 'tooling')
-rwxr-xr-xtooling/bin/find_only_allowed_files_changes2
-rwxr-xr-xtooling/bin/gettext_extractor17
-rw-r--r--tooling/danger/analytics_instrumentation.rb2
-rw-r--r--tooling/danger/config_files.rb2
-rw-r--r--tooling/danger/customer_success.rb4
-rw-r--r--tooling/danger/database_dictionary.rb2
-rw-r--r--tooling/danger/datateam.rb8
-rw-r--r--tooling/danger/experiments.rb34
-rw-r--r--tooling/danger/project_helper.rb6
-rw-r--r--tooling/danger/specs/feature_category_suggestion.rb2
-rw-r--r--tooling/danger/stable_branch.rb4
-rw-r--r--tooling/lib/tooling/kubernetes_client.rb2
-rw-r--r--tooling/lib/tooling/mappings/view_to_js_mappings.rb4
-rw-r--r--tooling/rspec_flaky/config.rb27
-rw-r--r--tooling/rspec_flaky/example.rb68
-rw-r--r--tooling/rspec_flaky/flaky_example.rb59
-rw-r--r--tooling/rspec_flaky/flaky_examples_collection.rb38
-rw-r--r--tooling/rspec_flaky/listener.rb70
-rw-r--r--tooling/rspec_flaky/report.rb57
19 files changed, 67 insertions, 341 deletions
diff --git a/tooling/bin/find_only_allowed_files_changes b/tooling/bin/find_only_allowed_files_changes
index c40048c66fa..1e903a4199f 100755
--- a/tooling/bin/find_only_allowed_files_changes
+++ b/tooling/bin/find_only_allowed_files_changes
@@ -3,6 +3,8 @@
require_relative '../lib/tooling/find_changes'
+ALLOWED_FILE_TYPES = ['.js', '.vue', '.md', '.scss'].freeze
+
if Tooling::FindChanges.new(from: :api).only_allowed_files_changed
puts "Only files with extensions #{ALLOWED_FILE_TYPES.join(', ')} were changed"
exit 0
diff --git a/tooling/bin/gettext_extractor b/tooling/bin/gettext_extractor
index 39f029616df..c430e89a9d3 100755
--- a/tooling/bin/gettext_extractor
+++ b/tooling/bin/gettext_extractor
@@ -4,6 +4,7 @@
require_relative '../lib/tooling/gettext_extractor'
pot_file = ARGV.shift
+silent = '--silent' in ARGV
if !pot_file || !Dir.exist?(File.dirname(pot_file))
abort <<~MSG
@@ -12,9 +13,11 @@ if !pot_file || !Dir.exist?(File.dirname(pot_file))
MSG
end
-puts <<~MSG
- Extracting translatable strings from source files...
-MSG
+unless silent
+ puts <<~MSG
+ Extracting translatable strings from source files...
+ MSG
+end
root_dir = File.expand_path('../../', __dir__)
@@ -24,6 +27,8 @@ extractor = Tooling::GettextExtractor.new(
File.write(pot_file, extractor.generate_pot)
-puts <<~MSG
- All done. Please commit the changes to `#{pot_file}`.
-MSG
+unless silent
+ puts <<~MSG
+ All done. Please commit the changes to `#{pot_file}`.
+ MSG
+end
diff --git a/tooling/danger/analytics_instrumentation.rb b/tooling/danger/analytics_instrumentation.rb
index 767ae8dfb4c..69cc30f51fb 100644
--- a/tooling/danger/analytics_instrumentation.rb
+++ b/tooling/danger/analytics_instrumentation.rb
@@ -77,7 +77,7 @@ module Tooling
def metric_scope_affected
select_models(helper.modified_files).each_with_object(Hash.new { |h, k| h[k] = [] }) do |file_name, matched_files|
helper.changed_lines(file_name).each do |mod_line, _i|
- next unless mod_line =~ /^\+\s+scope :\w+/
+ next unless /^\+\s+scope :\w+/.match?(mod_line)
affected_scope = mod_line.match(/:\w+/)
next if affected_scope.nil?
diff --git a/tooling/danger/config_files.rb b/tooling/danger/config_files.rb
index e165792471f..1b09da6c8c9 100644
--- a/tooling/danger/config_files.rb
+++ b/tooling/danger/config_files.rb
@@ -8,7 +8,7 @@ module Tooling
module ConfigFiles
include ::Tooling::Danger::Suggestor
- MISSING_INTRODUCED_BY_REGEX = /^\+?(?<attr_name>\s*introduced_by_url):\s*$/.freeze
+ MISSING_INTRODUCED_BY_REGEX = /^\+?(?<attr_name>\s*introduced_by_url):\s*$/
CONFIG_DIRS = %w[
config/feature_flags
diff --git a/tooling/danger/customer_success.rb b/tooling/danger/customer_success.rb
index 43bdeadd8a4..22911adee06 100644
--- a/tooling/danger/customer_success.rb
+++ b/tooling/danger/customer_success.rb
@@ -11,8 +11,8 @@ module Tooling
The following files require a review:
MSG
- FILE_PATH_REGEX = %r{((ee|jh)/)?config/metrics/.+\.yml}.freeze
- CATEGORY_CHANGED = /data_category: operational/i.freeze
+ FILE_PATH_REGEX = %r{((ee|jh)/)?config/metrics/.+\.yml}
+ CATEGORY_CHANGED = /data_category: operational/i
def build_message
return unless impacted?
diff --git a/tooling/danger/database_dictionary.rb b/tooling/danger/database_dictionary.rb
index 8776532ff84..2ea937efd73 100644
--- a/tooling/danger/database_dictionary.rb
+++ b/tooling/danger/database_dictionary.rb
@@ -14,7 +14,7 @@ module Tooling
def database_dictionary_files(change_type:)
files = helper.public_send("#{change_type}_files") # rubocop:disable GitlabSecurity/PublicSend
- files.filter_map { |path| Found.new(path) if path =~ DICTIONARY_PATH_REGEXP }
+ files.filter_map { |path| Found.new(path) if DICTIONARY_PATH_REGEXP.match?(path) }
end
class Found
diff --git a/tooling/danger/datateam.rb b/tooling/danger/datateam.rb
index dfa8e1549ef..86e413e55b6 100644
--- a/tooling/danger/datateam.rb
+++ b/tooling/danger/datateam.rb
@@ -13,10 +13,10 @@ module Tooling
MSG
DATA_WAREHOUSE_SCOPE = 'Data Warehouse::'
- FILE_PATH_REGEX = %r{((ee|jh)/)?config/metrics(/.+\.yml)}.freeze
- PERFORMANCE_INDICATOR_REGEX = %r{gmau|smau|paid_gmau|umau}.freeze
- METRIC_REMOVED = %r{\+status: removed}.freeze
- DATABASE_REGEX = %r{\Adb/structure\.sql}.freeze
+ FILE_PATH_REGEX = %r{((ee|jh)/)?config/metrics(/.+\.yml)}
+ PERFORMANCE_INDICATOR_REGEX = %r{gmau|smau|paid_gmau|umau}
+ METRIC_REMOVED = %r{\+status: removed}
+ DATABASE_REGEX = %r{\Adb/structure\.sql}
STRUCTURE_SQL_FILE = %w(db/structure.sql).freeze
def build_message
diff --git a/tooling/danger/experiments.rb b/tooling/danger/experiments.rb
new file mode 100644
index 00000000000..49489419bab
--- /dev/null
+++ b/tooling/danger/experiments.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+module Tooling
+ module Danger
+ module Experiments
+ EXPERIMENTS_YML_REGEX = %r{\A(ee/)?config/feature_flags/experiment/}
+ CLASS_FILES_DIR = %w[app/experiments/ ee/app/experiments/].freeze
+
+ def class_files_removed?
+ (removed_experiments & current_experiments_with_class_files).empty?
+ end
+
+ def removed_experiments
+ yml_files_paths = helper.deleted_files
+
+ yml_files_paths.select { |path| path =~ EXPERIMENTS_YML_REGEX }.map { |path| File.basename(path).chomp('.yml') }
+ end
+
+ private
+
+ def current_experiments_with_class_files
+ experiment_names = []
+
+ CLASS_FILES_DIR.each do |directory_path|
+ experiment_names += Dir.glob("#{directory_path}*.rb").map do |path|
+ File.basename(path).chomp('_experiment.rb')
+ end
+ end
+
+ experiment_names
+ end
+ end
+ end
+end
diff --git a/tooling/danger/project_helper.rb b/tooling/danger/project_helper.rb
index 9ab6c5fa32e..f7c8f4f5133 100644
--- a/tooling/danger/project_helper.rb
+++ b/tooling/danger/project_helper.rb
@@ -70,6 +70,7 @@ module Tooling
%r{\A((ee|jh)/)?app/assets/} => :frontend,
%r{\A((ee|jh)/)?app/views/.*\.svg} => :frontend,
%r{\A((ee|jh)/)?app/views/} => [:frontend, :backend],
+ %r{\A((ee|jh)/)?app/components/} => [:frontend, :backend],
%r{\A((ee|jh)/)?public/} => :frontend,
%r{\A((ee|jh)/)?spec/(javascripts|frontend|frontend_integration)/} => :frontend,
%r{\A((ee|jh)/)?spec/contracts/consumer} => :frontend,
@@ -112,10 +113,12 @@ module Tooling
%r{\A\.editorconfig\z} => :tooling,
%r{Dangerfile\z} => :tooling,
%r{\A((ee|jh)/)?(danger/|tooling/danger/)} => :tooling,
+ %r{\Agems/gem\.gitlab-ci\.yml\z} => :tooling,
+ %r{\Agems/config/} => :tooling,
%r{\A((ee|jh)/)?scripts/(lib/)?glfm/.*\.rb} => [:backend],
%r{\A((ee|jh)/)?scripts/(lib/)?glfm/.*\.js} => [:frontend],
- %r{\A((ee|jh)/)?scripts/remote_development/.*} => [:remote_development],
+ %r{\A((ee|jh)/)?scripts/remote_development/.*} => [:remote_development_be],
%r{\A((ee|jh)/)?scripts/.*\.rb} => [:backend, :tooling],
%r{\A((ee|jh)/)?scripts/.*\.js} => [:frontend, :tooling],
%r{\A((ee|jh)/)?scripts/} => :tooling,
@@ -161,6 +164,7 @@ module Tooling
%r{\A(Gemfile.*|Rakefile)\z} => :backend,
%r{\A[A-Z_]+_VERSION\z} => :backend,
%r{\A\.rubocop(_todo)?\.yml\z} => :backend,
+ %r{\Agems/.*/\.rubocop\.yml\z} => :backend,
%r{\A\.rubocop_todo/.*\.yml\z} => :backend,
%r{\Afile_hooks/} => :backend,
diff --git a/tooling/danger/specs/feature_category_suggestion.rb b/tooling/danger/specs/feature_category_suggestion.rb
index 5acf73c8956..00cb99f368b 100644
--- a/tooling/danger/specs/feature_category_suggestion.rb
+++ b/tooling/danger/specs/feature_category_suggestion.rb
@@ -18,7 +18,7 @@ module Tooling
changed_lines = helper.changed_lines(filename)
changed_lines.each do |changed_line|
- next unless changed_line =~ RSPEC_TOP_LEVEL_DESCRIBE_REGEX
+ next unless RSPEC_TOP_LEVEL_DESCRIBE_REGEX.match?(changed_line)
line_number = file_lines.find_index(changed_line.delete_prefix('+'))
next unless line_number
diff --git a/tooling/danger/stable_branch.rb b/tooling/danger/stable_branch.rb
index bba198d1310..efcd3cfc967 100644
--- a/tooling/danger/stable_branch.rb
+++ b/tooling/danger/stable_branch.rb
@@ -5,7 +5,7 @@ module Tooling
module StableBranch
VersionApiError = Class.new(StandardError)
- STABLE_BRANCH_REGEX = %r{\A(?<version>\d+-\d+)-stable-ee\z}.freeze
+ STABLE_BRANCH_REGEX = %r{\A(?<version>\d+-\d+)-stable-ee\z}
FAILING_PACKAGE_AND_TEST_STATUSES = %w[manual canceled].freeze
# rubocop:disable Lint/MixedRegexpCaptureTypes
@@ -16,7 +16,7 @@ module Tooling
(-(?<rc>rc(?<rc_number>\d*)))?
(-\h+\.\h+)?
(-ee|\.ee\.\d+)?\z
- }x.freeze
+ }x
# rubocop:enable Lint/MixedRegexpCaptureTypes
MAINTENANCE_POLICY_URL = 'https://docs.gitlab.com/ee/policy/maintenance.html'
diff --git a/tooling/lib/tooling/kubernetes_client.rb b/tooling/lib/tooling/kubernetes_client.rb
index 5579f130a84..276a7e64473 100644
--- a/tooling/lib/tooling/kubernetes_client.rb
+++ b/tooling/lib/tooling/kubernetes_client.rb
@@ -6,7 +6,7 @@ require_relative '../../../lib/gitlab/popen' unless defined?(Gitlab::Popen)
module Tooling
class KubernetesClient
- K8S_ALLOWED_NAMESPACES_REGEX = /^review-(?!apps).+/.freeze
+ K8S_ALLOWED_NAMESPACES_REGEX = /^review-(?!apps).+/
CommandFailedError = Class.new(StandardError)
def cleanup_namespaces_by_created_at(created_before:)
diff --git a/tooling/lib/tooling/mappings/view_to_js_mappings.rb b/tooling/lib/tooling/mappings/view_to_js_mappings.rb
index b78c354f9d2..56168592f0d 100644
--- a/tooling/lib/tooling/mappings/view_to_js_mappings.rb
+++ b/tooling/lib/tooling/mappings/view_to_js_mappings.rb
@@ -10,10 +10,10 @@ module Tooling
include Helpers::PredictiveTestsHelper
# The HTML attribute value pattern we're looking for to match an HTML file to a JS file.
- HTML_ATTRIBUTE_VALUE_REGEXP = /js-[-\w]+/.freeze
+ HTML_ATTRIBUTE_VALUE_REGEXP = /js-[-\w]+/
# Search for Rails partials included in an HTML file
- RAILS_PARTIAL_INVOCATION_REGEXP = %r{(?:render|render_if_exists)(?: |\()(?:partial: ?)?['"]([\w/-]+)['"]}.freeze
+ RAILS_PARTIAL_INVOCATION_REGEXP = %r{(?:render|render_if_exists)(?: |\()(?:partial: ?)?['"]([\w/-]+)['"]}
def initialize(
changed_files_pathname, predictive_tests_pathname,
diff --git a/tooling/rspec_flaky/config.rb b/tooling/rspec_flaky/config.rb
deleted file mode 100644
index 0e36e985aad..00000000000
--- a/tooling/rspec_flaky/config.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-# frozen_string_literal: true
-
-module RspecFlaky
- class Config
- def self.generate_report?
- !!(ENV['FLAKY_RSPEC_GENERATE_REPORT'] =~ /1|true/)
- end
-
- def self.suite_flaky_examples_report_path
- ENV['FLAKY_RSPEC_SUITE_REPORT_PATH'] || rails_path("rspec/flaky/suite-report.json")
- end
-
- def self.flaky_examples_report_path
- ENV['FLAKY_RSPEC_REPORT_PATH'] || rails_path("rspec/flaky/report.json")
- end
-
- def self.new_flaky_examples_report_path
- ENV['NEW_FLAKY_RSPEC_REPORT_PATH'] || rails_path("rspec/flaky/new-report.json")
- end
-
- def self.rails_path(path)
- return path unless defined?(Rails)
-
- Rails.root.join(path)
- end
- end
-end
diff --git a/tooling/rspec_flaky/example.rb b/tooling/rspec_flaky/example.rb
deleted file mode 100644
index 8f369c99c5b..00000000000
--- a/tooling/rspec_flaky/example.rb
+++ /dev/null
@@ -1,68 +0,0 @@
-# frozen_string_literal: true
-
-require 'forwardable'
-require 'digest'
-
-module RspecFlaky
- # This is a wrapper class for RSpec::Core::Example
- class Example
- extend Forwardable
-
- def_delegators :execution_result, :status, :exception
-
- def initialize(rspec_example)
- @rspec_example = rspec_example.respond_to?(:example) ? rspec_example.example : rspec_example
- end
-
- def uid
- @uid ||= Digest::MD5.hexdigest("#{description}-#{file}")
- end
-
- def example_id
- rspec_example.id
- end
-
- def file
- metadata[:file_path]
- end
-
- def line
- metadata[:line_number]
- end
-
- def description
- metadata[:full_description]
- end
-
- def attempts
- rspec_example.respond_to?(:attempts) ? rspec_example.attempts : 1
- end
-
- def feature_category
- metadata[:feature_category]
- end
-
- def to_h
- {
- example_id: example_id,
- file: file,
- line: line,
- description: description,
- last_attempts_count: attempts,
- feature_category: feature_category
- }
- end
-
- private
-
- attr_reader :rspec_example
-
- def metadata
- rspec_example.metadata
- end
-
- def execution_result
- rspec_example.execution_result
- end
- end
-end
diff --git a/tooling/rspec_flaky/flaky_example.rb b/tooling/rspec_flaky/flaky_example.rb
deleted file mode 100644
index 3ce48ce1cd3..00000000000
--- a/tooling/rspec_flaky/flaky_example.rb
+++ /dev/null
@@ -1,59 +0,0 @@
-# frozen_string_literal: true
-
-require 'ostruct'
-
-module RspecFlaky
- ALLOWED_ATTRIBUTES = %i[
- example_id
- file
- line
- description
- first_flaky_at
- last_flaky_at
- last_flaky_job
- last_attempts_count
- flaky_reports
- feature_category
- ].freeze
-
- # This represents a flaky RSpec example and is mainly meant to be saved in a JSON file
- class FlakyExample
- def initialize(example_hash)
- @attributes = {
- first_flaky_at: Time.now,
- last_flaky_at: Time.now,
- last_flaky_job: nil,
- last_attempts_count: example_hash[:attempts],
- flaky_reports: 0,
- feature_category: example_hash[:feature_category]
- }.merge(example_hash.slice(*ALLOWED_ATTRIBUTES))
-
- %i[first_flaky_at last_flaky_at].each do |attr|
- attributes[attr] = Time.parse(attributes[attr]) if attributes[attr].is_a?(String)
- end
- end
-
- def update!(example_hash)
- attributes[:file] = example_hash[:file]
- attributes[:line] = example_hash[:line]
- attributes[:description] = example_hash[:description]
- attributes[:first_flaky_at] ||= Time.now
- attributes[:last_flaky_at] = Time.now
- attributes[:flaky_reports] += 1
- attributes[:feature_category] = example_hash[:feature_category]
- attributes[:last_attempts_count] = example_hash[:last_attempts_count] if example_hash[:last_attempts_count]
-
- if ENV['CI_JOB_URL']
- attributes[:last_flaky_job] = "#{ENV['CI_JOB_URL']}"
- end
- end
-
- def to_h
- attributes.dup
- end
-
- private
-
- attr_reader :attributes
- end
-end
diff --git a/tooling/rspec_flaky/flaky_examples_collection.rb b/tooling/rspec_flaky/flaky_examples_collection.rb
deleted file mode 100644
index 019ebf703da..00000000000
--- a/tooling/rspec_flaky/flaky_examples_collection.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-# frozen_string_literal: true
-
-require 'active_support/hash_with_indifferent_access'
-require 'delegate'
-
-require_relative 'flaky_example'
-
-module RspecFlaky
- class FlakyExamplesCollection < SimpleDelegator
- def initialize(collection = {})
- unless collection.is_a?(Hash)
- raise ArgumentError, "`collection` must be a Hash, #{collection.class} given!"
- end
-
- collection_of_flaky_examples =
- collection.map do |uid, example|
- [
- uid,
- RspecFlaky::FlakyExample.new(example.to_h.symbolize_keys)
- ]
- end
-
- super(Hash[collection_of_flaky_examples])
- end
-
- def to_h
- transform_values { |example| example.to_h }.deep_symbolize_keys
- end
-
- def -(other)
- unless other.respond_to?(:key)
- raise ArgumentError, "`other` must respond to `#key?`, #{other.class} does not!"
- end
-
- self.class.new(reject { |uid, _| other.key?(uid) })
- end
- end
-end
diff --git a/tooling/rspec_flaky/listener.rb b/tooling/rspec_flaky/listener.rb
deleted file mode 100644
index 3431d814a8a..00000000000
--- a/tooling/rspec_flaky/listener.rb
+++ /dev/null
@@ -1,70 +0,0 @@
-# frozen_string_literal: true
-
-require 'json'
-
-require_relative 'config'
-require_relative 'example'
-require_relative 'flaky_example'
-require_relative 'flaky_examples_collection'
-require_relative 'report'
-
-module RspecFlaky
- class Listener
- # - suite_flaky_examples: contains all the currently tracked flacky example
- # for the whole RSpec suite
- # - flaky_examples: contains the examples detected as flaky during the
- # current RSpec run
- attr_reader :suite_flaky_examples, :flaky_examples
-
- def initialize(suite_flaky_examples_json = nil)
- @flaky_examples = RspecFlaky::FlakyExamplesCollection.new
- @suite_flaky_examples = init_suite_flaky_examples(suite_flaky_examples_json)
- end
-
- def example_passed(notification)
- current_example = RspecFlaky::Example.new(notification.example)
-
- return unless current_example.attempts > 1
-
- flaky_example = suite_flaky_examples.fetch(current_example.uid) { RspecFlaky::FlakyExample.new(current_example.to_h) }
- flaky_example.update!(current_example.to_h)
-
- flaky_examples[current_example.uid] = flaky_example
- end
-
- def dump_summary(_)
- RspecFlaky::Report.new(flaky_examples).write(RspecFlaky::Config.flaky_examples_report_path)
- # write_report_file(flaky_examples, RspecFlaky::Config.flaky_examples_report_path)
-
- if new_flaky_examples.any?
- rails_logger_warn("\nNew flaky examples detected:\n")
- rails_logger_warn(JSON.pretty_generate(new_flaky_examples.to_h)) # rubocop:disable Gitlab/Json
-
- RspecFlaky::Report.new(new_flaky_examples).write(RspecFlaky::Config.new_flaky_examples_report_path)
- # write_report_file(new_flaky_examples, RspecFlaky::Config.new_flaky_examples_report_path)
- end
- end
-
- private
-
- def new_flaky_examples
- @new_flaky_examples ||= flaky_examples - suite_flaky_examples
- end
-
- def init_suite_flaky_examples(suite_flaky_examples_json = nil)
- if suite_flaky_examples_json
- RspecFlaky::Report.load_json(suite_flaky_examples_json).flaky_examples
- else
- return {} unless File.exist?(RspecFlaky::Config.suite_flaky_examples_report_path)
-
- RspecFlaky::Report.load(RspecFlaky::Config.suite_flaky_examples_report_path).flaky_examples
- end
- end
-
- def rails_logger_warn(text)
- target = defined?(Rails) ? Rails.logger : Kernel
-
- target.warn(text)
- end
- end
-end
diff --git a/tooling/rspec_flaky/report.rb b/tooling/rspec_flaky/report.rb
deleted file mode 100644
index 17dbb277446..00000000000
--- a/tooling/rspec_flaky/report.rb
+++ /dev/null
@@ -1,57 +0,0 @@
-# frozen_string_literal: true
-
-require 'json'
-require 'time'
-
-require_relative 'config'
-require_relative 'flaky_examples_collection'
-
-module RspecFlaky
- # This class is responsible for loading/saving JSON reports, and pruning
- # outdated examples.
- class Report < SimpleDelegator
- OUTDATED_DAYS_THRESHOLD = 7
-
- attr_reader :flaky_examples
-
- def self.load(file_path)
- load_json(File.read(file_path))
- end
-
- def self.load_json(json)
- new(RspecFlaky::FlakyExamplesCollection.new(JSON.parse(json)))
- end
-
- def initialize(flaky_examples)
- unless flaky_examples.is_a?(RspecFlaky::FlakyExamplesCollection)
- raise ArgumentError, "`flaky_examples` must be a RspecFlaky::FlakyExamplesCollection, #{flaky_examples.class} given!"
- end
-
- @flaky_examples = flaky_examples
- super(flaky_examples)
- end
-
- def write(file_path)
- unless RspecFlaky::Config.generate_report?
- Kernel.warn "! Generating reports is disabled. To enable it, please set the `FLAKY_RSPEC_GENERATE_REPORT=1` !"
- return
- end
-
- report_path_dir = File.dirname(file_path)
- FileUtils.mkdir_p(report_path_dir) unless Dir.exist?(report_path_dir)
-
- File.write(file_path, JSON.pretty_generate(flaky_examples.to_h))
- end
-
- def prune_outdated(days: OUTDATED_DAYS_THRESHOLD)
- outdated_date_threshold = Time.now - (3600 * 24 * days)
- recent_flaky_examples = flaky_examples.dup
- .delete_if do |_uid, flaky_example|
- last_flaky_at = flaky_example.to_h[:last_flaky_at]
- last_flaky_at && last_flaky_at.to_i < outdated_date_threshold.to_i
- end
-
- self.class.new(RspecFlaky::FlakyExamplesCollection.new(recent_flaky_examples))
- end
- end
-end