From b45403ec7efb6758eacde33d05a814a9a5201142 Mon Sep 17 00:00:00 2001
From: Guillaume Pasero <guillaume.pasero@c-s.fr>
Date: Mon, 15 Apr 2019 18:27:35 +0200
Subject: [PATCH] CI: difference between POST and GET requests

---
 CI/check_twin_pipelines.py | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/CI/check_twin_pipelines.py b/CI/check_twin_pipelines.py
index e32f14d196..d2a6113924 100644
--- a/CI/check_twin_pipelines.py
+++ b/CI/check_twin_pipelines.py
@@ -28,14 +28,19 @@ import time
 """
 Send a request to Gitlab and return the answer
 The request parameter is added after `project/:id/`
+WARNING: when data is given, the request will be a POST
+Otherwise, it is a GET
 """
-def GitlabRequest(request, project=53, token=''):
+def GitlabRequest(request, project=53, data=None, token=''):
   gitlab_url = "https://gitlab.orfeo-toolbox.org/api/v4/projects/"
   gitlab_url+= str(project) + '/' + request
+  params = None
   myHeader = {}
+  if not data is None:
+    params = urllib.parse.urlencode(data).encode('ascii')
   if token:
     myHeader = {'PRIVATE-TOKEN':token}
-  gitlab_request = urllib.request.Request(gitlab_url,headers=myHeader)
+  gitlab_request = urllib.request.Request(gitlab_url, data=params, headers=myHeader)
   res = urllib.request.urlopen(gitlab_request)
   return json.loads(res.read().decode())
 
@@ -67,7 +72,7 @@ if __name__ == "__main__":
     if wip_regex.search(mrInfo["title"]):
       # Yes: cancel the current pipeline
       print("Cancel current pipeline "+env['CI_PIPELINE_ID'])
-      GitlabRequest('pipelines/'+env['CI_PIPELINE_ID']+'/cancel', \
+      GitlabRequest('pipelines/'+env['CI_PIPELINE_ID']+'/cancel', data={}, \
         project=env['CI_PROJECT_ID'], token=env['K8S_SECRET_TWIN_PIPELINE'])
       time.sleep(180)
       print("Error: this pipeline should have been canceled")
@@ -78,6 +83,6 @@ if __name__ == "__main__":
       for item in jres:
         if item["id"] < int(env['CI_PIPELINE_ID']) and item["status"] == "running":
           print("Cancel pipeline "+str(item["id"]))
-          jres2 = GitlabRequest('pipelines/'+str(item["id"])+'/cancel', \
+          jres2 = GitlabRequest('pipelines/'+str(item["id"])+'/cancel', data={}, \
             project=env['CI_PROJECT_ID'], token=env['K8S_SECRET_TWIN_PIPELINE'])
 
-- 
GitLab