Skip to content

Commit

Permalink
Adds handler for workspace with no path specified
Browse files Browse the repository at this point in the history
  • Loading branch information
sachin-sandhu committed Jan 27, 2025
1 parent 687c0e5 commit dc1978a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cargo/lib/dependabot/cargo/file_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
19 changes: 19 additions & 0 deletions cargo/spec/dependabot/cargo/file_fetcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
}

0 comments on commit dc1978a

Please sign in to comment.