packs 0.0.31 → 0.0.32

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1be2b40d120f6b71973da3e330c847f838d4aa0ff5ebd5746195bd2d5c4315e2
4
- data.tar.gz: 55b52c46ce021dea56b5002791a1b380c3b0d9b9afea4aa69cc097f53c26b66b
3
+ metadata.gz: e95bfe90d9d998317f46782be71a54dce569df90c9aa14d4c27fe8fe5fe39e4f
4
+ data.tar.gz: 39eeba5a2b20decbb502c3eeb113391e9834a8d4f646c659c7230f667e8ae921
5
5
  SHA512:
6
- metadata.gz: b79719467ebe137489298dbfa6156dfde81645cbc7a21845024add2530328b59c9587a0ce3a46d718b0a3507c9e49ae9036b7205467df6fe69d09eccaf461446
7
- data.tar.gz: 3598caac2513f596afc5514b3f56981129604cf152f5430736283fa43c0ba25e926b419c5a042fc9060c132cd848d456a4731646f45bf71d776e266a45a5cc38
6
+ metadata.gz: bd00632afab57dcd9bac60e5afab1b50a606e87f2f53bdc9ab6c0a1f8da26ca01565c6a363449f3bb5314449cf570087868de34368d74d6bba37293f49a47c7e
7
+ data.tar.gz: c45e3640db3a3251b04b54f14ce41347bf0d9ed03f3090efca62a3d68ab621631faab3c7d4d1d208cf0840781e6b4228635f2a24313921aa26cf48c3a3cbd924
data/lib/packs/cli.rb CHANGED
@@ -74,10 +74,7 @@ module Packs
74
74
  LONG_DESC
75
75
  sig { params(paths: String).void }
76
76
  def make_public(*paths)
77
- Packs.make_public!(
78
- paths_relative_to_root: paths,
79
- per_file_processors: [Packs::RubocopPostProcessor.new, Packs::CodeOwnershipPostProcessor.new]
80
- )
77
+ Packs.make_public!(paths_relative_to_root: paths)
81
78
  exit_successfully
82
79
  end
83
80
 
@@ -92,8 +89,7 @@ module Packs
92
89
  def move(pack_name, *paths)
93
90
  Packs.move_to_pack!(
94
91
  pack_name: pack_name,
95
- paths_relative_to_root: paths,
96
- per_file_processors: [Packs::RubocopPostProcessor.new, Packs::CodeOwnershipPostProcessor.new]
92
+ paths_relative_to_root: paths
97
93
  )
98
94
  exit_successfully
99
95
  end
@@ -129,9 +125,21 @@ module Packs
129
125
  end
130
126
 
131
127
  desc 'get_info [ packs/my_pack packs/my_other_pack ]', 'Get info about size and violations for packs'
128
+ option :include_date, type: :boolean, default: false, aliases: :d, banner: "Include today's date as part of the data (useful to take snapshots over time)"
129
+ option :format, type: :string, default: 'detail', aliases: :f, banner: 'Specify the output format (detail, csv)'
130
+ option :types, type: :string, default: 'privacy,dependency', aliases: :t, banner: 'List of validation types to include (privacy,dependency,architecture)'
132
131
  sig { params(pack_names: String).void }
133
132
  def get_info(*pack_names)
134
- Private.get_info(packs: parse_pack_names(pack_names))
133
+ selected_types = options[:types].to_s.downcase.split(',')
134
+ invalid_types = selected_types - POSIBLE_TYPES
135
+ raise StandardError, "Invalid type(s): #{invalid_types.join(', ')}. Possible types are: #{POSIBLE_TYPES.join(', ')}" unless invalid_types.empty?
136
+
137
+ Private.get_info(
138
+ packs: parse_pack_names(pack_names),
139
+ format: options[:format].to_sym,
140
+ types: selected_types.map(&:to_sym),
141
+ include_date: options[:include_date]
142
+ )
135
143
  exit_successfully
136
144
  end
137
145
 
@@ -147,8 +155,7 @@ module Packs
147
155
  def move_to_parent(child_pack_name, parent_pack_name)
148
156
  Packs.move_to_parent!(
149
157
  parent_name: parent_pack_name,
150
- pack_name: child_pack_name,
151
- per_file_processors: [Packs::RubocopPostProcessor.new, Packs::CodeOwnershipPostProcessor.new]
158
+ pack_name: child_pack_name
152
159
  )
153
160
  exit_successfully
154
161
  end
@@ -26,9 +26,23 @@ module Packs
26
26
  selected_packs = PackSelector.single_or_all_pack_multi_select(prompt, question_text: 'What pack(s) would you like info on?')
27
27
  end
28
28
 
29
+ format = prompt.select('What output format do you want?', %w[Detail CSV])
30
+
31
+ types = prompt.multi_select(
32
+ 'What violation types do you want stats for?',
33
+ %w[Privacy Dependency Architecture]
34
+ )
35
+
36
+ include_date = !prompt.no?('Should the current date be included in the report?')
37
+
29
38
  puts "You've selected #{selected_packs.count} packs. Wow! Here's all the info."
