summaryrefslogtreecommitdiff
path: root/scripts/merge-reports
blob: 43374d134d455aa2d787001dd3a1dd05358f471b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'json'

main_report_file = ARGV.shift
unless main_report_file
  puts 'usage: merge-reports <main-report> [extra reports...]'
  exit 1
end

puts "Loading #{main_report_file}..."
main_report = JSON.parse(File.read(main_report_file))
new_report = main_report.dup

ARGV.each do |report_file|
  next unless File.exist?(report_file)

  report = JSON.parse(File.read(report_file))

  # Remove existing values
  updates = report.delete_if do |key, value|
    main_report[key] && main_report[key] == value
  end
  new_report.merge!(updates)

  puts "Merged #{report_file} adding #{updates.size} results."
end

File.write(main_report_file, JSON.pretty_generate(new_report))
puts "Saved #{main_report_file}."