From dc1978a11a9b3f71f831888e4dc0e42ce739490e Mon Sep 17 00:00:00 2001 From: sachin-sandhu Date: Fri, 24 Jan 2025 21:16:38 -0500 Subject: [PATCH] Adds handler for workspace with no path specified --- cargo/lib/dependabot/cargo/file_fetcher.rb | 7 ++++++- .../dependabot/cargo/file_fetcher_spec.rb | 19 +++++++++++++++++++ ...cargo_manifest_workspace_with_no_path.json | 18 ++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 cargo/spec/fixtures/github/contents_cargo_manifest_workspace_with_no_path.json diff --git a/cargo/lib/dependabot/cargo/file_fetcher.rb b/cargo/lib/dependabot/cargo/file_fetcher.rb index c178c36f10f..83af9b1f602 100644 --- a/cargo/lib/dependabot/cargo/file_fetcher.rb +++ b/cargo/lib/dependabot/cargo/file_fetcher.rb @@ -359,7 +359,12 @@ def required_path?(file, path) def expand_workspaces(path) path = Pathname.new(path).cleanpath.to_path dir = directory.gsub(%r{(^/|/$)}, "") - unglobbed_path = T.must(path.split("*").first).gsub(%r{(?<=/)[^/]*$}, "") + + unglobbed_path = if path.eql?("*") + String(nil) + else + T.must(path.split("*").first).gsub(%r{(?<=/)[^/]*$}, "") + end repo_contents(dir: unglobbed_path, raise_errors: false) .select { |file| file.type == "dir" } diff --git a/cargo/spec/dependabot/cargo/file_fetcher_spec.rb b/cargo/spec/dependabot/cargo/file_fetcher_spec.rb index 4186f9ca806..0e1a1fb633e 100644 --- a/cargo/spec/dependabot/cargo/file_fetcher_spec.rb +++ b/cargo/spec/dependabot/cargo/file_fetcher_spec.rb @@ -656,6 +656,25 @@ .to eq(["file"]) end end + + context "with a glob that has a wild card '*' but no directory information specified" do + let(:parent_fixture) do + fixture( + "github", + "contents_cargo_manifest_workspace_with_no_path.json" + ) + end + + it "fetches the workspace dependency's Cargo.toml" do + expect(file_fetcher_instance.files.map(&:name)) + .to match_array( + %w(Cargo.toml + .cargo/config.toml) + ) + expect(file_fetcher_instance.files.map(&:type).uniq) + .to eq(["file"]) + end + end end end diff --git a/cargo/spec/fixtures/github/contents_cargo_manifest_workspace_with_no_path.json b/cargo/spec/fixtures/github/contents_cargo_manifest_workspace_with_no_path.json new file mode 100644 index 00000000000..c2fab05a0e3 --- /dev/null +++ b/cargo/spec/fixtures/github/contents_cargo_manifest_workspace_with_no_path.json @@ -0,0 +1,18 @@ +{ + "name": "Cargo.toml", + "path": "Cargo.toml", + "sha": "cb9ddc34d2c13ca51bd54ec7374d89cbad814d78", + "size": 213, + "url": "https://api.github.com/repos/runconduit/conduit/contents/Cargo.toml?ref=master", + "html_url": "https://github.com/runconduit/conduit/blob/master/Cargo.toml", + "git_url": "https://api.github.com/repos/runconduit/conduit/git/blobs/cb9ddc34d2c13ca51bd54ec7374d89cbad814d78", + "download_url": "https://raw.githubusercontent.com/runconduit/conduit/master/Cargo.toml", + "type": "file", + "content": "W3dvcmtzcGFjZV0KbWVtYmVycyA9IFsiLi8qL3N1Yl8qIl0=\n", + "encoding": "base64", + "_links": { + "self": "https://api.github.com/repos/runconduit/conduit/contents/Cargo.toml?ref=master", + "git": "https://api.github.com/repos/runconduit/conduit/git/blobs/cb9ddc34d2c13ca51bd54ec7374d89cbad814d78", + "html": "https://github.com/runconduit/conduit/blob/master/Cargo.toml" + } +}