fix: impl gh-r version detection using GitHub API (#731)

This commit is contained in:
Xie Zejian 2025-09-05 20:27:03 +08:00 committed by GitHub
parent c6dd2a69c5
commit f1e503dc3b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1441,9 +1441,15 @@ builtin source "${ZINIT[BIN_DIR]}/zinit-side.zsh" || {
parts=(${(@s:;:)$(.zi::get-architecture)})
if [[ -z $urlpart ]]; then
local tag_version=${ICE[ver]}
if [[ -z $tag_version ]]; then
# Try GitHub API first, fallback to HTML parsing
local api_url=https://api.github.com/repos/$user/$plugin/releases/latest
tag_version="$( { .zinit-download-file-stdout $api_url || .zinit-download-file-stdout $api_url 1; } 2>/dev/null | command grep -o '"tag_name"[[:space:]]*:[[:space:]]*"[^"]\+"' | command grep -o '"[^"]*"$' | tr -d '"' )"
# Fallback to original method if API fails
if [[ -z $tag_version ]]; then
local releases_url=https://github.com/$user/$plugin/releases/latest
tag_version="$( { .zinit-download-file-stdout $releases_url || .zinit-download-file-stdout $releases_url 1; } 2>/dev/null | command grep -m1 -o 'href=./'$user'/'$plugin'/releases/tag/[^"]\+' )"
fi
tag_version=${tag_version##*/}
fi
local url=https://github.com/$user/$plugin/releases/expanded_assets/$tag_version