Skip to content

Commit

Permalink
Incorporate "packs" into use_packs (#72)
Browse files Browse the repository at this point in the history
* Use packs/rspec/support

* bump version

* Change implementation to use packs

* rubocop
  • Loading branch information
Alex Evanczuk authored Dec 29, 2022
1 parent 7ba50d6 commit e311492
Show file tree
Hide file tree
Showing 13 changed files with 158 additions and 64 deletions.
12 changes: 8 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ GIT
PATH
remote: .
specs:
use_packs (0.0.12)
use_packs (0.0.13)
code_ownership
colorize
packs
packwerk
parse_packwerk
rubocop-packs
Expand Down Expand Up @@ -52,9 +53,9 @@ GEM
smart_properties
builder (3.2.4)
byebug (11.1.3)
code_ownership (1.29.1)
code_ownership (1.29.2)
code_teams (~> 1.0)
parse_packwerk
packs
sorbet-runtime
code_teams (1.0.0)
sorbet-runtime
Expand All @@ -77,6 +78,8 @@ GEM
nokogiri (1.13.10)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
packs (0.0.5)
sorbet-runtime
parallel (1.22.1)
parse_packwerk (0.18.0)
sorbet-runtime
Expand Down Expand Up @@ -130,8 +133,9 @@ GEM
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.21.0)
parser (>= 3.1.1.0)
rubocop-packs (0.0.32)
rubocop-packs (0.0.33)
activesupport
packs
parse_packwerk
rubocop
rubocop-sorbet
Expand Down
17 changes: 10 additions & 7 deletions lib/use_packs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,16 +282,19 @@ def self.lint_package_todo_yml_files!
end
end

sig { params(packs: T::Array[ParsePackwerk::Package]).void }
sig { params(packs: T::Array[Packs::Pack]).void }
def self.lint_package_yml_files!(packs)
packs.each do |p|
packwerk_package = ParsePackwerk.find(p.name)
next if packwerk_package.nil?

new_package = ParsePackwerk::Package.new(
name: p.name,
enforce_privacy: p.enforce_privacy,
enforce_dependencies: p.enforce_dependencies,
dependencies: p.dependencies.uniq.sort,
metadata: p.metadata,
config: p.config
name: packwerk_package.name,
enforce_privacy: packwerk_package.enforce_privacy,
enforce_dependencies: packwerk_package.enforce_dependencies,
dependencies: packwerk_package.dependencies.uniq.sort,
metadata: packwerk_package.metadata,
config: packwerk_package.config
)
ParsePackwerk.write_package_yml!(new_package)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/use_packs/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ def regenerate_rubocop_todo(*pack_names)

# This is used by thor to know that these private methods are not intended to be CLI commands
no_commands do
sig { params(pack_names: T::Array[String]).returns(T::Array[ParsePackwerk::Package]) }
sig { params(pack_names: T::Array[String]).returns(T::Array[Packs::Pack]) }
def parse_pack_names(pack_names)
pack_names.empty? ? ParsePackwerk.all : pack_names.map { |p| ParsePackwerk.find(p.gsub(%r{/$}, '')) }.compact
pack_names.empty? ? Packs.all : pack_names.map { |p| Packs.find(p.gsub(%r{/$}, '')) }.compact
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/use_packs/code_ownership_post_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def before_move_file!(file_move_operation)
@teams << 'Unknown'
end

if !CodeOwnership.for_package(file_move_operation.destination_pack).nil?
pack = Packs.find(file_move_operation.destination_pack.name)
if pack && !CodeOwnership.for_package(pack).nil?
CodeOwnership.remove_file_annotation!(relative_path_to_origin.to_s)
@did_move_files = true
end
Expand Down
19 changes: 18 additions & 1 deletion lib/use_packs/private.rb
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,8 @@ def self.create_pack_if_not_exists!(pack_name:, enforce_privacy:, enforce_depend
)

ParsePackwerk.write_package_yml!(package)
RuboCop::Packs.set_default_rubocop_yml(packs: [package])
pack = Packs.find(package.name)
RuboCop::Packs.set_default_rubocop_yml(packs: [pack].compact)

current_contents = package.yml.read
new_contents = current_contents.gsub('MyTeam', 'MyTeam # specify your team here, or delete this key if this package is not owned by one team')
Expand Down Expand Up @@ -452,6 +453,22 @@ def self.write_package_todo_to_tmp_folder(package_todo_files, tmp_folder)
temp_package_todo_yml.write(contents)
end
end

sig { params(packages: T::Array[ParsePackwerk::Package]).returns(T::Array[Packs::Pack]) }
def self.packwerk_packages_to_packs(packages)
packs = []
packages.each do |package|
pack = Packs.find(package.name)
packs << pack if !pack.nil?
end

packs
end

sig { params(package: ParsePackwerk::Package).returns(T.nilable(Packs::Pack)) }
def self.packwerk_package_to_pack(package)
Packs.find(package.name)
end
end

private_constant :Private
Expand Down
12 changes: 6 additions & 6 deletions lib/use_packs/private/interactive_cli/pack_selector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ module InteractiveCli
class PackSelector
extend T::Sig

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

pack_selection = T.let(prompt.select(
question_text,
packs,
filter: true,
per_page: 10,
show_help: :always
), T.nilable(ParsePackwerk::Package))
), T.nilable(Packs::Pack))

while pack_selection.nil?
prompt.error(
Expand All @@ -29,15 +29,15 @@ def self.single_pack_select(prompt, question_text: 'Please use space to select a
pack_selection
end

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

while pack_selection.empty?
prompt.error(
Expand Down
9 changes: 5 additions & 4 deletions lib/use_packs/private/interactive_cli/use_cases/get_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def perform!(prompt)

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

selected_packs.sort_by { |p| -p.directory.glob('**/*.rb').count }.each do |pack|
selected_packs.sort_by { |p| -p.relative_path.glob('**/*.rb').count }.each do |pack|
puts "\n=========== Info about: #{pack.name}"

owner = CodeOwnership.for_package(pack)
puts "Owned by: #{owner.nil? ? 'No one' : owner.name}"
puts "Size: #{pack.directory.glob('**/*.rb').count} ruby files"
puts "Public API: #{pack.directory.join('app/public')}"
puts "Size: #{pack.relative_path.glob('**/*.rb').count} ruby files"
puts "Public API: #{pack.relative_path.join('app/public')}"

inbound_for_pack = inbound_violations[pack.name] || []
outbound_for_pack = outbound_violations[pack.name] || []
Expand Down
7 changes: 5 additions & 2 deletions lib/use_packs/private/interactive_cli/use_cases/visualize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ def perform!(prompt)
by_name_or_by_owner = prompt.select('Do you select packs by name or by owner?', ['By name', 'By owner'])
if by_name_or_by_owner == 'By owner'
teams = TeamSelector.multi_select(prompt)
selected_packs = ParsePackwerk.all.select do |p|
selected_packs = Packs.all.select do |p|
teams.map(&:name).include?(CodeOwnership.for_package(p)&.name)
end
else
selected_packs = PackSelector.single_or_all_pack_multi_select(prompt)
end

VisualizePackwerk.package_graph!(selected_packs)
packwerk_packages = selected_packs.map do |pack|
T.must(ParsePackwerk.find(pack.name))
end
VisualizePackwerk.package_graph!(packwerk_packages)
end
end

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 84 additions & 0 deletions sorbet/rbi/gems/[email protected]

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e311492

Please sign in to comment.