30
39
 
31
- Private.get_info(packs: selected_packs)
40
+ Private.get_info(
41
+ packs: selected_packs,
42
+ format: format.downcase.to_sym,
43
+ types: types.map(&:downcase).map(&:to_sym),
44
+ include_date: include_date
45
+ )
32
46
  end
33
47
  end
34
48
  end
data/lib/packs/private.rb CHANGED
@@ -10,6 +10,8 @@ require 'packs/private/file_move_operation'
10
10
  require 'packs/private/pack_relationship_analyzer'
11
11
  require 'packs/private/interactive_cli'
12
12
 
13
+ require 'date'
14
+
13
15
  module Packs
14
16
  module Private
15
17
  extend T::Sig
@@ -197,13 +199,20 @@ module Packs
197
199
  new_dependencies += [new_package_name]
198
200
  end
199
201
 
202
+ new_config = other_package.config.dup
203
+ if new_config['ignored_dependencies']
204
+ new_config['ignored_dependencies'] = new_config['ignored_dependencies'].map do |d|
205
+ d == pack_name ? new_package_name : d
206
+ end
207
+ end
208
+
200
209
  new_other_package = ParsePackwerk::Package.new(
201
210
  name: other_package.name,
202
211
  enforce_privacy: other_package.enforce_privacy,
203
212
  enforce_dependencies: other_package.enforce_dependencies,
204
213
  dependencies: new_dependencies.uniq.sort,
205
214
  metadata: other_package.metadata,
206
- config: other_package.config
215
+ config: new_config
207
216
  )
208
217
 
209
218
  ParsePackwerk.write_package_yml!(new_other_package)
@@ -479,45 +488,97 @@ module Packs
479
488
  Packs.find(package.name)
480
489
  end
481
490
 
482
- sig { params(packs: T::Array[Packs::Pack]).void }
483
- def self.get_info(packs: Packs.all)
484
- inbound_violations = {}
485
- outbound_violations = {}
491
+ sig do
492
+ params(
493
+ packs: T::Array[Packs::Pack],
494
+ format: Symbol,
495
+ types: T::Array[Symbol],
496
+ include_date: T::Boolean
497
+ ).void
498
+ end
499
+ def self.get_info(packs: Packs.all, format: :detail, types: %i[privacy dependency architecture], include_date: false)
500
+ require 'csv' if format == :csv
501
+
502
+ today = Date.today.iso8601
503
+ violations = {
504
+ inbound: {},
505
+ outbound: {}
506
+ }
507
+
486
508
  ParsePackwerk.all.each do |p|
487
509
  p.violations.each do |violation|
488
- outbound_violations[p.name] ||= []
489
- outbound_violations[p.name] << violation
490
- inbound_violations[violation.to_package_name] ||= []
491
- inbound_violations[violation.to_package_name] << violation
510
+ violations[:outbound][p.name] ||= []
511
+ violations[:outbound][p.name] << violation
512
+ violations[:inbound][violation.to_package_name] ||= []
513
+ violations[:inbound][violation.to_package_name] << violation
492
514
  end
493
515
  end
494
516
 
495
- all_inbound = T.let([], T::Array[ParsePackwerk::Violation])
496
- all_outbound = T.let([], T::Array[ParsePackwerk::Violation])
517
+ all = {
518
+ inbound: T.let([], T::Array[ParsePackwerk::Violation]),
519
+ outbound: T.let([], T::Array[ParsePackwerk::Violation])
520
+ }
497
521
  packs.each do |pack|
498
- all_inbound += inbound_violations[pack.name] || []
499
- all_outbound += outbound_violations[pack.name] || []
522
+ all[:inbound] += violations[:inbound][pack.name] || []
523
+ all[:outbound] += violations[:outbound][pack.name] || []
500
524
  end
501
525
 
502
- puts "There are #{all_inbound.select(&:privacy?).sum { |v| v.files.count }} total inbound privacy violations"
503
- puts "There are #{all_inbound.select(&:dependency?).sum { |v| v.files.count }} total inbound dependency violations"
504
- puts "There are #{all_outbound.select(&:privacy?).sum { |v| v.files.count }} total outbound privacy violations"
505
- puts "There are #{all_outbound.select(&:dependency?).sum { |v| v.files.count }} total outbound dependency violations"
526
+ case format
527
+ when :csv
528
+ headers = ['Date', 'Pack name', 'Owned by', 'Size', 'Public API']
529
+ headers.delete('Date') unless include_date
530
+ types.each do |type|
531
+ headers << "Inbound #{type} violations"
532
+ headers << "Outbound #{type} violations"
533
+ end
534
+ puts CSV.generate_line(headers)
535
+ else # :detail
536
+ puts "Date: #{today}" if include_date
537
+ types.each do |type|
538
+ inbound_count = all[:inbound].select { _1.type.to_sym == type }.sum { |v| v.files.count }
539
+ outbound_count = all[:outbound].select { _1.type.to_sym == type }.sum { |v| v.files.count }
540
+ puts "There are #{inbound_count} total inbound #{type} violations"
541
+ puts "There are #{outbound_count} total outbound #{type} violations"
542
+ end
543
+ end
506
544
 
507
545
  packs.sort_by { |p| -p.relative_path.glob('**/*.rb').count }.each do |pack|
508
- puts "\n=========== Info about: #{pack.name}"
509
-
510
546
  owner = CodeOwnership.for_package(pack)
511
- puts "Owned by: #{owner.nil? ? 'No one' : owner.name}"
512
- puts "Size: #{pack.relative_path.glob('**/*.rb').count} ruby files"
513
- puts "Public API: #{pack.relative_path.join('app/public')}"
514
-
515
- inbound_for_pack = inbound_violations[pack.name] || []
516
- outbound_for_pack = outbound_violations[pack.name] || []
517
- puts "There are #{inbound_for_pack.select(&:privacy?).sum { |v| v.files.count }} inbound privacy violations"
518
- puts "There are #{inbound_for_pack.flatten.select(&:dependency?).sum { |v| v.files.count }} inbound dependency violations"
519
- puts "There are #{outbound_for_pack.select(&:privacy?).sum { |v| v.files.count }} outbound privacy violations"
520
- puts "There are #{outbound_for_pack.flatten.select(&:dependency?).sum { |v| v.files.count }} outbound dependency violations"
547
+
548
+ row = {
549
+ date: today,
550
+ pack_name: pack.name,
551
+ owner: owner.nil? ? 'No one' : owner.name,
552
+ size: pack.relative_path.glob('**/*.rb').count,
553
+ public_api: pack.relative_path.join('app/public')
554
+ }
555
+
556
+ row.delete(:date) unless include_date
557
+
558
+ types.each do |type|
559
+ key = ['inbound', type, 'violations'].join('_').to_sym
560
+ row[key] = (violations[:inbound][pack.name] || []).select { _1.type.to_sym == type }.sum { |v| v.files.count }
561
+ key = ['outbound', type, 'violations'].join('_').to_sym
562
+ row[key] = (violations[:outbound][pack.name] || []).select { _1.type.to_sym == type }.sum { |v| v.files.count }
563
+ end
564
+
565
+ case format
566
+ when :csv
567
+ puts CSV.generate_line(row.values)
568
+ else # :detail
569
+ puts "\n=========== Info about: #{row[:pack_name]}"
570
+
571
+ puts "Date: #{row[:date]}" if include_date
572
+ puts "Owned by: #{row[:owner]}"
573
+ puts "Size: #{row[:size]} ruby files"
574
+ puts "Public API: #{row[:public_api]}"
575
+ types.each do |type|
576
+ key = ['inbound', type, 'violations'].join('_').to_sym
577
+ puts "There are #{row[key]} inbound #{type} violations"
578
+ key = ['outbound', type, 'violations'].join('_').to_sym
579
+ puts "There are #{row[key]} outbound #{type} violations"
580
+ end
581
+ end
521
582
  end
522
583
  end
523
584
 
data/lib/packs.rb CHANGED
@@ -82,7 +82,7 @@ module Packs
82
82
  def self.move_to_pack!(
83
83
  pack_name:,
84
84
  paths_relative_to_root: [],
85
- per_file_processors: []
85
+ per_file_processors: [Packs::RubocopPostProcessor.new, Packs::CodeOwnershipPostProcessor.new]
86
86
  )
87
87
  Logging.section('👋 Hi!') do
88
88
  intro = Packs.config.user_event_logger.before_move_to_pack(pack_name)
@@ -109,7 +109,7 @@ module Packs
109
109
  end
110
110
  def self.make_public!(
111
111
  paths_relative_to_root: [],
112
- per_file_processors: []
112
+ per_file_processors: [Packs::RubocopPostProcessor.new, Packs::CodeOwnershipPostProcessor.new]
113
113
  )
114
114
  Logging.section('Making files public') do
115
115
  intro = Packs.config.user_event_logger.before_make_public
@@ -163,7 +163,7 @@ module Packs
163
163
  def self.move_to_parent!(
164
164
  pack_name:,
165
165
  parent_name:,
166
- per_file_processors: []
166
+ per_file_processors: [Packs::RubocopPostProcessor.new, Packs::CodeOwnershipPostProcessor.new]
167
167
  )
168
168
  Logging.section('👋 Hi!') do
169
169
  intro = Packs.config.user_event_logger.before_move_to_parent(pack_name)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: packs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.31
4
+ version: 0.0.32
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gusto Engineers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-11 00:00:00.000000000 Z
11
+ date: 2023-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: code_ownership