Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,33 @@ sort_versions() {
}

fetch_all_assets() {
curl -s -H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${GH_REPO}/releases |
jq -r '.[0].assets[] | "\(.name) \(.browser_download_url)"'
local response
response=$(curl -s -H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${GH_REPO}/releases")

# Check if response is valid JSON
if ! echo "$response" | jq empty 2>/dev/null; then
fail "Failed to fetch releases from GitHub API. Invalid JSON response."
fi

# Check if response is an array (releases endpoint returns array)
if ! echo "$response" | jq -e 'type == "array"' >/dev/null 2>&1; then
# Response is not an array, likely an error from GitHub API
local error_message
error_message=$(echo "$response" | jq -r '.message // "Unknown API error"' 2>/dev/null || echo "API returned unexpected format")
fail "GitHub API error: ${error_message}. Please check your network connection and GitHub API status."
fi

# Check if there are any releases
local release_count
release_count=$(echo "$response" | jq 'length')
if [ "$release_count" -eq 0 ]; then
fail "No releases found in repository ${GH_REPO}."
fi

# Extract assets from the first release safely with built-in type checking
# This provides additional protection against edge cases
echo "$response" | jq -r 'if type == "array" and length > 0 then .[0].assets[]? | "\(.name) \(.browser_download_url)" else empty end'
}

validate_platform() {
Expand Down
Loading