Skip to content

Commit 011cb72

Browse files
authored
fix(tools): handle repos with 30+ pre-releases in check_for_gh_release
- Try /releases/latest first for non-pinned versions (1 API call) - Increase per_page to 100 when fetching all releases
1 parent d9b0588 commit 011cb72

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

misc/tools.func

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,15 +1453,32 @@ check_for_gh_release() {
14531453

14541454
ensure_dependencies jq
14551455

1456-
# Fetch releases and exclude drafts/prereleases
1457-
local releases_json
1458-
releases_json=$(curl -fsSL --max-time 20 \
1459-
-H 'Accept: application/vnd.github+json' \
1460-
-H 'X-GitHub-Api-Version: 2022-11-28' \
1461-
"https://api.github.com/repos/${source}/releases") || {
1462-
msg_error "Unable to fetch releases for ${app}"
1463-
return 1
1464-
}
1456+
# Try /latest endpoint for non-pinned versions (most efficient)
1457+
local releases_json=""
1458+
1459+
if [[ -z "$pinned_version_in" ]]; then
1460+
releases_json=$(curl -fsSL --max-time 20 \
1461+
-H 'Accept: application/vnd.github+json' \
1462+
-H 'X-GitHub-Api-Version: 2022-11-28' \
1463+
"https://api.github.com/repos/${source}/releases/latest" 2>/dev/null)
1464+
1465+
if [[ $? -eq 0 ]] && [[ -n "$releases_json" ]]; then
1466+
# Wrap single release in array for consistent processing
1467+
releases_json="[$releases_json]"
1468+
fi
1469+
fi
1470+
1471+
# If no releases yet (pinned version OR /latest failed), fetch up to 100
1472+
if [[ -z "$releases_json" ]]; then
1473+
# Fetch releases and exclude drafts/prereleases
1474+
releases_json=$(curl -fsSL --max-time 20 \
1475+
-H 'Accept: application/vnd.github+json' \
1476+
-H 'X-GitHub-Api-Version: 2022-11-28' \
1477+
"https://api.github.com/repos/${source}/releases?per_page=100") || {
1478+
msg_error "Unable to fetch releases for ${app}"
1479+
return 1
1480+
}
1481+
fi
14651482

14661483
mapfile -t raw_tags < <(jq -r '.[] | select(.draft==false and .prerelease==false) | .tag_name' <<<"$releases_json")
14671484
if ((${#raw_tags[@]} == 0)); then

0 commit comments

Comments
 (0)