Skip to content

Commit

Permalink
Prefer some more code readability over DRYness
Browse files Browse the repository at this point in the history
This is to satisfy some feedback I got on the PR.
  • Loading branch information
oboxodo committed Oct 12, 2023
1 parent 9f419a5 commit 3431f36
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions lib/packs/private.rb
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,6 @@ def self.get_info(packs: Packs.all, format: :detail, types: %i[privacy dependenc
inbound: {},
outbound: {}
}
directions = violations.keys
dir_x_types = directions.product(types)

ParsePackwerk.all.each do |p|
p.violations.each do |violation|
Expand All @@ -522,14 +520,18 @@ def self.get_info(packs: Packs.all, format: :detail, types: %i[privacy dependenc
when :csv
headers = ['Date', 'Pack name', 'Owned by', 'Size', 'Public API']
headers.delete('Date') unless include_date
dir_x_types.each do |direction, type|
headers << "#{direction.capitalize} #{type} violations"
types.each do |type|
headers << "Inbound #{type} violations"
headers << "Outbound #{type} violations"
end
puts CSV.generate_line(headers)
else # :detail
puts "Date: #{today}" if include_date
dir_x_types.each do |direction, type|
puts "There are #{all[direction].select { _1.type.to_sym == type }.sum { |v| v.files.count }} total #{direction} #{type} violations"
types.each do |type|
inbound_count = all[:inbound].select { _1.type.to_sym == type }.sum { |v| v.files.count }
outbound_count = all[:outbound].select { _1.type.to_sym == type }.sum { |v| v.files.count }
puts "There are #{inbound_count} total inbound #{type} violations"
puts "There are #{outbound_count} total outbound #{type} violations"
end
end

Expand All @@ -546,9 +548,11 @@ def self.get_info(packs: Packs.all, format: :detail, types: %i[privacy dependenc

row.delete(:date) unless include_date

dir_x_types.each do |direction, type|
key = [direction, type, 'violations'].join('_').to_sym
row[key] = (violations[direction][pack.name] || []).select { _1.type.to_sym == type }.sum { |v| v.files.count }
types.each do |type|
key = ['inbound', type, 'violations'].join('_').to_sym
row[key] = (violations[:inbound][pack.name] || []).select { _1.type.to_sym == type }.sum { |v| v.files.count }
key = ['outbound', type, 'violations'].join('_').to_sym
row[key] = (violations[:outbound][pack.name] || []).select { _1.type.to_sym == type }.sum { |v| v.files.count }
end

case format
Expand All @@ -561,9 +565,11 @@ def self.get_info(packs: Packs.all, format: :detail, types: %i[privacy dependenc
puts "Owned by: #{row[:owner]}"
puts "Size: #{row[:size]} ruby files"
puts "Public API: #{row[:public_api]}"
dir_x_types.each do |direction, type|
key = [direction, type, 'violations'].join('_').to_sym
puts "There are #{row[key]} #{direction} #{type} violations"
types.each do |type|
key = ['inbound', type, 'violations'].join('_').to_sym
puts "There are #{row[key]} inbound #{type} violations"
key = ['outbound', type, 'violations'].join('_').to_sym
puts "There are #{row[key]} outbound #{type} violations"
end
end
end
Expand Down

0 comments on commit 3431f36

Please sign in to comment.