Skip to content
Snippets Groups Projects
Commit 63778f91 authored by Amir MOHAMMADI's avatar Amir MOHAMMADI
Browse files

Automatically accept bob.conda merge requests if the pipeline succeeds

parent b0bf6296
No related branches found
No related tags found
1 merge request!54Automatically accept bob.conda merge requests if the pipeline succeeds
...@@ -69,6 +69,7 @@ class Gitlab(object): ...@@ -69,6 +69,7 @@ class Gitlab(object):
super(Gitlab, self).__init__() super(Gitlab, self).__init__()
self.token = token self.token = token
self.base_url = 'https://gitlab.idiap.ch/api/v3/' self.base_url = 'https://gitlab.idiap.ch/api/v3/'
self.projects_url = self.base_url + 'projects/'
def get_project(self, project_name, namespace='bob'): def get_project(self, project_name, namespace='bob'):
cmd = ["curl", "--header", cmd = ["curl", "--header",
...@@ -112,6 +113,31 @@ class Gitlab(object): ...@@ -112,6 +113,31 @@ class Gitlab(object):
pipeline = subprocess.check_output(cmd) pipeline = subprocess.check_output(cmd)
return json.loads(pipeline.decode()) 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): def update_meta(meta_path, package):
stable_version = get_version(package) stable_version = get_version(package)
...@@ -220,8 +246,10 @@ def main(package, subfolder='recipes', direct_push=False): ...@@ -220,8 +246,10 @@ def main(package, subfolder='recipes', direct_push=False):
gitlab = Gitlab(os.environ.get('GITLAB_API_TOKEN')) gitlab = Gitlab(os.environ.get('GITLAB_API_TOKEN'))
project_id = gitlab.get_project('bob.conda')['id'] project_id = gitlab.get_project('bob.conda')['id']
title = 'Update-to-{}'.format(branch_name) title = 'Update-to-{}'.format(branch_name)
gitlab.create_merge_request(project_id, branch_name, 'master', title, mr = gitlab.create_merge_request(project_id, branch_name, 'master',
remove_source_branch='true') title, remove_source_branch='true')
gitlab.accept_merge_request(
project_id, mr['id'], merge_when_pipeline_succeeds='true')
finally: finally:
shutil.rmtree(temp_dir) shutil.rmtree(temp_dir)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment