Skip to content
Snippets Groups Projects
Verified Commit bed2b5db authored by Christian Heusel's avatar Christian Heusel :rocket: Committed by Levente Polyak
Browse files

fix(gitlab): prevent division by 0 for missing total pages

As it turns out the Gitlab api is not guaranteed to return the
x-total-pages header for larger query result which previously resulted
in a division by zero for pkgctl search as the utlity function assumed
that this value would always be set to a positive integer.

Fixes #255

Link: https://gitlab.com/gitlab-org/gitlab/-/issues/436373


Component: gitlab.sh
Signed-off-by: default avatarChristian Heusel <christian@heusel.eu>
parent 47d5ea1e
No related branches found
No related tags found
1 merge request!292fix: prevent division by 0 for missing total pages
Pipeline #116360 passed
......@@ -119,11 +119,13 @@ gitlab_api_call_paged() {
local next_page=1
local total_pages=1
local known_total_pages=1
local percentage=100
while [[ -n "${next_page}" ]]; do
percentage=$(( 100 * next_page / total_pages ))
printf "📡 Querying GitLab: %s/%s [%s] %%spinner%%" \
"${BOLD}${next_page}" "${total_pages}" "${percentage}%${ALL_OFF}" \
"${BOLD}${next_page}" "${known_total_pages}" "${percentage}%${ALL_OFF}" \
> "${tmp_file}"
mv "${tmp_file}" "${status_file}"
......@@ -148,6 +150,15 @@ gitlab_api_call_paged() {
next_page=$(grep "x-next-page" "${header}" | tr -d '\r' | awk '{ print $2 }')
total_pages=$(grep "x-total-pages" "${header}" | tr -d '\r' | awk '{ print $2 }')
# The api is not guaranteed to return x-total-pages for larger query results
# https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/23931
# https://gitlab.com/gitlab-org/gitlab/-/issues/436373
if (( total_pages == 0 )); then
total_pages=${next_page}
known_total_pages="?"
else
known_total_pages=${total_pages}
fi
done
jq --slurp add "${api_workdir}"/result.* > "${outfile}"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment