Add pagination

This commit is contained in:
Antonio J. Delgado 2024-02-16 14:16:28 +02:00
parent f3a869a0de
commit 888607d193

View file

@ -50,8 +50,16 @@ done
if [ "${tag}" == "latest" ]; then if [ "${tag}" == "latest" ]; then
tag=$(curl -L -s -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${token}" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/mastodon/mastodon/releases/latest | jq '.tag_name') tag=$(curl -L -s -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${token}" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/mastodon/mastodon/releases/latest | jq '.tag_name')
else else
releases=$(curl -L -s -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${token}" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/mastodon/mastodon/releases | jq '.[]|.tag_name') next_page=https://api.github.com/repos/mastodon/mastodon/releases
if ! echo "${releases}" | pgrep "${tag}"; then releases_file=$(mktemp /tmp/tmp.XXXX)
while [ -z "${next_page}" ]
do
tmpfile=$(mktemp /tmp/tmp.XXXXX)
releases=$(curl -L -s -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${token}" -H "X-GitHub-Api-Version: 2022-11-28" "${next_page}" | jq '.[]|.tag_name' 2> "${tmpfile}")
echo "${releases}" >> "${releases_file}"
next_page=$(grep '< link: ' "${tmpfile}" | sed 's/< link: //g' | sed 's/, /\n/g' | grep 'rel="next"' | grep -o 'https://[^>]*')
done
if ! pgrep "${tag}" "${releases_file}"; then
printf "The tag '%s' is not part of the releases:\n%s" "${tag}" "${releases}" printf "The tag '%s' is not part of the releases:\n%s" "${tag}" "${releases}"
exit 1 exit 1
fi fi