From d7c7014379ef4298c7ff7a6cd15affc12194273a Mon Sep 17 00:00:00 2001
From: Florent Pruvost <florent.pruvost@inria.fr>
Date: Fri, 29 Sep 2023 14:18:31 +0200
Subject: [PATCH] fix validate.sh, use SONARQUBE_LOGIN to authenticate and fix
 coverage comparison

---
 .gitlab/validate.sh | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/.gitlab/validate.sh b/.gitlab/validate.sh
index daf827c2c..201fc52c9 100755
--- a/.gitlab/validate.sh
+++ b/.gitlab/validate.sh
@@ -5,7 +5,7 @@
 #  @copyright 2023-2023 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
 #                       Univ. Bordeaux. All rights reserved.
 #
-#  @version 1.0.0
+#  @version 1.2.0
 #  @author Mathieu Faverge
 #  @author Florent Pruvost
 #  @date 2023-09-22
@@ -34,8 +34,9 @@ if [[ -z $SONARQUBE_LOGIN ]]; then
 fi
 
 if [[ $METRIC == "BUG" ]]; then
-  BUG=`curl -u $TOKEN: -X GET "https://sonarqube.inria.fr/sonarqube/api/measures/component?component=${CI_PROJECT_NAMESPACE}%3A${CI_PROJECT_NAME}&pullRequest=${CI_MERGE_REQUEST_IID}&metricKeys=new_bugs" |jq '.component.measures[0].period.value' | sed -e "s#\"##g"`
-  if [[ $BUG > 0 ]]; then
+  BUG=`curl -u $SONARQUBE_LOGIN: -X GET "https://sonarqube.inria.fr/sonarqube/api/measures/component?component=${CI_PROJECT_NAMESPACE}%3A${CI_PROJECT_NAME}&pullRequest=${CI_MERGE_REQUEST_IID}&metricKeys=new_bugs" |jq '.component.measures[0].period.value' | sed -e "s#\"##g"`
+  echo "BUG=$BUG"
+  if [[ $BUG -gt 0 ]]; then
     echo "%{BUG} new bugs detected by Sonarqube -> Failure."
     exit 1
   else
@@ -43,11 +44,12 @@ if [[ $METRIC == "BUG" ]]; then
     exit 0
   fi
 elif [[ $METRIC == "COVERAGE" ]]; then
-  COV=`curl -u $TOKEN: -X GET "https://sonarqube.inria.fr/sonarqube/api/measures/component?component=${CI_PROJECT_NAMESPACE}%3A${CI_PROJECT_NAME}&pullRequest=${CI_MERGE_REQUEST_IID}&metricKeys=new_coverage" |jq '.component.measures[0].period.value' | sed -e "s#\"##g"`
+  COV=`curl -u $SONARQUBE_LOGIN: -X GET "https://sonarqube.inria.fr/sonarqube/api/measures/component?component=${CI_PROJECT_NAMESPACE}%3A${CI_PROJECT_NAME}&pullRequest=${CI_MERGE_REQUEST_IID}&metricKeys=new_coverage" |jq '.component.measures[0].period.value' | sed -e "s#\"##g" | cut -d "." -f 1`
+  echo "COV=$COV"
   if [[ $COV == "null" || -z $COV  ]]; then
     echo "Coverage is empty, certainly that there are no lines of new code (considered during the analysis) to compare -> Success."
   else
-    if [[ $COV < 80 ]]; then
+    if [[ $COV -lt 80 ]]; then
       echo "Coverage on new lines is ${COV}%, which is < 80% -> Failure."
       exit 1
     else
-- 
GitLab