Skip to content

Commit e311492

Browse files
author
Alex Evanczuk
authored
Incorporate "packs" into use_packs (#72)
* Use packs/rspec/support * bump version * Change implementation to use packs * rubocop
1 parent 7ba50d6 commit e311492

File tree

13 files changed

+158
-64
lines changed

13 files changed

+158
-64
lines changed

Gemfile.lock

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ GIT
1717
PATH
1818
remote: .
1919
specs:
20-
use_packs (0.0.12)
20+
use_packs (0.0.13)
2121
code_ownership
2222
colorize
23+
packs
2324
packwerk
2425
parse_packwerk
2526
rubocop-packs
@@ -52,9 +53,9 @@ GEM
5253
smart_properties
5354
builder (3.2.4)
5455
byebug (11.1.3)
55-
code_ownership (1.29.1)
56+
code_ownership (1.29.2)
5657
code_teams (~> 1.0)
57-
parse_packwerk
58+
packs
5859
sorbet-runtime
5960
code_teams (1.0.0)
6061
sorbet-runtime
@@ -77,6 +78,8 @@ GEM
7778
nokogiri (1.13.10)
7879
mini_portile2 (~> 2.8.0)
7980
racc (~> 1.4)
81+
packs (0.0.5)
82+
sorbet-runtime
8083
parallel (1.22.1)
8184
parse_packwerk (0.18.0)
8285
sorbet-runtime
@@ -130,8 +133,9 @@ GEM
130133
unicode-display_width (>= 1.4.0, < 3.0)
131134
rubocop-ast (1.21.0)
132135
parser (>= 3.1.1.0)
133-
rubocop-packs (0.0.32)
136+
rubocop-packs (0.0.33)
134137
activesupport
138+
packs
135139
parse_packwerk
136140
rubocop
137141
rubocop-sorbet

lib/use_packs.rb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -282,16 +282,19 @@ def self.lint_package_todo_yml_files!
282282
end
283283
end
284284

285-
sig { params(packs: T::Array[ParsePackwerk::Package]).void }
285+
sig { params(packs: T::Array[Packs::Pack]).void }
286286
def self.lint_package_yml_files!(packs)
287287
packs.each do |p|
288+
packwerk_package = ParsePackwerk.find(p.name)
289+
next if packwerk_package.nil?
290+
288291
new_package = ParsePackwerk::Package.new(
289-
name: p.name,
290-
enforce_privacy: p.enforce_privacy,
291-
enforce_dependencies: p.enforce_dependencies,
292-
dependencies: p.dependencies.uniq.sort,
293-
metadata: p.metadata,
294-
config: p.config
292+
name: packwerk_package.name,
293+
enforce_privacy: packwerk_package.enforce_privacy,
294+
enforce_dependencies: packwerk_package.enforce_dependencies,
295+
dependencies: packwerk_package.dependencies.uniq.sort,
296+
metadata: packwerk_package.metadata,
297+
config: packwerk_package.config
295298
)
296299
ParsePackwerk.write_package_yml!(new_package)
297300
end

lib/use_packs/cli.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ def regenerate_rubocop_todo(*pack_names)
118118

119119
# This is used by thor to know that these private methods are not intended to be CLI commands
120120
no_commands do
121-
sig { params(pack_names: T::Array[String]).returns(T::Array[ParsePackwerk::Package]) }
121+
sig { params(pack_names: T::Array[String]).returns(T::Array[Packs::Pack]) }
122122
def parse_pack_names(pack_names)
123-
pack_names.empty? ? ParsePackwerk.all : pack_names.map { |p| ParsePackwerk.find(p.gsub(%r{/$}, '')) }.compact
123+
pack_names.empty? ? Packs.all : pack_names.map { |p| Packs.find(p.gsub(%r{/$}, '')) }.compact
124124
end
125125
end
126126
end

lib/use_packs/code_ownership_post_processor.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ def before_move_file!(file_move_operation)
3434
@teams << 'Unknown'
3535
end
3636

37-
if !CodeOwnership.for_package(file_move_operation.destination_pack).nil?
37+
pack = Packs.find(file_move_operation.destination_pack.name)
38+
if pack && !CodeOwnership.for_package(pack).nil?
3839
CodeOwnership.remove_file_annotation!(relative_path_to_origin.to_s)
3940
@did_move_files = true
4041
end

lib/use_packs/private.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,8 @@ def self.create_pack_if_not_exists!(pack_name:, enforce_privacy:, enforce_depend
378378
)
379379

380380
ParsePackwerk.write_package_yml!(package)
381-
RuboCop::Packs.set_default_rubocop_yml(packs: [package])
381+
pack = Packs.find(package.name)
382+
RuboCop::Packs.set_default_rubocop_yml(packs: [pack].compact)
382383

383384
current_contents = package.yml.read
384385
new_contents = current_contents.gsub('MyTeam', 'MyTeam # specify your team here, or delete this key if this package is not owned by one team')
@@ -452,6 +453,22 @@ def self.write_package_todo_to_tmp_folder(package_todo_files, tmp_folder)
452453
temp_package_todo_yml.write(contents)
453454
end
454455
end
456+
457+
sig { params(packages: T::Array[ParsePackwerk::Package]).returns(T::Array[Packs::Pack]) }
458+
def self.packwerk_packages_to_packs(packages)
459+
packs = []
460+
packages.each do |package|
461+
pack = Packs.find(package.name)
462+
packs << pack if !pack.nil?
463+
end
464+
465+
packs
466+
end
467+
468+
sig { params(package: ParsePackwerk::Package).returns(T.nilable(Packs::Pack)) }
469+
def self.packwerk_package_to_pack(package)
470+
Packs.find(package.name)
471+
end
455472
end
456473

457474
private_constant :Private

lib/use_packs/private/interactive_cli/pack_selector.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ module InteractiveCli
66
class PackSelector
77
extend T::Sig
88

9-
sig { params(prompt: TTY::Prompt, question_text: String).returns(ParsePackwerk::Package) }
9+
sig { params(prompt: TTY::Prompt, question_text: String).returns(Packs::Pack) }
1010
def self.single_pack_select(prompt, question_text: 'Please use space to select a pack')
11-
packs = ParsePackwerk.all.to_h { |t| [t.name, t] }
11+
packs = Packs.all.to_h { |t| [t.name, t] }
1212

1313
pack_selection = T.let(prompt.select(
1414
question_text,
1515
packs,
1616
filter: true,
1717
per_page: 10,
1818
show_help: :always
19-
), T.nilable(ParsePackwerk::Package))
19+
), T.nilable(Packs::Pack))
2020

