Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions lib/packs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@
module Packs
extend T::Sig

PERMITTED_PACK_LOCATIONS = T.let(%w[
gems
components
packs
], T::Array[String])

sig { void }
def self.start_interactive_mode!
Private::InteractiveCli.start!
Expand Down
5 changes: 3 additions & 2 deletions lib/packs/private.rb
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,9 @@ def self.add_readme_todo(package)
).returns(ParsePackwerk::Package)
end
def self.create_pack_if_not_exists!(pack_name:, enforce_privacy:, enforce_dependencies:, team: nil)
if PERMITTED_PACK_LOCATIONS.none? { |permitted_location| pack_name.start_with?(permitted_location) }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@naveg Could we change this to check the packs config and ensure that the desired pack path is permitted via the configuration?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. I'll give it a go and update this PR

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

raise StandardError, "Packs only supports packages in the the following directories: #{PERMITTED_PACK_LOCATIONS.inspect}. Please make sure to pass in the name of the pack including the full directory path, e.g. `packs/my_pack`."
allowed_locations = Packs::Specification.config.pack_paths
if allowed_locations.none? { |location| File.fnmatch(location, pack_name) }
raise StandardError, "Packs only supports packages in the the following directories: #{allowed_locations}. Please make sure to pass in the name of the pack including the full directory path, e.g. `packs/my_pack`."
end

existing_package = ParsePackwerk.all.find { |p| p.name == pack_name }
Expand Down
6 changes: 5 additions & 1 deletion spec/packs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def write_codeownership_config

it 'errors' do
expect { Packs.create_pack!(pack_name: 'foo/my_pack') }.to raise_error(
'Packs only supports packages in the the following directories: ["gems", "components", "packs"]. Please make sure to pass in the name of the pack including the full directory path, e.g. `packs/my_pack`.'
'Packs only supports packages in the the following directories: ["packs/*", "packs/*/*"]. Please make sure to pass in the name of the pack including the full directory path, e.g. `packs/my_pack`.'
)
end
end
Expand Down Expand Up @@ -161,6 +161,10 @@ def write_codeownership_config
context 'pack is in gems' do
let(:pack_name) { 'gems/my_pack' }

before do
allow(Packs::Specification.config).to receive(:pack_paths).and_return(['gems/*'])
end

it 'creates the pack' do
Packs.create_pack!(pack_name: 'gems/my_pack')
ParsePackwerk.bust_cache!
Expand Down