tf-a-lts-docs-watcher.sh: Add helper function to debug REST API responses

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
Change-Id: I5ce7ca1d31fd02fc34335faf90d4f42c94743452
diff --git a/scripts/tf-a-lts-docs-watcher.sh b/scripts/tf-a-lts-docs-watcher.sh
index 4da08e3..d8c8459 100755
--- a/scripts/tf-a-lts-docs-watcher.sh
+++ b/scripts/tf-a-lts-docs-watcher.sh
@@ -1,11 +1,13 @@
 #!/bin/bash
-set -ex
+set -x
 
 echo "########################################################################"
 echo "    Gerrit Environment"
 env | grep '^GERRIT'
 echo "########################################################################"
 
+set -e
+
 if [ "${GERRIT_PROJECT}" == "TF-A/trusted-firmware-a" ]; then
     # For real production project, non-sandbox run goes to production RTD project,
     # while for sandbox run to a separate RTD project.
@@ -45,6 +47,14 @@
     lts_branch=${refname%.*}
 fi
 
+function rtd_rest_api() {
+    uri="$1"
+    jqfilt="$2"
+    resp=$(curl -s -H "Authorization: Token ${RTD_API_TOKEN}" "$uri")
+    echo $resp 1>&2
+    echo $resp | jq -r "$jqfilt"
+}
+
 function activate_version() {
     version=$1
     max_retry_time=20
@@ -109,8 +119,7 @@
 if [ -n "${new_tag}" ]; then
     echo -e "\nNew release tag: ${new_tag}, slug: ${new_slug}"
     # Hide the current active and unhidden tags
-    old_tags=$(curl -s -H "Authorization: Token ${RTD_API_TOKEN}" "${RTD_VER_API}/?slug=${lts_branch}&type=tag&active=true" | \
-                   jq -r '.results | map(select(.hidden == false) | .slug) | .[]')
+    old_tags=$(rtd_rest_api "${RTD_VER_API}/?slug=${lts_branch}&type=tag&active=true" '.results | map(select(.hidden == false) | .slug) | .[]')
     for t in ${old_tags};
     do
         echo "Hide old tag: ${t}"