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 +4 -4
- data/lib/packs/cli.rb +16 -9
- data/lib/packs/private/interactive_cli/use_cases/get_info.rb +15 -1
- data/lib/packs/private.rb +92 -30
- data/lib/packs/user_event_logger.rb +1 -1
- data/lib/packs.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e95bfe90d9d998317f46782be71a54dce569df90c9aa14d4c27fe8fe5fe39e4f
|
4
|
+
data.tar.gz: 39eeba5a2b20decbb502c3eeb113391e9834a8d4f646c659c7230f667e8ae921
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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(
|
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:
|
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
|
482
|
-
|
483
|
-
|
484
|
-
|
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
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
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
|
-
|
495
|
-
|
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
|
-
|
498
|
-
|
522
|
+
all[:inbound] += violations[:inbound][pack.name] || []
|
523
|
+
all[:outbound] += violations[:outbound][pack.name] || []
|
499
524
|
end
|
500
525
|
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
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
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
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 -
|
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.
|
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-
|
11
|
+
date: 2023-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: code_ownership
|