Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLevente Polyak <anthraxx@archlinux.org>2024-01-18 19:44:11 +0100
committerLevente Polyak <anthraxx@archlinux.org>2024-02-06 17:37:17 +0100
commit67fdb58758db553d2c081cf16fbfb54e8d4e932d (patch)
tree1f8371b508d0f666125d6f5d7361fe5e1a3f4486
parenteabb1a9313a83baa5789992004dba3eb28efd070 (diff)
feat(search): add status spinner to long running GitLab calls
This helps people to be slightly more patient as the progress status update includes the current percentage. Component: pkgctl search Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
-rw-r--r--src/lib/api/gitlab.sh22
-rw-r--r--src/lib/search.sh24
2 files changed, 36 insertions, 10 deletions
diff --git a/src/lib/api/gitlab.sh b/src/lib/api/gitlab.sh
index e4b8a9d..115e58c 100644
--- a/src/lib/api/gitlab.sh
+++ b/src/lib/api/gitlab.sh
@@ -97,9 +97,10 @@ gitlab_api_call() {
gitlab_api_call_paged() {
local outfile=$1
- local request=$2
- local endpoint=$3
- local data=${4:-}
+ local status_file=$2
+ local request=$3
+ local endpoint=$4
+ local data=${5:-}
local result header
# empty token
@@ -110,9 +111,18 @@ gitlab_api_call_paged() {
[[ -z ${WORKDIR:-} ]] && setup_workdir
api_workdir=$(mktemp --tmpdir="${WORKDIR}" --directory pkgctl-gitlab-api.XXXXXXXXXX)
+ tmp_file=$(mktemp --tmpdir="${api_workdir}" spinner.tmp.XXXXXXXXXX)
+
+ local next_page=1
+ local total_pages=1
- next_page=1
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}" \
+ > "${tmp_file}"
+ mv "${tmp_file}" "${status_file}"
+
result="${api_workdir}/result.${next_page}"
header="${api_workdir}/header"
if ! curl --request "${request}" \
@@ -133,6 +143,7 @@ gitlab_api_call_paged() {
fi
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 }')
done
jq --slurp add "${api_workdir}"/result.* > "${outfile}"
@@ -277,12 +288,13 @@ gitlab_api_create_project() {
# https://docs.gitlab.com/ee/api/search.html#scope-blobs
gitlab_api_search() {
local search=$1
+ local status_file=$2
local outfile
[[ -z ${WORKDIR:-} ]] && setup_workdir
outfile=$(mktemp --tmpdir="${WORKDIR}" pkgctl-gitlab-api.XXXXXXXXXX)
- if ! gitlab_api_call_paged "${outfile}" GET "/groups/archlinux%2fpackaging%2fpackages/search?scope=blobs" "search=${search}"; then
+ if ! gitlab_api_call_paged "${outfile}" "${status_file}" GET "/groups/archlinux%2fpackaging%2fpackages/search?scope=blobs" "search=${search}"; then
return 1
fi
diff --git a/src/lib/search.sh b/src/lib/search.sh
index e737dfa..d3bad68 100644
--- a/src/lib/search.sh
+++ b/src/lib/search.sh
@@ -14,6 +14,8 @@ source "${_DEVTOOLS_LIBRARY_DIR}"/lib/cache.sh
source "${_DEVTOOLS_LIBRARY_DIR}"/lib/api/gitlab.sh
# shellcheck source=src/lib/valid-search.sh
source "${_DEVTOOLS_LIBRARY_DIR}"/lib/valid-search.sh
+# shellcheck source=src/lib/util/term.sh
+source "${_DEVTOOLS_LIBRARY_DIR}"/lib/util/term.sh
source /usr/share/makepkg/util/util.sh
source /usr/share/makepkg/util/message.sh
@@ -167,9 +169,12 @@ pkgctl_search() {
fi
# call the gitlab search API
- stat_busy "Querying gitlab search api"
- output=$(gitlab_api_search "${search}")
- stat_done
+ status_dir=$(mktemp --tmpdir="${WORKDIR}" --directory pkgctl-gitlab-api.XXXXXXXXXX)
+ printf "📡 Querying GitLab search API..." > "${status_dir}/status"
+ term_spinner_start "${status_dir}"
+ output=$(gitlab_api_search "${search}" "${status_dir}/status")
+ term_spinner_stop "${status_dir}"
+ msg_success "Querying GitLab search API"
# collect project ids whose name needs to be looked up
project_name_cache_file=$(get_cache_file gitlab/project_id_to_name)
@@ -179,7 +184,9 @@ pkgctl_search() {
grep --invert-match --file <(awk '{ print $1 }' < "${project_name_cache_file}" ))
# look up project names
- stat_busy "Querying project names"
+ tmp_file=$(mktemp --tmpdir="${WORKDIR}" pkgctl-gitlab-api-spinner.tmp.XXXXXXXXXX)
+ printf "📡 Querying GitLab project names..." > "${status_dir}/status"
+ term_spinner_start "${status_dir}"
local entries="${#project_ids[@]}"
local until=0
while (( until < entries )); do
@@ -190,6 +197,12 @@ pkgctl_search() {
fi
length=$(( until - from ))
+ percentage=$(( 100 * until / entries ))
+ printf "📡 Querying GitLab project names: %s/%s [%s] %%spinner%%" \
+ "${BOLD}${until}" "${entries}" "${percentage}%${ALL_OFF}" \
+ > "${tmp_file}"
+ mv "${tmp_file}" "${status_dir}/status"
+
project_slice=("${project_ids[@]:${from}:${length}}")
printf -v projects '"gid://gitlab/Project/%s",' "${project_slice[@]}"
query='{
@@ -214,7 +227,8 @@ pkgctl_search() {
'.[] | "\(.id | rindex("/") as $lastSlash | .[$lastSlash+1:]) \(.name)"' \
<<< "${mapping_output}")
done
- stat_done
+ term_spinner_stop "${status_dir}"
+ msg_success "Querying GitLab project names"
# read project_id to name mapping from cache
declare -A project_name_lookup=()