use_packs 0.0.12 → 0.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5f98eb76891cbb942fb3d546c0b8a8aa15be6a8cd6068b84717e808a66a7fc55
4
- data.tar.gz: 967fe01ab77ca126919f70b92d578eb479a290c3d858bcfff502dd4c333a5c25
3
+ metadata.gz: fb4b5cfe33a3c5881971d27c78fefe591378e9728baf6513beffc14058ef23d6
4
+ data.tar.gz: 15144da46c38e628af6bfc3c5243d8d0c42a46b2fa739b66339fb120e31c6d36
5
5
  SHA512:
6
- metadata.gz: c0997685aee1f0f5be74164cce68fe0517c73f3635619696ddd1e4a0bc1b4be1c5143882ba3888bd5661d767ebc5f856bc29de516f621fe0d45f5a4ab28d91a9
7
- data.tar.gz: d6031d17ba30549dd813e240aa558330ad0e0233c6ec5437ecd215b26f9d09a1c79b658262fa74457e5b9985d8aa7bdf3c2f9065787e81d87ffd43b5006a12e1
6
+ metadata.gz: ce3dbd0c9c3b103887e0ff3e84421396cc3e711b4cac3626e34e622d403ab806eb63ec50e3bb4daf64b647d7f991d940e5973e60cd28e1a8b1a4880635be2525
7
+ data.tar.gz: 9f38e2e00c87dc857a279a726bd7539d5344a0a51dbd5acfeac4153194dcaef5bcab1e577c9a11417963602f652d7559e33a9dba5a77f6372bec066e8ac058c2
data/README.md CHANGED
@@ -50,16 +50,16 @@ Releases happen automatically through github actions once a version update is co
50
50
  To keep things organized, here are some recommended homes:
51
51
 
52
52
  ### Issues:
53
- https://github.com/Gusto/use_packs/issues
53
+ https://github.com/rubyatscale/use_packs/issues
54
54
 
55
55
  ### Questions:
56
- https://github.com/Gusto/use_packs/discussions/categories/q-a
56
+ https://github.com/rubyatscale/use_packs/discussions/categories/q-a
57
57
 
58
58
  ### General discussions:
59
- https://github.com/Gusto/use_packs/discussions/categories/general
59
+ https://github.com/rubyatscale/use_packs/discussions/categories/general
60
60
 
61
61
  ### Ideas, new features, requests for change:
62
- https://github.com/Gusto/use_packs/discussions/categories/ideas
62
+ https://github.com/rubyatscale/use_packs/discussions/categories/ideas
63
63
 
64
64
  ### Showcasing your work:
65
- https://github.com/Gusto/use_packs/discussions/categories/show-and-tell
65
+ https://github.com/rubyatscale/use_packs/discussions/categories/show-and-tell
data/lib/use_packs/cli.rb CHANGED
@@ -118,9 +118,9 @@ module UsePacks
118
118
 
119
119
  # This is used by thor to know that these private methods are not intended to be CLI commands
120
120
  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]) }
122
122
  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
124
124
  end
125
125
  end
126
126
  end
@@ -17,14 +17,13 @@ module UsePacks
17
17
  relative_path_to_destination = file_move_operation.destination_pathname
18
18
 
19
19
  code_owners_allow_list_file = Pathname.new('config/code_ownership.yml')
20
+ return if !code_owners_allow_list_file.exist?
20
21
 
21
- if code_owners_allow_list_file.exist?
22
- UsePacks.replace_in_file(
23
- file: code_owners_allow_list_file.to_s,
24
- find: relative_path_to_origin,
25
- replace_with: relative_path_to_destination
26
- )
27
- end
22
+ UsePacks.replace_in_file(
23
+ file: code_owners_allow_list_file.to_s,
24
+ find: relative_path_to_origin,
25
+ replace_with: relative_path_to_destination
26
+ )
28
27
 
29
28
  team = CodeOwnership.for_file(relative_path_to_origin.to_s)
30
29
 
@@ -34,7 +33,8 @@ module UsePacks
34
33
  @teams << 'Unknown'
35
34
  end
36
35
 
37
- if !CodeOwnership.for_package(file_move_operation.destination_pack).nil?
36
+ pack = Packs.find(file_move_operation.destination_pack.name)
37
+ if pack && !CodeOwnership.for_package(pack).nil?
38
38
  CodeOwnership.remove_file_annotation!(relative_path_to_origin.to_s)
39
39
  @did_move_files = true
40
40
  end
@@ -6,9 +6,9 @@ module UsePacks
6
6
  class PackSelector
7
7
  extend T::Sig
8
8
 
9
- sig { params(prompt: TTY::Prompt, question_text: String).returns(ParsePackwerk::Package) }
9
+ sig { params(prompt: TTY::Prompt, question_text: String).returns(Packs::Pack) }
10
10
  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] }
12
12
 
13
13
  pack_selection = T.let(prompt.select(
14
14
  question_text,
@@ -16,7 +16,7 @@ module UsePacks
16
16
  filter: true,
17
17
  per_page: 10,
18
18
  show_help: :always
19
- ), T.nilable(ParsePackwerk::Package))
19
+ ), T.nilable(Packs::Pack))
20
20
 
21
21
  while pack_selection.nil?
22
22
  prompt.error(
@@ -29,15 +29,15 @@ module UsePacks
29
29
  pack_selection
30
30
  end
31
31
 
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]) }
33
33
  def self.single_or_all_pack_multi_select(prompt, question_text: 'Please use space to select one or more packs')
34
34
  pack_selection = T.let(prompt.multi_select(
35
35
  question_text,
36
- ParsePackwerk.all.to_h { |t| [t.name, t] },
36
+ Packs.all.to_h { |t| [t.name, t] },
37
37
  filter: true,
38
38
  per_page: 10,
39
39
  show_help: :always
40
- ), T::Array[ParsePackwerk::Package])
40
+ ), T::Array[Packs::Pack])
41
41
 
42
42
  while pack_selection.empty?
