diff options
| author | William Boman <william@redwill.se> | 2023-08-19 08:31:07 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-19 08:31:07 +0200 |
| commit | e9eb0048cecc577a1eec534485d3e010487b46a7 (patch) | |
| tree | 2c2ccc7015dc6c7f0d79b3a39d5d14c9e64992a9 | |
| parent | chore(async): add Channel (#1456) (diff) | |
| download | mason-e9eb0048cecc577a1eec534485d3e010487b46a7.tar mason-e9eb0048cecc577a1eec534485d3e010487b46a7.tar.gz mason-e9eb0048cecc577a1eec534485d3e010487b46a7.tar.bz2 mason-e9eb0048cecc577a1eec534485d3e010487b46a7.tar.lz mason-e9eb0048cecc577a1eec534485d3e010487b46a7.tar.xz mason-e9eb0048cecc577a1eec534485d3e010487b46a7.tar.zst mason-e9eb0048cecc577a1eec534485d3e010487b46a7.zip | |
feat(cargo): support fetching versions for git crates hosted on github (#1459)
| -rw-r--r-- | lua/mason-core/installer/registry/providers/cargo.lua | 14 | ||||
| -rw-r--r-- | tests/mason-core/installer/registry/providers/cargo_spec.lua | 20 |
2 files changed, 34 insertions, 0 deletions
diff --git a/lua/mason-core/installer/registry/providers/cargo.lua b/lua/mason-core/installer/registry/providers/cargo.lua index 312a2938..af43db86 100644 --- a/lua/mason-core/installer/registry/providers/cargo.lua +++ b/lua/mason-core/installer/registry/providers/cargo.lua @@ -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 diff --git a/tests/mason-core/installer/registry/providers/cargo_spec.lua b/tests/mason-core/installer/registry/providers/cargo_spec.lua index 674164c2..d3468909 100644 --- a/tests/mason-core/installer/registry/providers/cargo_spec.lua +++ b/tests/mason-core/installer/registry/providers/cargo_spec.lua @@ -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 @@ -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) |