2121
while pack_selection.nil?
2222
prompt.error(
@@ -29,15 +29,15 @@ def self.single_pack_select(prompt, question_text: 'Please use space to select a
2929
pack_selection
3030
end
3131

32-
sig { params(prompt: TTY::Prompt, question_text: String).returns(T::Array[ParsePackwerk::Package]) }
32+
sig { params(prompt: TTY::Prompt, question_text: String).returns(T::Array[Packs::Pack]) }
3333
def self.single_or_all_pack_multi_select(prompt, question_text: 'Please use space to select one or more packs')
3434
pack_selection = T.let(prompt.multi_select(
3535
question_text,
36-
ParsePackwerk.all.to_h { |t| [t.name, t] },
36+
Packs.all.to_h { |t| [t.name, t] },
3737
filter: true,
3838
per_page: 10,
3939
show_help: :always
40-
), T::Array[ParsePackwerk::Package])
40+
), T::Array[Packs::Pack])
4141

4242
while pack_selection.empty?
4343
prompt.error(

lib/use_packs/private/interactive_cli/use_cases/get_info.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def perform!(prompt)
2020

2121
if team_or_pack == 'By team'
2222
teams = TeamSelector.multi_select(prompt)
23-
selected_packs = ParsePackwerk.all.select do |p|
23+
selected_packs = Packs.all.select do |p|
2424
teams.map(&:name).include?(CodeOwnership.for_package(p)&.name)
2525
end
2626
else
@@ -51,12 +51,13 @@ def perform!(prompt)
5151
puts "There are #{all_outbound.select(&:privacy?).sum { |v| v.files.count }} total outbound privacy violations"
5252
puts "There are #{all_outbound.select(&:dependency?).sum { |v| v.files.count }} total outbound dependency violations"
5353

54-
selected_packs.sort_by { |p| -p.directory.glob('**/*.rb').count }.each do |pack|
54+
selected_packs.sort_by { |p| -p.relative_path.glob('**/*.rb').count }.each do |pack|
5555
puts "\n=========== Info about: #{pack.name}"
56+
5657
owner = CodeOwnership.for_package(pack)
5758
puts "Owned by: #{owner.nil? ? 'No one' : owner.name}"
58-
puts "Size: #{pack.directory.glob('**/*.rb').count} ruby files"
59-
puts "Public API: #{pack.directory.join('app/public')}"
59+
puts "Size: #{pack.relative_path.glob('**/*.rb').count} ruby files"
60+
puts "Public API: #{pack.relative_path.join('app/public')}"
6061

6162
inbound_for_pack = inbound_violations[pack.name] || []
6263
outbound_for_pack = outbound_violations[pack.name] || []

lib/use_packs/private/interactive_cli/use_cases/visualize.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@ def perform!(prompt)
2222
by_name_or_by_owner = prompt.select('Do you select packs by name or by owner?', ['By name', 'By owner'])
2323
if by_name_or_by_owner == 'By owner'
2424
teams = TeamSelector.multi_select(prompt)
25-
selected_packs = ParsePackwerk.all.select do |p|
25+
selected_packs = Packs.all.select do |p|
2626
teams.map(&:name).include?(CodeOwnership.for_package(p)&.name)
2727
end
2828
else
2929
selected_packs = PackSelector.single_or_all_pack_multi_select(prompt)
3030
end
3131

32-
VisualizePackwerk.package_graph!(selected_packs)
32+
packwerk_packages = selected_packs.map do |pack|
33+
T.must(ParsePackwerk.find(pack.name))
34+
end
35+
VisualizePackwerk.package_graph!(packwerk_packages)
3336
end
3437
end
3538

Lines changed: 6 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sorbet/rbi/gems/[email protected]

Lines changed: 84 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)