diff --git a/gitlab/update_feedstock.py b/gitlab/update_feedstock.py index 3ebf7e00ff2e1c386a63f2b37c71575e0a22a57a..670f07c6020a94fa8e96a1516af839158c50bf77 100755 --- a/gitlab/update_feedstock.py +++ b/gitlab/update_feedstock.py @@ -69,6 +69,7 @@ class Gitlab(object): super(Gitlab, self).__init__() self.token = token self.base_url = 'https://gitlab.idiap.ch/api/v3/' + self.projects_url = self.base_url + 'projects/' def get_project(self, project_name, namespace='bob'): cmd = ["curl", "--header", @@ -112,6 +113,31 @@ class Gitlab(object): pipeline = subprocess.check_output(cmd) 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): + """ + 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: + return False + def update_meta(meta_path, package): stable_version = get_version(package) @@ -220,8 +246,10 @@ def main(package, subfolder='recipes', direct_push=False): gitlab = Gitlab(os.environ.get('GITLAB_API_TOKEN')) project_id = gitlab.get_project('bob.conda')['id'] title = 'Update-to-{}'.format(branch_name) - gitlab.create_merge_request(project_id, branch_name, 'master', title, - remove_source_branch='true') + mr = gitlab.create_merge_request(project_id, branch_name, 'master', + title, remove_source_branch='true') + gitlab.accept_merge_request( + project_id, mr['id'], merge_when_pipeline_succeeds='true') finally: shutil.rmtree(temp_dir)