From 2c653c8c112ddd981e1380d5bb222d00e08b6bf8 Mon Sep 17 00:00:00 2001
From: jurgenhaas <juergen.haas@lakedrops.com>
Date: Thu, 16 Jun 2022 13:40:55 +0200
Subject: [PATCH] Improve debugging output Provide argument from which branch
 to download

---
 bin/download | 11 ++++++++---
 bin/merge    |  8 ++++++++
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/bin/download b/bin/download
index fe97de3..f682838 100755
--- a/bin/download
+++ b/bin/download
@@ -7,7 +7,7 @@ in
   *) echo "Provide either db or files as a first argument!"
     exit 1;;
 esac
-branch=main
+branch=$(git rev-parse --abbrev-ref HEAD)
 if [[ "x$2" != "x" ]]; then
   branch=$2
 fi
@@ -23,12 +23,17 @@ function gitlab() {
     echo curl --write-out "\nHTTP-Code:%{http_code}" -X "$METHOD" -s -H "Private-Token: ${GITLAB_PRIVATE_TOKEN}" "${GITLAB_URL}"/api/v4/"$REQUEST" "$@"
   fi
   output="$(curl --write-out "\nHTTP-Code:%{http_code}" -X "$METHOD" -s -H "Private-Token: ${GITLAB_PRIVATE_TOKEN}" "${GITLAB_URL}"/api/v4/"$REQUEST" "$@")"
+  if [[ "${DEBUG}" == "yes" ]]; then
+    echo $output
+  fi
   result="$(echo "$output" | grep "{")"
   code="$(echo "$output" | grep -m 1 "HTTP-Code:" | cut -d: -f2)"
   if [[ $code -eq $EXPECTED ]]; then
     return
   fi
-  echo $output
+  if [[ "${DEBUG}" == "no" ]]; then
+    echo $output
+  fi
   echo "$METHOD request to $REQUEST did not succeed! Responds with code $code instead of $EXPECTED"
   exit 99
 }
@@ -106,7 +111,7 @@ if [[ "a${TRIGGERTOKEN}a" == "aa" ]]; then
 fi
 
 echo "Trigger pipeline ..."
-gitlab 201 POST projects/"$PRJID"/trigger/pipeline --data "token=$TRIGGERTOKEN" --data "ref=${branch}" --data "variables[TRIGGERTASK]=$mode"
+gitlab 201 POST projects/"$PRJID"/trigger/pipeline --data "token=$TRIGGERTOKEN" --data "ref=${branch}" --data "variables[TRIGGERTASK]=$mode" --data "variables[TRIGGER_INPUT]=$branch"
 PIPELINEID=$(echo "$result"  | jq -r ."id")
 PIPELINESTATUS=$(echo "$result"  | jq -r ."status")
 
diff --git a/bin/merge b/bin/merge
index a05b207..013985a 100755
--- a/bin/merge
+++ b/bin/merge
@@ -1,5 +1,7 @@
 #!/bin/bash
 
+export DEBUG=no
+
 function gitlab() {
   EXPECTED=$1
   METHOD=$2
@@ -9,11 +11,17 @@ function gitlab() {
     echo curl --write-out "\nHTTP-Code:%{http_code}" -X "$METHOD" -s -H "Private-Token: ${GITLAB_PRIVATE_TOKEN}" "${GITLAB_URL}"/api/v4/"$REQUEST" "$@"
   fi
   output="$(curl --write-out "\nHTTP-Code:%{http_code}" -X "$METHOD" -s -H "Private-Token: ${GITLAB_PRIVATE_TOKEN}" "${GITLAB_URL}"/api/v4/"$REQUEST" "$@")"
+  if [[ "${DEBUG}" == "yes" ]]; then
+    echo $output
+  fi
   result="$(echo "$output" | grep "{")"
   code="$(echo "$output" | grep -m 1 "HTTP-Code:" | cut -d: -f2)"
   if [[ $code -eq $EXPECTED ]]; then
     return
   fi
+  if [[ "${DEBUG}" == "no" ]]; then
+    echo $output
+  fi
   echo "$METHOD request to $REQUEST did not succeed! Responds with code $code instead of $EXPECTED"
   exit 99
 }
-- 
GitLab