fix(install): simplify to the direct /releases/download/latest/ URL
Gitea serves the most recent release under the `latest` tag segment, so `/releases/download/latest/nuwiki-ls-<target>.tar.gz` resolves directly (HTTP 200) — no API lookup or JSON parsing needed. Drop the latest_asset_url helpers added in the previous fix; the only real bug was the URL shape (`/releases/latest/download/` is GitHub-only and 404s on Gitea). Both install paths now just pick the target and build the URL. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+7
-26
@@ -66,28 +66,6 @@ local function build_from_source(dest)
|
|||||||
return vim.fn.executable(dest) == 1
|
return vim.fn.executable(dest) == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Gitea API base for this repo. Gitea has no GitHub-style
|
|
||||||
-- `/releases/latest/download/<asset>` shortcut, so resolve the asset's real
|
|
||||||
-- download URL (`browser_download_url`) through the API instead.
|
|
||||||
local REPO_API = 'https://code.gfran.co/api/v1/repos/gffranco/nuwiki'
|
|
||||||
|
|
||||||
local function latest_asset_url(asset_name)
|
|
||||||
local body = vim.fn.system({ 'curl', '-fsSL', REPO_API .. '/releases/latest' })
|
|
||||||
if vim.v.shell_error ~= 0 then
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
local ok, release = pcall(vim.json.decode, body)
|
|
||||||
if not ok or type(release) ~= 'table' or type(release.assets) ~= 'table' then
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
for _, a in ipairs(release.assets) do
|
|
||||||
if a.name == asset_name then
|
|
||||||
return a.browser_download_url
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
local function download_release(dest)
|
local function download_release(dest)
|
||||||
local target = target_triple()
|
local target = target_triple()
|
||||||
if not target then
|
if not target then
|
||||||
@@ -96,10 +74,13 @@ local function download_release(dest)
|
|||||||
if vim.fn.executable('curl') ~= 1 or vim.fn.executable('tar') ~= 1 then
|
if vim.fn.executable('curl') ~= 1 or vim.fn.executable('tar') ~= 1 then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
local url = latest_asset_url('nuwiki-ls-' .. target .. '.tar.gz')
|
-- Gitea serves the most recent release under the `latest` tag segment
|
||||||
if not url then
|
-- (`/releases/download/latest/<asset>`). Note this is NOT GitHub's
|
||||||
return false
|
-- `/releases/latest/download/<asset>` shape, which Gitea 404s.
|
||||||
end
|
local url = string.format(
|
||||||
|
'https://code.gfran.co/gffranco/nuwiki/releases/download/latest/nuwiki-ls-%s.tar.gz',
|
||||||
|
target
|
||||||
|
)
|
||||||
local archive = vim.fn.tempname() .. '.tar.gz'
|
local archive = vim.fn.tempname() .. '.tar.gz'
|
||||||
vim.fn.system({ 'curl', '-fsSL', '-o', archive, url })
|
vim.fn.system({ 'curl', '-fsSL', '-o', archive, url })
|
||||||
if vim.v.shell_error ~= 0 then
|
if vim.v.shell_error ~= 0 then
|
||||||
|
|||||||
@@ -48,30 +48,6 @@ function! s:build_from_source() abort
|
|||||||
return executable(s:bin)
|
return executable(s:bin)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Gitea has no GitHub-style /releases/latest/download/<asset> shortcut, so
|
|
||||||
" resolve the asset's real download URL (browser_download_url) via the API.
|
|
||||||
function! s:latest_asset_url(asset) abort
|
|
||||||
let l:api = 'https://code.gfran.co/api/v1/repos/gffranco/nuwiki/releases/latest'
|
|
||||||
let l:body = system('curl -fsSL ' . shellescape(l:api))
|
|
||||||
if v:shell_error != 0
|
|
||||||
return ''
|
|
||||||
endif
|
|
||||||
try
|
|
||||||
let l:release = json_decode(l:body)
|
|
||||||
catch
|
|
||||||
return ''
|
|
||||||
endtry
|
|
||||||
if type(l:release) != type({}) || !has_key(l:release, 'assets')
|
|
||||||
return ''
|
|
||||||
endif
|
|
||||||
for l:item in l:release.assets
|
|
||||||
if get(l:item, 'name', '') ==# a:asset
|
|
||||||
return get(l:item, 'browser_download_url', '')
|
|
||||||
endif
|
|
||||||
endfor
|
|
||||||
return ''
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:download_release() abort
|
function! s:download_release() abort
|
||||||
let l:target = s:target()
|
let l:target = s:target()
|
||||||
if empty(l:target)
|
if empty(l:target)
|
||||||
@@ -80,10 +56,11 @@ function! s:download_release() abort
|
|||||||
if !executable('curl') || !executable('tar')
|
if !executable('curl') || !executable('tar')
|
||||||
return 0
|
return 0
|
||||||
endif
|
endif
|
||||||
let l:url = s:latest_asset_url('nuwiki-ls-' . l:target . '.tar.gz')
|
" Gitea serves the most recent release under the `latest` tag segment
|
||||||
if empty(l:url)
|
" (/releases/download/latest/<asset>). NOT GitHub's
|
||||||
return 0
|
" /releases/latest/download/<asset> shape, which Gitea 404s.
|
||||||
endif
|
let l:url = 'https://code.gfran.co/gffranco/nuwiki/releases/download/latest/nuwiki-ls-'
|
||||||
|
\ . l:target . '.tar.gz'
|
||||||
let l:archive = tempname() . '.tar.gz'
|
let l:archive = tempname() . '.tar.gz'
|
||||||
call system('curl -fsSL -o ' . shellescape(l:archive) . ' ' . shellescape(l:url))
|
call system('curl -fsSL -o ' . shellescape(l:archive) . ' ' . shellescape(l:url))
|
||||||
if v:shell_error != 0
|
if v:shell_error != 0
|
||||||
|
|||||||
Reference in New Issue
Block a user