packs 0.0.25 → 0.0.28

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: 6d0b7482840c04ba379ace0bb6b3af72257dee2c3538ed49212b11bc45821b53
4
- data.tar.gz: a0b35ed0dd622f22000a1e472cffa1c3d2b5e87479af1fa2bef2686454203fa9
3
+ metadata.gz: a84d1cf9caf1c2e96c4331060015703cc1383177a3dc77252dfb4a54ec9637e0
4
+ data.tar.gz: 7c2f8e1b763d61dd2f0b1c43c759f857e9a89b1fb53dc1edd7a0fedbf8e3fd69
5
5
  SHA512:
6
- metadata.gz: 4ef79ae43f292f79c70aa3324723a0f3ae3c307207f6f133a4ed3a7caea9b861a18d9dacb96b7c8603582e481f8193eadf71a6aa4d1e28a34fbd7ed20080f110
7
- data.tar.gz: 5c7c2be4ba96f3c8b3bd0bab435735414299e27b1748f31f11427f829c7ee010a9a035872b25a0e6c38259dd5680353e3b1c57b626d5249350a1f63aa1dbff97
6
+ metadata.gz: 69140e0f68acb38d625f969cdd32488d73f25c7edbf05230743c7aae6b836d1f9802dbf4b542171dc596f1f076109e08d12507737f5ff0957fc9d05bf7aeffd6
7
+ data.tar.gz: 7db402b5c133d3a737e74bfa4cb95e4b964272f396015822f74fea7e374da63826da63b18897e82b40f99a96bdfdcdf2d2a86c0efd4da7299768c437e3f975a7
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 dependency violations of packs/your_pack
53
- `bin/packs list_top_dependency_violations packs/your_pack`
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
- Want to see who is depending on you? Not sure how your pack's code is being used in an unstated way
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
- If no pack name is passed in, this will list out violations across all packs.
60
-
61
- ## List the top privacy violations of packs/your_pack
62
- `bin/packs list_top_privacy_violations packs/your_pack`
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.
63
60
 
64
- Want to create interfaces? Not sure how your pack's code is being used?
65
-
66
- You can use this command to list the top privacy violations.
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
 
@@ -100,9 +95,6 @@ Make sure there are no spaces between the comma-separated list of paths of direc
100
95
  ## Get info about size and violations for packs
101
96
  `bin/packs get_info [ packs/my_pack packs/my_other_pack ]`
102
97
 
103
- ## Visualize packs
104
- `bin/packs visualize [ packs/my_pack packs/my_other_pack ]`
105
-
106
98
  ## Rename a pack
107
99
  `bin/packs rename`
108
100
 
data/lib/packs/cli.rb CHANGED
@@ -31,36 +31,31 @@ module Packs
31
31
  exit_successfully
32
32
  end
33
33
 
34
- desc 'list_top_dependency_violations packs/your_pack', 'List the top dependency violations of packs/your_pack'
34
+ POSIBLE_TYPES = T.let(%w[dependency privacy architecture], T::Array[String])
35
+ desc 'list_top_violations type [ packs/your_pack ]', 'List the top violations of a specific type for packs/your_pack.'
35
36
  long_desc <<~LONG_DESC
36
- Want to see who is depending on you? Not sure how your pack's code is being used in an unstated way
37
+ Possible types are: #{POSIBLE_TYPES.join(', ')}.
37
38
 
38
- You can use this command to list the top dependency violations.
39
+ 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.
39
40
 
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
41
+ 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.
51
42
 
52
- desc 'list_top_privacy_violations packs/your_pack', 'List the top privacy violations of packs/your_pack'
53
- long_desc <<~LONG_DESC
54
- Want to create interfaces? Not sure how your pack's code is being used?
55
-
56
- You can use this command to list the top privacy violations.
43
+ Want to focus on the big picture first? You can use this command to list the top architecture violations.
57
44
 
58
45
  If no pack name is passed in, this will list out violations across all packs.
59
46
  LONG_DESC
60
47
  option :limit, type: :numeric, default: 10, aliases: :l, banner: 'Specify the limit of constants to analyze'
61
- sig { params(pack_name: String).void }
62
- def list_top_privacy_violations(pack_name)
63
- Packs.list_top_privacy_violations(
48
+ sig do
49
+ params(
50
+ type: String,
51
+ pack_name: T.nilable(String)
52
+ ).void
53
+ end
54
+ def list_top_violations(type, pack_name = nil)
55
+ raise StandardError, "Invalid type #{type}. Possible types are: #{POSIBLE_TYPES.join(', ')}" unless POSIBLE_TYPES.include?(type)
56
+
57
+ Packs.list_top_violations(
58
+ type: type,
64
59
  pack_name: pack_name,
65
60
  limit: options[:limit]
66
61
  )
@@ -136,13 +131,6 @@ module Packs
136
131
  exit_successfully
137
132
  end
138
133
 
139
- desc 'visualize [ packs/my_pack packs/my_other_pack ]', 'Visualize packs'
140
- sig { params(pack_names: String).void }
141
- def visualize(*pack_names)
142
- Private.visualize(packs: parse_pack_names(pack_names))
143
- exit_successfully
144
- end
145
-
146
134
  desc 'rename', 'Rename a pack'
147
135
  sig { void }
148
136
  def rename
@@ -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 `list_top_dependency_violations` take in an array of things
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
- if selection == 'Dependency'
36
- Packs.list_top_dependency_violations(
37
- pack_name: selected_pack,
38
- limit: limit
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
@@ -19,7 +19,6 @@ require 'packs/private/interactive_cli/use_cases/check'
19
19
  require 'packs/private/interactive_cli/use_cases/update'
20
20
  require 'packs/private/interactive_cli/use_cases/validate'
21
21
  require 'packs/private/interactive_cli/use_cases/lint_package_yml_files'
22
- require 'packs/private/interactive_cli/use_cases/visualize'
23
22
 
24
23
  module Packs
25
24
  module Private
@@ -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.list_top_privacy_violations(pack_name, limit)
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.before_list_top_dependency_violations(pack_name, limit)
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(&:dependency?).each do |violation|
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
@@ -587,11 +587,6 @@ module Packs
587
587
  config.to_a.sort_by { |key, _value| T.unsafe(sort_order).index(key) }.to_h
588
588
  end
589
589
 
590
- sig { params(packs: T::Array[Packs::Pack]).void }
591
- def self.visualize(packs: Packs.all)
592
- VisualizePacks.package_graph!(packs)
593
- end
594
-
595
590
  sig { returns(String) }
596
591
  def self.rename_pack
597
592
  <<~WARNING
@@ -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 list_top_privacy_violations #{pack_name}`
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 before_list_top_dependency_violations(pack_name, limit)
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} dependency 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_dependency_violations #{pack_name} -l 1000`
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} dependency 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_dependency_violations #{pack_name} -l 1000`
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.list_top_privacy_violations(
194
+ def self.list_top_violations(
195
+ type:,
194
196
  pack_name:,
195
197
  limit:
196
198
  )
197
- Private::PackRelationshipAnalyzer.list_top_privacy_violations(
198
- pack_name,
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.25
4
+ version: 0.0.28
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-08-23 00:00:00.000000000 Z
11
+ date: 2023-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: code_ownership
@@ -136,20 +136,6 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
- - !ruby/object:Gem::Dependency
140
- name: visualize_packs
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
145
- version: '0'
146
- type: :runtime
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - ">="
151
- - !ruby/object:Gem::Version
152
- version: '0'
153
139
  - !ruby/object:Gem::Dependency
154
140
  name: bundler
155
141
  requirement: !ruby/object:Gem::Requirement
@@ -343,7 +329,6 @@ files:
343
329
  - lib/packs/private/interactive_cli/use_cases/rename.rb
344
330
  - lib/packs/private/interactive_cli/use_cases/update.rb
345
331
  - lib/packs/private/interactive_cli/use_cases/validate.rb
346
- - lib/packs/private/interactive_cli/use_cases/visualize.rb
347
332
  - lib/packs/private/pack_relationship_analyzer.rb
348
333
  - lib/packs/private/packwerk_wrapper/offenses_aggregator_formatter.rb
349
334
  - lib/packs/rubocop_post_processor.rb
@@ -1,44 +0,0 @@
1
- # typed: strict
2
-
3
- require 'visualize_packs'
4
-
5
- module Packs
6
- module Private
7
- module InteractiveCli
8
- module UseCases
9
- class Visualize
10
- extend T::Sig
11
- extend T::Helpers
12
- include Interface
13
-
14
- sig { override.params(prompt: TTY::Prompt).void }
15
- def perform!(prompt)
16
- teams_or_packs = prompt.select('Do you want the graph nodes to be teams or packs?', %w[Teams Packs])
17
-
18
- if teams_or_packs == 'Teams'
19
- teams = TeamSelector.multi_select(prompt)
20
- VisualizePacks.team_graph!(teams)
21
- else
22
- by_name_or_by_owner = prompt.select('Do you select packs by name or by owner?', ['By name', 'By owner'])
23
- if by_name_or_by_owner == 'By owner'
24
- teams = TeamSelector.multi_select(prompt)
25
- selected_packs = Packs.all.select do |p|
26
- teams.map(&:name).include?(CodeOwnership.for_package(p)&.name)
27
- end
28
- else
29
- selected_packs = PackSelector.single_or_all_pack_multi_select(prompt)
30
- end
31
-
32
- Private.visualize(packs: selected_packs)
33
- end
34
- end
35
-
36
- sig { override.returns(String) }
37
- def user_facing_name
38
- 'Visualize pack relationships'
39
- end
40
- end
41
- end
42
- end
43
- end
44
- end