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

Merge branch 'automerge' into 'master'

Automatically accept bob.conda merge requests if the pipeline succeeds

See merge request !54
parents b0bf6296 63778f91
Branches
No related tags found
1 merge request!54Automatically accept bob.conda merge requests if the pipeline succeeds
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment