aboutsummaryrefslogtreecommitdiffstats
path: root/lua/nvim-lsp-installer/core
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-05-01 15:02:43 +0200
committerGitHub <noreply@github.com>2022-05-01 15:02:43 +0200
commit52d8f78fd1c1657f58115adc1928763571ffc7fa (patch)
tree0eb4ab1657980b7fc425c75d3d1920e5a345d545 /lua/nvim-lsp-installer/core
parentfeat: allow excluding servers from automatic installation (#643) (diff)
downloadmason-52d8f78fd1c1657f58115adc1928763571ffc7fa.tar
mason-52d8f78fd1c1657f58115adc1928763571ffc7fa.tar.gz
mason-52d8f78fd1c1657f58115adc1928763571ffc7fa.tar.bz2
mason-52d8f78fd1c1657f58115adc1928763571ffc7fa.tar.lz
mason-52d8f78fd1c1657f58115adc1928763571ffc7fa.tar.xz
mason-52d8f78fd1c1657f58115adc1928763571ffc7fa.tar.zst
mason-52d8f78fd1c1657f58115adc1928763571ffc7fa.zip
feat(receipt): add "github_release" type (#650)
This is for sources that uses GitHub releases, but doesn't target a specific asset file (as opposed to the github_release_file source).
Diffstat (limited to 'lua/nvim-lsp-installer/core')
-rw-r--r--lua/nvim-lsp-installer/core/managers/github/init.lua45
-rw-r--r--lua/nvim-lsp-installer/core/receipt.lua22
2 files changed, 46 insertions, 21 deletions
diff --git a/lua/nvim-lsp-installer/core/managers/github/init.lua b/lua/nvim-lsp-installer/core/managers/github/init.lua
index cb19ad2e..107bc94d 100644
--- a/lua/nvim-lsp-installer/core/managers/github/init.lua
+++ b/lua/nvim-lsp-installer/core/managers/github/init.lua
@@ -2,6 +2,7 @@ local installer = require "nvim-lsp-installer.core.installer"
local std = require "nvim-lsp-installer.core.managers.std"
local client = require "nvim-lsp-installer.core.managers.github.client"
local platform = require "nvim-lsp-installer.platform"
+local Result = require "nvim-lsp-installer.core.result"
local M = {}
@@ -84,4 +85,48 @@ function M.gunzip_release_file(opts)
return release_file_source
end
+---@async
+---@param receipt InstallReceipt
+function M.check_outdated_primary_package_release(receipt)
+ local source = receipt.primary_source
+ if source.type ~= "github_release" and source.type ~= "github_release_file" then
+ return Result.failure "Receipt does not have a primary source of type (github_release|github_release_file)."
+ end
+ return client.fetch_latest_release(source.repo, { tag_name_pattern = source.tag_name_pattern }):map_catching(
+ ---@param latest_release GitHubRelease
+ function(latest_release)
+ if source.release ~= latest_release.tag_name then
+ return {
+ name = source.repo,
+ current_version = source.release,
+ latest_version = latest_release.tag_name,
+ }
+ end
+ error "Primary package is not outdated."
+ end
+ )
+end
+
+---@async
+---@param receipt InstallReceipt
+function M.check_outdated_primary_package_tag(receipt)
+ local source = receipt.primary_source
+ if source.type ~= "github_tag" then
+ return Result.failure "Receipt does not have a primary source of type github_tag."
+ end
+ return client.fetch_latest_tag(source.repo):map_catching(
+ ---@param latest_tag GitHubTag
+ function(latest_tag)
+ if source.tag ~= latest_tag.name then
+ return {
+ name = source.repo,
+ current_version = source.tag,
+ latest_version = latest_tag.name,
+ }
+ end
+ error "Primary package is not outdated."
+ end
+ )
+end
+
return M
diff --git a/lua/nvim-lsp-installer/core/receipt.lua b/lua/nvim-lsp-installer/core/receipt.lua
index 21600eae..4517256a 100644
--- a/lua/nvim-lsp-installer/core/receipt.lua
+++ b/lua/nvim-lsp-installer/core/receipt.lua
@@ -18,6 +18,7 @@ local M = {}
---| '"jdtls"'
---| '"git"'
---| '"github_tag"'
+---| '"github_release"'
---| '"github_release_file"'
---@alias InstallReceiptSource {type: InstallReceiptSourceType}
@@ -135,27 +136,6 @@ function InstallReceiptBuilder.git_remote(remote_url)
return { type = "git", remote = remote_url }
end
----@param ctx ServerInstallContext
----@param opts FetchLatestGithubReleaseOpts|nil
-function InstallReceiptBuilder.github_release_file(ctx, opts)
- opts = opts or {}
- return {
- type = "github_release_file",
- repo = ctx.github_repo,
- file = ctx.github_release_file,
- release = ctx.requested_server_version,
- tag_name_pattern = opts.tag_name_pattern,
- }
-end
-
-function InstallReceiptBuilder.github_tag(ctx)
- return {
- type = "github_tag",
- repo = ctx.github_repo,
- tag = ctx.requested_server_version,
- }
-end
-
---@class InstallReceipt
---@field public name string
---@field public schema_version InstallReceiptSchemaVersion