43
43
  prompt.error(
@@ -6,9 +6,10 @@ module UsePacks
6
6
  class TeamSelector
7
7
  extend T::Sig
8
8
 
9
- sig { params(prompt: TTY::Prompt, question_text: String).returns(CodeTeams::Team) }
9
+ sig { params(prompt: TTY::Prompt, question_text: String).returns(T.nilable(CodeTeams::Team)) }
10
10
  def self.single_select(prompt, question_text: 'Please use space to select a team owner')
11
11
  teams = CodeTeams.all.sort_by(&:name).to_h { |t| [t.name, t] }
12
+ return nil if teams.count == 0
12
13
 
13
14
  team_selection = T.let(prompt.select(
14
15
  question_text,
@@ -20,7 +20,7 @@ module UsePacks
20
20
 
21
21
  if team_or_pack == 'By team'
22
22
  teams = TeamSelector.multi_select(prompt)
23
- selected_packs = ParsePackwerk.all.select do |p|
23
+ selected_packs = Packs.all.select do |p|
24
24
  teams.map(&:name).include?(CodeOwnership.for_package(p)&.name)
25
25
  end
26
26
  else
@@ -51,12 +51,13 @@ module UsePacks
51
51
  puts "There are #{all_outbound.select(&:privacy?).sum { |v| v.files.count }} total outbound privacy violations"
52
52
  puts "There are #{all_outbound.select(&:dependency?).sum { |v| v.files.count }} total outbound dependency violations"
53
53
 
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|
55
55
  puts "\n=========== Info about: #{pack.name}"
56
+
56
57
  owner = CodeOwnership.for_package(pack)
57
58
  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')}"
60
61
 
61
62
  inbound_for_pack = inbound_violations[pack.name] || []
62
63
  outbound_for_pack = outbound_violations[pack.name] || []
@@ -22,14 +22,17 @@ module UsePacks
22
22
  by_name_or_by_owner = prompt.select('Do you select packs by name or by owner?', ['By name', 'By owner'])
23
23
  if by_name_or_by_owner == 'By owner'
24
24
  teams = TeamSelector.multi_select(prompt)
25
- selected_packs = ParsePackwerk.all.select do |p|
25
+ selected_packs = Packs.all.select do |p|
26
26
  teams.map(&:name).include?(CodeOwnership.for_package(p)&.name)
27
27
  end
28
28
  else
29
29
  selected_packs = PackSelector.single_or_all_pack_multi_select(prompt)
30
30
  end
31
31
 
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)
33
36
  end
34
37
  end
35
38
 
@@ -366,19 +366,28 @@ module UsePacks
366
366
  if existing_package.nil?
367
367
  should_enforce_dependenceies = enforce_dependencies.nil? ? UsePacks.config.enforce_dependencies : enforce_dependencies
368
368
 
369
+ # TODO: This should probably be `if defined?(CodeOwnership) && CodeOwnership.configured?`
370
+ # but we'll need to add an API to CodeOwnership to do this
371
+ if Pathname.new('config/code_ownership.yml').exist?
372
+ metadata = {
373
+ 'owner' => team.nil? ? 'MyTeam' : team.name
374
+ }
375
+ else
376
+ metadata = {}
377
+ end
378
+
369
379
  package = ParsePackwerk::Package.new(
370
380
  enforce_dependencies: should_enforce_dependenceies,
371
381
  enforce_privacy: enforce_privacy,
372
382
  dependencies: [],
373
- metadata: {
374
- 'owner' => team.nil? ? 'MyTeam' : team.name
375
- },
383
+ metadata: metadata,
376
384
  name: pack_name,
377
385
  config: {}
378
386
  )
379
387
 
380
388
  ParsePackwerk.write_package_yml!(package)
381
- RuboCop::Packs.set_default_rubocop_yml(packs: [package])
389
+ pack = Packs.find(package.name)
390
+ RuboCop::Packs.set_default_rubocop_yml(packs: [pack].compact)
382
391
 
383
392
  current_contents = package.yml.read
384
393
  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 +461,22 @@ module UsePacks
452
461
  temp_package_todo_yml.write(contents)
453
462
  end
454
463
  end
464
+
465
+ sig { params(packages: T::Array[ParsePackwerk::Package]).returns(T::Array[Packs::Pack]) }
466
+ def self.packwerk_packages_to_packs(packages)
467
+ packs = []
468
+ packages.each do |package|
469
+ pack = Packs.find(package.name)
470
+ packs << pack if !pack.nil?
471
+ end
472
+
473
+ packs
474
+ end
475
+
476
+ sig { params(package: ParsePackwerk::Package).returns(T.nilable(Packs::Pack)) }
477
+ def self.packwerk_package_to_pack(package)
478
+ Packs.find(package.name)
479
+ end
455
480
  end
456
481
 
457
482
  private_constant :Private
data/lib/use_packs.rb CHANGED
@@ -282,16 +282,19 @@ module UsePacks
282
282
  end
283
283
  end
284
284
 
285
- sig { params(packs: T::Array[ParsePackwerk::Package]).void }
285
+ sig { params(packs: T::Array[Packs::Pack]).void }
286
286
  def self.lint_package_yml_files!(packs)
287
287
  packs.each do |p|
288
+ packwerk_package = ParsePackwerk.find(p.name)
289
+ next if packwerk_package.nil?
290
+
288
291
  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
295
298
  )
296
299
  ParsePackwerk.write_package_yml!(new_package)
297
300
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: use_packs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gusto Engineers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-27 00:00:00.000000000 Z
11
+ date: 2023-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: code_ownership
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: packs
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: packwerk
43
57
  requirement: !ruby/object:Gem::Requirement