Skip to content

Commit

Permalink
Support to_import with partial matches
Browse files Browse the repository at this point in the history
  • Loading branch information
azimux committed Apr 30, 2024
1 parent e18a4bb commit c58252e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
14 changes: 7 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GIT
remote: foobara
revision: 9d258143cf0a58a3bd7a63c89443dff0fc45ef14
revision: 76232e8f44a65cc6267fc43f82cdd1ccfe6f7f67
branch: main
specs:
foobara (0.0.1)
Expand Down Expand Up @@ -38,7 +38,7 @@ GIT

GIT
remote: https://github.com/foobara/foob.git
revision: f54b66cfe5ab557d556e56b846e3ed079eca9f79
revision: 32e226216f04c02c285add2869774b1d40203c86
specs:
foobara-foob (0.0.1)

Expand All @@ -58,7 +58,7 @@ GIT

GIT
remote: https://github.com/foobara/sh-cli-connector.git
revision: caf838a83c38501ca8d6e1181f103c2bbabd3fd3
revision: b08ff244e38ea10e01d36d07adb48937fe1998ca
specs:
foobara-sh-cli-connector (0.1.0)

Expand Down Expand Up @@ -93,7 +93,7 @@ GEM
rexml
diff-lcs (1.5.1)
docile (1.4.0)
dotenv (3.1.0)
dotenv (3.1.1)
ffi (1.16.3)
formatador (1.1.0)
guard (2.18.1)
Expand Down Expand Up @@ -157,7 +157,7 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.1)
rubocop (1.63.3)
rubocop (1.63.4)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
Expand All @@ -168,8 +168,8 @@ GEM
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.2)
parser (>= 3.3.0.4)
rubocop-ast (1.31.3)
parser (>= 3.3.1.0)
rubocop-capybara (2.20.0)
rubocop (~> 1.41)
rubocop-factory_bot (2.25.1)
Expand Down
13 changes: 13 additions & 0 deletions spec/foobara/remote_imports/import_command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@
expect(SomeOrg::Math).to be_foobara_domain
end

context "when using a partial match" do
let(:to_import) { "CreateNestedNoCollisions" }

it "creates the command" do
expect(outcome).to be_success

expect(result.size).to eq(1)
command = result.first
expect(command).to be < Foobara::Command
expect(command).to eq(NestedModelsNoCollisions::CreateNestedNoCollisions)
end
end

context "when creating all commands" do
let(:inputs) do
{
Expand Down
20 changes: 19 additions & 1 deletion src/foobara/remote_imports/import_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,27 @@ def load_manifest_from_url
def filter_manifests_to_import
return if to_import.nil? || to_import.empty?

references = manifests_to_import.map(&:reference)

filter = Util.array(to_import)

not_found = filter - manifests_to_import.map(&:reference)
filter.map! do |name|
if references.include?(name)
name
else
suffix = "::#{name}"

partial_matches = references.select { |reference| reference.end_with?(suffix) }

if partial_matches.size == 1
partial_matches.first
else
name
end
end
end

not_found = filter - references

if not_found.any?
add_input_error :to_import, :not_found, "Could not find #{not_found}", not_found:
Expand Down

0 comments on commit c58252e

Please sign in to comment.