From 37b15c72b21b1f45593267f4465ddb9427585bc7 Mon Sep 17 00:00:00 2001 From: Andre Anjos <andre.dos.anjos@gmail.com> Date: Thu, 14 Feb 2019 14:54:11 +0100 Subject: [PATCH] [release] Ensure merge-when-pipeline-succeeds is properly set --- bob/devtools/release.py | 15 +++++++-------- bob/devtools/scripts/commitfile.py | 10 ++++++---- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/bob/devtools/release.py b/bob/devtools/release.py index a1cc6cdd..ba7e0e38 100644 --- a/bob/devtools/release.py +++ b/bob/devtools/release.py @@ -229,7 +229,7 @@ def update_tag_comments(gitpkg, tag_name, tag_comments_list, dry_run=False): def update_files_with_mr(gitpkg, files_dict, message, branch, automerge, - dry_run): + dry_run, user_id): """Update (via a commit) files of a given gitlab package, through an MR This function can update a file in a gitlab package, but will do this @@ -244,6 +244,7 @@ def update_files_with_mr(gitpkg, files_dict, message, branch, automerge, automerge: If we should set the "merge if build suceeds" flag on the created MR dry_run: If True, nothing will be pushed to gitlab + user_id: The integer which numbers the user to attribute this MR to """ @@ -268,17 +269,15 @@ def update_files_with_mr(gitpkg, files_dict, message, branch, automerge, logger.debug("Creating merge request %s -> master", branch) logger.debug("Set merge-when-pipeline-succeeds = %s", automerge) if not dry_run: - mr = project.mergerequests.create({ + mr = gitpkg.mergerequests.create({ 'source_branch': branch, 'target_branch': 'master', 'title': message, + 'remove_source_branch': True, + 'assignee_id': user_id, }) - accept = { - 'merge_when_pipeline_succeeds': 'true' if automerge else 'false', - 'should_remove_source_branch': 'true', - } - mr.merge(accept) - + time.sleep(0.5) # to avoid the MR to be merged automatically - bug? + mr.merge(merge_when_pipeline_succeeds=automerge) def update_files_at_master(gitpkg, files_dict, message, dry_run): diff --git a/bob/devtools/scripts/commitfile.py b/bob/devtools/scripts/commitfile.py index c1e9cae3..66303197 100644 --- a/bob/devtools/scripts/commitfile.py +++ b/bob/devtools/scripts/commitfile.py @@ -57,6 +57,8 @@ def commitfile(package, message, file, path, branch, auto_merge, dry_run): raise RuntimeError('PACKAGE should be specified as "group/name"') gl = get_gitlab_instance() + gl.auth() + user_id = gl.user.attributes['id'] # we lookup the gitlab package once use_package = gl.projects.get(package) @@ -75,10 +77,10 @@ def commitfile(package, message, file, path, branch, auto_merge, dry_run): contents = f.read() components = os.path.splitext(path)[0].split(os.sep) - branch = 'update-%s' % components[-1].lower() - message = message or ("[%s] update" % \ - ''.join(['[%s]' % k for k in components])) + branch = branch or 'update-%s' % components[-1].lower() + message = message or ("%s update" % \ + ''.join(['[%s]' % k.lower() for k in components])) # commit and push changes update_files_with_mr(use_package, {path: contents}, message, branch, - auto_merge, dry_run) + auto_merge, dry_run, user_id) -- GitLab