script/tf-a-lts-docs-watcher.sh: Build the doc for the branch

Ensure the documentation is built for the branch when the job
is triggered so that the branch version points to the latest tag.

Change-Id: I86d87d2d0b90dc8ade39d9ba779fe963ab509827
Signed-off-by: Arthur She <arthur.she@linaro.org>
diff --git a/scripts/tf-a-lts-docs-watcher.sh b/scripts/tf-a-lts-docs-watcher.sh
index 734e1a5..abdd448 100755
--- a/scripts/tf-a-lts-docs-watcher.sh
+++ b/scripts/tf-a-lts-docs-watcher.sh
@@ -60,6 +60,9 @@
     max_retry_time=20
     retry=0
 
+    # Check whether we need to activate a tag or a branch. If it's a tag, create a branch variable
+    echo ${version} | grep -q "lts-v[0-9].*\.[0-9].*\.[0-9].*" && branch=${version%.*}
+
     ver_slug=$(curl -s -H "Authorization: Token ${RTD_API_TOKEN}" ${RTD_VER_API}/${version}/ | \
                  jq -r '.slug')
 
@@ -72,6 +75,12 @@
                      jq -r '.slug')
     done
 
+    # activate and hide the branch
+    if [ -n "${branch}" ]; then
+        curl -s -X PATCH -H "Content-Type: application/json" -H "Authorization: Token ${RTD_API_TOKEN}" \
+             -d "{\"active\": true, \"hidden\": true}" ${RTD_VER_API}/${branch}/
+    fi
+
     if [ ${retry} -le ${max_retry_time} ]; then
         echo "Active new version: ${version}"
         curl -s -X PATCH -H "Content-Type: application/json" -H "Authorization: Token ${RTD_API_TOKEN}" \
@@ -104,7 +113,7 @@
 }
 
 echo "Notifying ReadTheDocs of changes"
-curl -s -X POST -H "Authorization: Token ${RTD_API_TOKEN}" ${RTD_API}/sync-versions/
+curl -s -X POST -H "Authorization: Token ${RTD_API_TOKEN}" ${RTD_VER_API}/${lts_branch}/builds/
 
 # Triggered by a new tag
 if [ -n "${new_tag}" ]; then