packs 0.0.30 → 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: 4b82c7108ae3ca6db3f119837248bedbef6aa33481f51e40bb025e0a5f71d939
4
- data.tar.gz: cce06aa5315648c21fa26f55955b7aa49dfc0f04a0662fc9336b2131926ec98c
3
+ metadata.gz: e95bfe90d9d998317f46782be71a54dce569df90c9aa14d4c27fe8fe5fe39e4f
4
+ data.tar.gz: 39eeba5a2b20decbb502c3eeb113391e9834a8d4f646c659c7230f667e8ae921
5
5
  SHA512:
6
- metadata.gz: 3e5553c2866632b9d64bdff514ca2f301e96b22db903b3227909eb9c5e3232140a5566d1f878197794bf51d9fc0a268db17a4b47ad7fa1e420bac011394d0592
7
- data.tar.gz: 3b9867217baf53cf7f3e8fc6d99e1c17c6d1a1f6cbba6ddab6535a9de1c2eaafb2b1fcb06ba2e43d1772c95954f61b6f9c372c94838c699c3bfaa324324d4060
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
@@ -84,7 +86,6 @@ module Packs
84
86
  end
85
87
 
86
88
  add_public_directory(package) if package.enforce_privacy
87
- add_readme_todo(package)
88
89
  package_location = package.directory
89
90
 
90
91
  file_move_operations = T.let([], T::Array[Private::FileMoveOperation])
@@ -132,6 +133,8 @@ module Packs
132
133
  end
133
134
  end
134
135
 
136
+ add_readme_todo(package)
137
+
135
138
  per_file_processors.each do |processor|
136
139
  processor.after_move_files!(file_move_operations)
137
140
  end
@@ -196,13 +199,20 @@ module Packs
196
199
  new_dependencies += [new_package_name]
197
200
  end
198
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
+
199
209
  new_other_package = ParsePackwerk::Package.new(
200
210
  name: other_package.name,
201
211
  enforce_privacy: other_package.enforce_privacy,
202
212
  enforce_dependencies: other_package.enforce_dependencies,
203
213
  dependencies: new_dependencies.uniq.sort,
204
214
  metadata: other_package.metadata,
205
- config: other_package.config
215
+ config: new_config
206
216
  )
207
217
 
208
218
  ParsePackwerk.write_package_yml!(new_other_package)
@@ -478,45 +488,97 @@ module Packs
478
488
  Packs.find(package.name)
479
489
  end
480
490
 
481
- sig { params(packs: T::Array[Packs::Pack]).void }
482
- def self.get_info(packs: Packs.all)
483
- inbound_violations = {}
484
- 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
+
485
508
  ParsePackwerk.all.each do |p|
486
509
  p.violations.each do |violation|
487
- outbound_violations[p.name] ||= []
488
- outbound_violations[p.name] << violation
489
- inbound_violations[violation.to_package_name] ||= []
490
- 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
491
514
  end
492
515
  end
493
516
 
494
- all_inbound = T.let([], T::Array[ParsePackwerk::Violation])
495
- 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
+ }
496
521
  packs.each do |pack|
497
- all_inbound += inbound_violations[pack.name] || []
498
- all_outbound += outbound_violations[pack.name] || []
522
+ all[:inbound] += violations[:inbound][pack.name] || []
523
+ all[:outbound] += violations[:outbound][pack.name] || []
499
524
  end
500
525
 
501
- puts "There are #{all_inbound.select(&:privacy?).sum { |v| v.files.count }} total inbound privacy violations"
502
- puts "There are #{all_inbound.select(&:dependency?).sum { |v| v.files.count }} total inbound dependency violations"
503
- puts "There are #{all_outbound.select(&:privacy?).sum { |v| v.files.count }} total outbound privacy violations"
504
- 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
505
544
 
506
545
  packs.sort_by { |p| -p.relative_path.glob('**/*.rb').count }.each do |pack|
507
- puts "\n=========== Info about: #{pack.name}"
508
-
509
546
  owner = CodeOwnership.for_package(pack)
510
- puts "Owned by: #{owner.nil? ? 'No one' : owner.name}"
511
- puts "Size: #{pack.relative_path.glob('**/*.rb').count} ruby files"
512
- puts "Public API: #{pack.relative_path.join('app/public')}"
513
-
514
- inbound_for_pack = inbound_violations[pack.name] || []
515
- outbound_for_pack = outbound_violations[pack.name] || []
516
- puts "There are #{inbound_for_pack.select(&:privacy?).sum { |v| v.files.count }} inbound privacy violations"
517
- puts "There are #{inbound_for_pack.flatten.select(&:dependency?).sum { |v| v.files.count }} inbound dependency violations"
518
- puts "There are #{outbound_for_pack.select(&:privacy?).sum { |v| v.files.count }} outbound privacy violations"
519
- 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
520
582
  end
521
583
  end
522
584
 
@@ -99,7 +99,7 @@ module Packs
99
99
  <<~MSG
100
100
  Your next steps might be:
101
101
 
102
- 1) Delete the old pack when things look good: `rm -rf #{pack_name}`
102
+ 1) Delete the old pack when things look good: `git rm -r #{pack_name}`
103
103
 
104
104
  2) Run `bin/packwerk update-todo` to update the violations. Make sure to run `spring stop` first.
105
105
  MSG
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.30
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-09-26 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