Skip to content

Commit

Permalink
feat(cargo): support fetching versions for git crates hosted on github (
Browse files Browse the repository at this point in the history
  • Loading branch information
williamboman committed Aug 19, 2023
1 parent b5bb138 commit e9eb004
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lua/mason-core/installer/registry/providers/cargo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ end
---@async
---@param purl Purl
function M.get_versions(purl)
---@type string?
local repository_url = _.path({ "qualifiers", "repository_url" }, purl)
if repository_url then
---@type Result?
local git_tags = _.cond {
{
_.matches "github.com/(.+)",
_.compose(providers.github.get_all_tags, _.head, _.match "github.com/(.+)"),
},
}(repository_url)
if git_tags then
return git_tags
end
end
return providers.crates.get_all_versions(purl.name)
end

Expand Down
20 changes: 20 additions & 0 deletions tests/mason-core/installer/registry/providers/cargo_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local Purl = require "mason-core.purl"
local Result = require "mason-core.result"
local cargo = require "mason-core.installer.registry.providers.cargo"
local installer = require "mason-core.installer"
local providers = require "mason-core.providers"
local stub = require "luassert.stub"

---@param overrides Purl
Expand Down Expand Up @@ -117,3 +118,22 @@ describe("cargo provider :: installing", function()
})
end)
end)

describe("cargo provider :: versions", function()
it("should recognize github cargo source", function()
stub(providers.github, "get_all_tags", function()
return Result.success { "1.0.0", "2.0.0", "3.0.0" }
end)

local result = cargo.get_versions(purl {
qualifiers = {
repository_url = "https://github.com/rust-lang/rust-analyzer",
},
})

assert.is_true(result:is_success())
assert.same({ "1.0.0", "2.0.0", "3.0.0" }, result:get_or_throw())
assert.spy(providers.github.get_all_tags).was_called(1)
assert.spy(providers.github.get_all_tags).was_called_with "rust-lang/rust-analyzer"
end)
end)

0 comments on commit e9eb004

Please sign in to comment.