18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/use_packwerk/private/interactive_cli/use_cases/get_info.rb', line 18
def perform!(prompt)
team_or_pack = prompt.select('Do you want info by team or by pack?', ['By team', 'By pack'])
if team_or_pack == 'By team'
teams = TeamSelector.multi_select(prompt)
selected_packs = ParsePackwerk.all.select do |p|
teams.map(&:name).include?(CodeOwnership.for_package(p)&.name)
end
else
selected_packs = PackSelector.single_or_all_pack_multi_select(prompt, question_text: 'What pack(s) would you like info on?')
end
inbound_violations = {}
outbound_violations = {}
ParsePackwerk.all.each do |p|
violations_for_pack = ParsePackwerk::DeprecatedReferences.for(p).violations
violations_for_pack.each do |violation|
outbound_violations[p.name] ||= []
outbound_violations[p.name] << violation
inbound_violations[violation.to_package_name] ||= []
inbound_violations[violation.to_package_name] << violation
end
end
puts "You've selected #{selected_packs.count} packs. Wow! Here's all the info."
all_inbound = T.let([], T::Array[ParsePackwerk::Violation])
all_outbound = T.let([], T::Array[ParsePackwerk::Violation])
selected_packs.each do |pack|
all_inbound += inbound_violations[pack.name] || []
all_outbound += outbound_violations[pack.name] || []
end
puts "There are #{all_inbound.select(&:privacy?).sum { |v| v.files.count }} total inbound privacy violations"
puts "There are #{all_inbound.select(&:dependency?).sum { |v| v.files.count }} total inbound dependency violations"
puts "There are #{all_outbound.select(&:privacy?).sum { |v| v.files.count }} total outbound privacy violations"
puts "There are #{all_outbound.select(&:dependency?).sum { |v| v.files.count }} total outbound dependency violations"
selected_packs.sort_by { |p| -p.directory.glob('**/*.rb').count }.each do |pack|
puts "\n=========== Info about: #{pack.name}"
owner = CodeOwnership.for_package(pack)
puts "Owned by: #{owner.nil? ? 'No one' : owner.name}"
puts "Size: #{pack.directory.glob('**/*.rb').count} ruby files"
puts "Public API: #{pack.directory.join('app/public')}"
inbound_for_pack = inbound_violations[pack.name] || []
outbound_for_pack = outbound_violations[pack.name] || []
puts "There are #{inbound_for_pack.select(&:privacy?).sum { |v| v.files.count }} inbound privacy violations"
puts "There are #{inbound_for_pack.flatten.select(&:dependency?).sum { |v| v.files.count }} inbound dependency violations"
puts "There are #{outbound_for_pack.select(&:privacy?).sum { |v| v.files.count }} outbound privacy violations"
puts "There are #{outbound_for_pack.flatten.select(&:dependency?).sum { |v| v.files.count }} outbound dependency violations"
end
end
|