From 007c2d3e114a1bb98e907b19160cc055ea7fc540 Mon Sep 17 00:00:00 2001 From: Amir MOHAMMADI <amir.mohammadi@idiap.ch> Date: Thu, 1 Jun 2017 16:44:36 +0200 Subject: [PATCH] Use the good old curl --- gitlab/update_feedstock.py | 39 ++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/gitlab/update_feedstock.py b/gitlab/update_feedstock.py index 670f07c..85406cb 100755 --- a/gitlab/update_feedstock.py +++ b/gitlab/update_feedstock.py @@ -114,28 +114,31 @@ class Gitlab(object): return json.loads(pipeline.decode()) def accept_merge_request(self, project_id, mergerequest_id, - merge_commit_message=None, - should_remove_source_branch=None, - merge_when_pipeline_succeeds=None, sha=None): + merge_commit_message='', + should_remove_source_branch='', + merge_when_pipeline_succeeds='', sha=''): """ Update an existing merge request. """ - data = { - 'merge_commit_message': merge_commit_message, - 'should_remove_source_branch': should_remove_source_branch, - 'merge_when_pipeline_succeeds': merge_when_pipeline_succeeds, - 'sha': sha, - } - - request = requests.put( - '{0}/{1}/merge_request/{2}/merge'.format( - self.projects_url, project_id, mergerequest_id), - data=data, headers={'PRIVATE-TOKEN': self.token}) - - if request.status_code == 200: - return request.json() - else: + url = "projects/{}/merge_request/{}/merge?" + url += "&".join([ + 'merge_commit_message={}', + 'should_remove_source_branch={}', + 'merge_when_pipeline_succeeds={}', + 'sha={}', + ]) + url = url.format(project_id, mergerequest_id, merge_commit_message, + should_remove_source_branch, + merge_when_pipeline_succeeds, + sha) + cmd = ["curl", "--request", "PUT", "--header", + "PRIVATE-TOKEN: {}".format(self.token), + self.base_url + url] + pipeline = subprocess.check_output(cmd) + try: + return json.loads(pipeline.decode()) + except Exception: return False -- GitLab