aboutsummaryrefslogtreecommitdiffstats
path: root/lua/mason-core/managers/github
diff options
context:
space:
mode:
Diffstat (limited to 'lua/mason-core/managers/github')
-rw-r--r--lua/mason-core/managers/github/client.lua26
-rw-r--r--lua/mason-core/managers/github/init.lua22
2 files changed, 30 insertions, 18 deletions
diff --git a/lua/mason-core/managers/github/client.lua b/lua/mason-core/managers/github/client.lua
index 80011e22..894df658 100644
--- a/lua/mason-core/managers/github/client.lua
+++ b/lua/mason-core/managers/github/client.lua
@@ -10,7 +10,7 @@ local M = {}
---@alias GitHubTag {name: string}
---@param path string
----@return Result: JSON decoded response.
+---@return Result # JSON decoded response.
local function api_call(path)
return spawn
.gh({ "api", path })
@@ -22,8 +22,8 @@ local function api_call(path)
end
---@async
----@param repo string: The GitHub repo ("username/repo").
----@return Result: of GitHubRelease[]
+---@param repo string The GitHub repo ("username/repo").
+---@return Result # Result<GitHubRelease[]>
function M.fetch_releases(repo)
log.fmt_trace("Fetching GitHub releases for repo=%s", repo)
local path = ("repos/%s/releases"):format(repo)
@@ -33,8 +33,8 @@ function M.fetch_releases(repo)
end
---@async
----@param repo string: The GitHub repo ("username/repo").
----@param tag_name string: The tag_name of the release to fetch.
+---@param repo string The GitHub repo ("username/repo").
+---@param tag_name string The tag_name of the release to fetch.
function M.fetch_release(repo, tag_name)
log.fmt_trace("Fetching GitHub release for repo=%s, tag_name=%s", repo, tag_name)
local path = ("repos/%s/releases/tags/%s"):format(repo, tag_name)
@@ -56,12 +56,12 @@ function M.release_predicate(opts)
}
end
----@alias FetchLatestGithubReleaseOpts {tag_name_pattern:string|nil, include_prerelease: boolean}
+---@alias FetchLatestGithubReleaseOpts {tag_name_pattern:string?, include_prerelease: boolean}
---@async
----@param repo string: The GitHub repo ("username/repo").
----@param opts FetchLatestGithubReleaseOpts|nil
----@return Result: of GitHubRelease
+---@param repo string The GitHub repo ("username/repo").
+---@param opts FetchLatestGithubReleaseOpts?
+---@return Result # Result<GitHubRelease>
function M.fetch_latest_release(repo, opts)
opts = opts or {
tag_name_pattern = nil,
@@ -86,8 +86,8 @@ function M.fetch_latest_release(repo, opts)
end
---@async
----@param repo string: The GitHub repo ("username/repo").
----@return Result: of GitHubTag[]
+---@param repo string The GitHub repo ("username/repo").
+---@return Result # Result<GitHubTag[]>
function M.fetch_tags(repo)
local path = ("repos/%s/tags"):format(repo)
return api_call(path):map_err(function()
@@ -96,8 +96,8 @@ function M.fetch_tags(repo)
end
---@async
----@param repo string: The GitHub repo ("username/repo").
----@return Result: Result<string> - The latest tag name.
+---@param repo string The GitHub repo ("username/repo").
+---@return Result # Result<string> The latest tag name.
function M.fetch_latest_tag(repo)
-- https://github.com/williamboman/vercel-github-api-latest-tag-proxy
return fetch(("https://latest-github-tag.redwill.se/api/repo/%s/latest-tag"):format(repo))
diff --git a/lua/mason-core/managers/github/init.lua b/lua/mason-core/managers/github/init.lua
index a0336d30..2634d02b 100644
--- a/lua/mason-core/managers/github/init.lua
+++ b/lua/mason-core/managers/github/init.lua
@@ -8,10 +8,17 @@ local settings = require "mason.settings"
local M = {}
+---@class InstallReceiptGitHubReleaseFileSource
+---@field type '"github_release_file"'
+---@field repo string
+---@field file string
+---@field release string
+
---@param repo string
---@param asset_file string
---@param release string
local function with_release_file_receipt(repo, asset_file, release)
+ ---@return InstallReceiptGitHubReleaseFileSource
return function()
local ctx = installer.context()
ctx.receipt:with_primary_source {
@@ -23,6 +30,11 @@ local function with_release_file_receipt(repo, asset_file, release)
end
end
+---@class InstallReceiptGitHubTagSource
+---@field type '"github_tag"'
+---@field repo string
+---@field tag string
+
---@param repo string
---@param tag string
local function with_tag_receipt(repo, tag)
@@ -37,7 +49,7 @@ local function with_tag_receipt(repo, tag)
end
---@async
----@param opts {repo: string, version: Optional|nil, asset_file: string|fun(release: string):string}
+---@param opts {repo: string, version: Optional?, asset_file: string|fun(release: string):string}
function M.release_file(opts)
local ctx = installer.context()
local release = _.coalesce(opts.version, ctx.requested_version):or_else_get(function()
@@ -50,7 +62,7 @@ function M.release_file(opts)
local asset_file
if type(opts.asset_file) == "function" then
asset_file = opts.asset_file(release)
- else
+ elseif type(asset_file) == "string" then
asset_file = opts.asset_file
end
if not asset_file then
@@ -71,7 +83,7 @@ function M.release_file(opts)
end
---@async
----@param opts {repo: string, version: Optional|nil}
+---@param opts {repo: string, version: Optional?}
function M.tag(opts)
local ctx = installer.context()
local tag = _.coalesce(opts.version, ctx.requested_version):or_else_get(function()
@@ -128,7 +140,7 @@ function M.gunzip_release_file(opts)
end
---@async
----@param receipt InstallReceipt
+---@param receipt InstallReceipt<InstallReceiptGitHubReleaseFileSource>
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
@@ -150,7 +162,7 @@ function M.check_outdated_primary_package_release(receipt)
end
---@async
----@param receipt InstallReceipt
+---@param receipt InstallReceipt<InstallReceiptGitHubTagSource>
function M.check_outdated_primary_package_tag(receipt)
local source = receipt.primary_source
if source.type ~= "github_tag" then