summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2018-04-05 12:06:01 +0200
committerRémy Coutable <remy@rymai.me>2018-04-10 15:38:40 +0200
commit9bb97abf041d7aa17fc72b850ecc1695c1bad0f5 (patch)
tree0bc1c0d4cf6c3f145ba4d269e83265d633ffd034 /scripts
parent5bef32195b3d4a0062564af4dc5c0a6e56b10faf (diff)
downloadgitlab-ce-9bb97abf041d7aa17fc72b850ecc1695c1bad0f5.tar.gz
Introduce scripts/prune-old-flaky-specs to prune outdated flaky specs from the report
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/prune-old-flaky-specs33
1 files changed, 33 insertions, 0 deletions
diff --git a/scripts/prune-old-flaky-specs b/scripts/prune-old-flaky-specs
new file mode 100755
index 00000000000..6c74b1f289c
--- /dev/null
+++ b/scripts/prune-old-flaky-specs
@@ -0,0 +1,33 @@
+#!/usr/bin/env ruby
+
+require 'bundler/setup'
+Bundler.require(:default)
+
+require_relative '../lib/rspec_flaky/flaky_examples_collection'
+require_relative '../lib/rspec_flaky/examples_pruner'
+
+report_file = ARGV.shift
+unless report_file
+ puts 'usage: prune-old-flaky-specs <report-file> <new-report-file>'
+ exit 1
+end
+
+new_report_file = ARGV.shift || report_file
+
+DAYS_THRESHOLD = 90
+
+def days_from_now(days)
+ Time.now - (3600 * 24 * days)
+end
+
+puts "Loading #{report_file}..."
+collection = RspecFlaky::FlakyExamplesCollection.new(JSON.parse(File.read(report_file)))
+
+puts "Current report has #{collection.size} entries."
+
+new_collection = RspecFlaky::ExamplesPruner.new(collection).prune_examples_older_than(days_from_now(DAYS_THRESHOLD))
+
+puts "New report has #{new_collection.size} entries: #{collection.size - new_collection.size} entries older than #{DAYS_THRESHOLD} days were removed."
+
+File.write(new_report_file, JSON.pretty_generate(new_collection.to_report))
+puts "Saved #{new_report_file}."