packs 0.0.27 → 0.0.29
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -11
- data/lib/packs/cli.rb +22 -23
- data/lib/packs/private/interactive_cli/use_cases/query.rb +7 -13
- data/lib/packs/private/pack_relationship_analyzer.rb +4 -67
- data/lib/packs/private.rb +2 -2
- data/lib/packs/user_event_logger.rb +7 -28
- data/lib/packs.rb +5 -18
- 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: 84931190d8fadb4e5aa74164f918bca6c92e5aabdd5be9a18ff0765778f7ce04
|
4
|
+
data.tar.gz: 33d2fb7b80465f54903c59eaae5d6e061827e0f806e8f99262b679d19cd93d11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7305b0e9e79aa830d14b04c2747a55240f8618783bd3588a6274985ccdd9be91f60deaba5f455733ed7dc5d40c28f2de9426494374983135121fcbd48d766ac4
|
7
|
+
data.tar.gz: cb9827aafcc9534fff14c982a1095b56d06880750cc8d8f450cb6db5d44c6c1ede6292c650dd2864fb5a20daad319fbf5d3aa53a616889eb6d0738ea9f5c54fc
|
data/README.md
CHANGED
@@ -49,21 +49,16 @@ modify packs/from_pack/package.yml's list of dependencies and add packs/to_pack.
|
|
49
49
|
|
50
50
|
This command will also sort the list and make it unique.
|
51
51
|
|
52
|
-
## List the top
|
53
|
-
`bin/packs
|
52
|
+
## List the top violations of a specific type for packs/your_pack.
|
53
|
+
`bin/packs list_top_violations type [ packs/your_pack ]`
|
54
54
|
|
55
|
-
|
55
|
+
Possible types are: dependency, privacy, architecture.
|
56
56
|
|
57
|
-
You can use this command to list the top dependency violations.
|
57
|
+
Want to see who is depending on you? Not sure how your pack's code is being used in an unstated way? You can use this command to list the top dependency violations.
|
58
58
|
|
59
|
-
|
60
|
-
|
61
|
-
## List the top privacy violations of packs/your_pack
|
62
|
-
`bin/packs list_top_privacy_violations packs/your_pack`
|
63
|
-
|
64
|
-
Want to create interfaces? Not sure how your pack's code is being used?
|
59
|
+
Want to create interfaces? Not sure how your pack's code is being used? You can use this command to list the top privacy violations.
|
65
60
|
|
66
|
-
You can use this command to list the top
|
61
|
+
Want to focus on the big picture first? You can use this command to list the top architecture violations.
|
67
62
|
|
68
63
|
If no pack name is passed in, this will list out violations across all packs.
|
69
64
|
|
data/lib/packs/cli.rb
CHANGED
@@ -7,9 +7,13 @@ module Packs
|
|
7
7
|
extend T::Sig
|
8
8
|
|
9
9
|
desc 'create packs/your_pack', 'Create pack with name packs/your_pack'
|
10
|
+
option :enforce_privacy, type: :boolean, default: true, aliases: :p, banner: 'Enforce privacy'
|
10
11
|
sig { params(pack_name: String).void }
|
11
12
|
def create(pack_name)
|
12
|
-
Packs.create_pack!(
|
13
|
+
Packs.create_pack!(
|
14
|
+
pack_name: pack_name,
|
15
|
+
enforce_privacy: options[:enforce_privacy]
|
16
|
+
)
|
13
17
|
exit_successfully
|
14
18
|
end
|
15
19
|
|
@@ -31,36 +35,31 @@ module Packs
|
|
31
35
|
exit_successfully
|
32
36
|
end
|
33
37
|
|
34
|
-
|
38
|
+
POSIBLE_TYPES = T.let(%w[dependency privacy architecture], T::Array[String])
|
39
|
+
desc 'list_top_violations type [ packs/your_pack ]', 'List the top violations of a specific type for packs/your_pack.'
|
35
40
|
long_desc <<~LONG_DESC
|
36
|
-
|
41
|
+
Possible types are: #{POSIBLE_TYPES.join(', ')}.
|
37
42
|
|
38
|
-
You can use this command to list the top dependency violations.
|
39
|
-
|
40
|
-
If no pack name is passed in, this will list out violations across all packs.
|
41
|
-
LONG_DESC
|
42
|
-
option :limit, type: :numeric, default: 10, aliases: :l, banner: 'Specify the limit of constants to analyze'
|
43
|
-
sig { params(pack_name: String).void }
|
44
|
-
def list_top_dependency_violations(pack_name)
|
45
|
-
Packs.list_top_dependency_violations(
|
46
|
-
pack_name: pack_name,
|
47
|
-
limit: options[:limit]
|
48
|
-
)
|
49
|
-
exit_successfully
|
50
|
-
end
|
43
|
+
Want to see who is depending on you? Not sure how your pack's code is being used in an unstated way? You can use this command to list the top dependency violations.
|
51
44
|
|
52
|
-
|
53
|
-
long_desc <<~LONG_DESC
|
54
|
-
Want to create interfaces? Not sure how your pack's code is being used?
|
45
|
+
Want to create interfaces? Not sure how your pack's code is being used? You can use this command to list the top privacy violations.
|
55
46
|
|
56
|
-
You can use this command to list the top
|
47
|
+
Want to focus on the big picture first? You can use this command to list the top architecture violations.
|
57
48
|
|
58
49
|
If no pack name is passed in, this will list out violations across all packs.
|
59
50
|
LONG_DESC
|
60
51
|
option :limit, type: :numeric, default: 10, aliases: :l, banner: 'Specify the limit of constants to analyze'
|
61
|
-
sig
|
62
|
-
|
63
|
-
|
52
|
+
sig do
|
53
|
+
params(
|
54
|
+
type: String,
|
55
|
+
pack_name: T.nilable(String)
|
56
|
+
).void
|
57
|
+
end
|
58
|
+
def list_top_violations(type, pack_name = nil)
|
59
|
+
raise StandardError, "Invalid type #{type}. Possible types are: #{POSIBLE_TYPES.join(', ')}" unless POSIBLE_TYPES.include?(type)
|
60
|
+
|
61
|
+
Packs.list_top_violations(
|
62
|
+
type: type,
|
64
63
|
pack_name: pack_name,
|
65
64
|
limit: options[:limit]
|
66
65
|
)
|
@@ -21,7 +21,7 @@ module Packs
|
|
21
21
|
def perform!(prompt)
|
22
22
|
selection = prompt.select('For one pack or all packs?', ['One pack', 'All packs'])
|
23
23
|
if selection == 'All packs'
|
24
|
-
# Probably should just make `
|
24
|
+
# Probably should just make `list_top_violations` take in an array of things
|
25
25
|
# Better yet we might just want to replace these functions with `QueryPackwerk`
|
26
26
|
selected_pack = nil
|
27
27
|
else
|
@@ -30,19 +30,13 @@ module Packs
|
|
30
30
|
|
31
31
|
limit = prompt.ask('Specify the limit of constants to analyze', default: 10, convert: :integer)
|
32
32
|
|
33
|
-
selection = prompt.select('Are you interested in dependency or privacy violations?', %w[Dependency Privacy], default: 'Privacy')
|
33
|
+
selection = prompt.select('Are you interested in dependency, or privacy violations?', %w[Dependency Privacy Architecture], default: 'Privacy')
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
else
|
41
|
-
Packs.list_top_privacy_violations(
|
42
|
-
pack_name: selected_pack,
|
43
|
-
limit: limit
|
44
|
-
)
|
45
|
-
end
|
35
|
+
Packs.list_top_violations(
|
36
|
+
type: selection.downcase,
|
37
|
+
pack_name: selected_pack,
|
38
|
+
limit: limit
|
39
|
+
)
|
46
40
|
end
|
47
41
|
end
|
48
42
|
end
|
@@ -7,74 +7,12 @@ module Packs
|
|
7
7
|
|
8
8
|
sig do
|
9
9
|
params(
|
10
|
+
type: String,
|
10
11
|
pack_name: T.nilable(String),
|
11
12
|
limit: Integer
|
12
13
|
).void
|
13
14
|
end
|
14
|
-
def self.
|
15
|
-
all_packages = ParsePackwerk.all
|
16
|
-
if pack_name.nil?
|
17
|
-
to_package_names = all_packages.map(&:name)
|
18
|
-
else
|
19
|
-
pack_name = Private.clean_pack_name(pack_name)
|
20
|
-
package = all_packages.find { |p| p.name == pack_name }
|
21
|
-
if package.nil?
|
22
|
-
raise StandardError, "Can not find package with name #{pack_name}. Make sure the argument is of the form `packs/my_pack/`"
|
23
|
-
end
|
24
|
-
|
25
|
-
to_package_names = [pack_name]
|
26
|
-
end
|
27
|
-
|
28
|
-
violations_by_count = {}
|
29
|
-
total_pack_violation_count = 0
|
30
|
-
|
31
|
-
Logging.section('👋 Hi there') do
|
32
|
-
intro = Packs.config.user_event_logger.before_list_top_privacy_violations(pack_name, limit)
|
33
|
-
Logging.print_bold_green(intro)
|
34
|
-
end
|
35
|
-
|
36
|
-
# TODO: This is a copy of the implementation below. We may want to refactor out this implementation detail before making changes that apply to both.
|
37
|
-
all_packages.each do |client_package|
|
38
|
-
client_package.violations.select(&:privacy?).each do |violation|
|
39
|
-
next unless to_package_names.include?(violation.to_package_name)
|
40
|
-
|
41
|
-
if pack_name.nil?
|
42
|
-
violated_symbol = "#{violation.class_name} (#{violation.to_package_name})"
|
43
|
-
else
|
44
|
-
violated_symbol = violation.class_name
|
45
|
-
end
|
46
|
-
violations_by_count[violated_symbol] ||= {}
|
47
|
-
violations_by_count[violated_symbol][:total_count] ||= 0
|
48
|
-
violations_by_count[violated_symbol][:by_package] ||= {}
|
49
|
-
violations_by_count[violated_symbol][:by_package][client_package.name] ||= 0
|
50
|
-
violations_by_count[violated_symbol][:total_count] += violation.files.count
|
51
|
-
violations_by_count[violated_symbol][:by_package][client_package.name] += violation.files.count
|
52
|
-
total_pack_violation_count += violation.files.count
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
Logging.print("Total Count: #{total_pack_violation_count}")
|
57
|
-
|
58
|
-
sorted_violations = violations_by_count.sort_by { |violated_symbol, count_info| [-count_info[:total_count], violated_symbol] }
|
59
|
-
sorted_violations.first(limit).each do |violated_symbol, count_info|
|
60
|
-
percentage_of_total = (count_info[:total_count] * 100.0 / total_pack_violation_count).round(2)
|
61
|
-
Logging.print(violated_symbol)
|
62
|
-
Logging.print(" - Total Count: #{count_info[:total_count]} (#{percentage_of_total}% of total)")
|
63
|
-
|
64
|
-
Logging.print(' - By package:')
|
65
|
-
count_info[:by_package].sort_by { |client_package_name, count| [-count, client_package_name] }.each do |client_package_name, count|
|
66
|
-
Logging.print(" - #{client_package_name}: #{count}")
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
sig do
|
72
|
-
params(
|
73
|
-
pack_name: T.nilable(String),
|
74
|
-
limit: Integer
|
75
|
-
).void
|
76
|
-
end
|
77
|
-
def self.list_top_dependency_violations(pack_name, limit)
|
15
|
+
def self.list_top_violations(type, pack_name, limit)
|
78
16
|
all_packages = ParsePackwerk.all
|
79
17
|
|
80
18
|
if pack_name.nil?
|
@@ -90,16 +28,15 @@ module Packs
|
|
90
28
|
end
|
91
29
|
|
92
30
|
Logging.section('👋 Hi there') do
|
93
|
-
intro = Packs.config.user_event_logger.
|
31
|
+
intro = Packs.config.user_event_logger.before_list_top_violations(type, pack_name, limit)
|
94
32
|
Logging.print_bold_green(intro)
|
95
33
|
end
|
96
34
|
|
97
35
|
violations_by_count = {}
|
98
36
|
total_pack_violation_count = 0
|
99
37
|
|
100
|
-
# TODO: This is a copy of the implementation above. We may want to refactor out this implementation detail before making changes that apply to both.
|
101
38
|
all_packages.each do |client_package|
|
102
|
-
client_package.violations.select
|
39
|
+
client_package.violations.select { _1.type == type }.each do |violation|
|
103
40
|
next unless to_package_names.include?(violation.to_package_name)
|
104
41
|
|
105
42
|
if pack_name.nil?
|
data/lib/packs/private.rb
CHANGED
@@ -58,7 +58,7 @@ module Packs
|
|
58
58
|
pack_name = Private.clean_pack_name(pack_name)
|
59
59
|
|
60
60
|
package = create_pack_if_not_exists!(pack_name: pack_name, enforce_privacy: enforce_privacy, enforce_dependencies: enforce_dependencies, team: team)
|
61
|
-
add_public_directory(package)
|
61
|
+
add_public_directory(package) if package.enforce_privacy
|
62
62
|
add_readme_todo(package)
|
63
63
|
|
64
64
|
Logging.section('Next steps') do
|
@@ -82,7 +82,7 @@ module Packs
|
|
82
82
|
raise StandardError, "Can not find package with name #{pack_name}. Make sure the argument is of the form `packs/my_pack/`"
|
83
83
|
end
|
84
84
|
|
85
|
-
add_public_directory(package)
|
85
|
+
add_public_directory(package) if package.enforce_privacy
|
86
86
|
add_readme_todo(package)
|
87
87
|
package_location = package.directory
|
88
88
|
|
@@ -117,7 +117,7 @@ module Packs
|
|
117
117
|
You can prevent other packs from using private API by using packwerk.
|
118
118
|
|
119
119
|
Want to find how your private API is being used today?
|
120
|
-
Try running: `bin/packs
|
120
|
+
Try running: `bin/packs list_top_violations privacy #{pack_name}`
|
121
121
|
|
122
122
|
Want to move something into this folder?
|
123
123
|
Try running: `bin/packs make_public #{pack_name}/path/to/file.rb`
|
@@ -149,41 +149,20 @@ module Packs
|
|
149
149
|
MSG
|
150
150
|
end
|
151
151
|
|
152
|
-
sig { params(pack_name: T.nilable(String), limit: Integer).returns(String) }
|
153
|
-
def
|
152
|
+
sig { params(type: String, pack_name: T.nilable(String), limit: Integer).returns(String) }
|
153
|
+
def before_list_top_violations(type, pack_name, limit)
|
154
154
|
if pack_name.nil?
|
155
155
|
<<~PACK_CONTENT
|
156
|
-
You are listing top #{limit}
|
157
|
-
Pass in a limit to display more or less, e.g. `bin/packs
|
156
|
+
You are listing top #{limit} #{type} violations for all packs. See #{documentation_link} for other utilities!
|
157
|
+
Pass in a limit to display more or less, e.g. `bin/packs list_top_violations #{type} #{pack_name} -l 1000`
|
158
158
|
|
159
159
|
This script is intended to help you find which of YOUR pack's private classes, constants, or modules other packs are using the most.
|
160
160
|
Anything not in pack_name/app/public is considered private API.
|
161
161
|
PACK_CONTENT
|
162
162
|
else
|
163
163
|
<<~PACK_CONTENT
|
164
|
-
You are listing top #{limit}
|
165
|
-
Pass in a limit to display more or less, e.g. `bin/packs
|
166
|
-
|
167
|
-
This script is intended to help you find which of YOUR pack's private classes, constants, or modules other packs are using the most.
|
168
|
-
Anything not in #{pack_name}/app/public is considered private API.
|
169
|
-
PACK_CONTENT
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
sig { params(pack_name: T.nilable(String), limit: Integer).returns(String) }
|
174
|
-
def before_list_top_privacy_violations(pack_name, limit)
|
175
|
-
if pack_name.nil?
|
176
|
-
<<~PACK_CONTENT
|
177
|
-
You are listing top #{limit} privacy violations for all packs. See #{documentation_link} for other utilities!
|
178
|
-
Pass in a limit to display more or less, e.g. `bin/packs list_top_privacy_violations #{pack_name} -l 1000`
|
179
|
-
|
180
|
-
This script is intended to help you find which of YOUR pack's private classes, constants, or modules other packs are using the most.
|
181
|
-
Anything not in pack_name/app/public is considered private API.
|
182
|
-
PACK_CONTENT
|
183
|
-
else
|
184
|
-
<<~PACK_CONTENT
|
185
|
-
You are listing top #{limit} privacy violations for #{pack_name}. See #{documentation_link} for other utilities!
|
186
|
-
Pass in a limit to display more or less, e.g. `bin/packs list_top_privacy_violations #{pack_name} -l 1000`
|
164
|
+
You are listing top #{limit} #{type} violations for #{pack_name}. See #{documentation_link} for other utilities!
|
165
|
+
Pass in a limit to display more or less, e.g. `bin/packs list_top_violations #{type} #{pack_name} -l 1000`
|
187
166
|
|
188
167
|
This script is intended to help you find which of YOUR pack's private classes, constants, or modules other packs are using the most.
|
189
168
|
Anything not in #{pack_name}/app/public is considered private API.
|
data/lib/packs.rb
CHANGED
@@ -186,31 +186,18 @@ module Packs
|
|
186
186
|
|
187
187
|
sig do
|
188
188
|
params(
|
189
|
+
type: String,
|
189
190
|
pack_name: T.nilable(String),
|
190
191
|
limit: Integer
|
191
192
|
).void
|
192
193
|
end
|
193
|
-
def self.
|
194
|
+
def self.list_top_violations(
|
195
|
+
type:,
|
194
196
|
pack_name:,
|
195
197
|
limit:
|
196
198
|
)
|
197
|
-
Private::PackRelationshipAnalyzer.
|
198
|
-
|
199
|
-
limit
|
200
|
-
)
|
201
|
-
end
|
202
|
-
|
203
|
-
sig do
|
204
|
-
params(
|
205
|
-
pack_name: T.nilable(String),
|
206
|
-
limit: Integer
|
207
|
-
).void
|
208
|
-
end
|
209
|
-
def self.list_top_dependency_violations(
|
210
|
-
pack_name:,
|
211
|
-
limit:
|
212
|
-
)
|
213
|
-
Private::PackRelationshipAnalyzer.list_top_dependency_violations(
|
199
|
+
Private::PackRelationshipAnalyzer.list_top_violations(
|
200
|
+
type,
|
214
201
|
pack_name,
|
215
202
|
limit
|
216
203
|
)
|
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.29
|
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-
|
11
|
+
date: 2023-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: code_ownership
|