Skip to content
Snippets Groups Projects
Commit 83002e07 authored by Tim Jaacks's avatar Tim Jaacks
Browse files

accept_merge_request: explicitly check if MR has merge conflicts

According to the documentation [1] we should get a 406 error from the
API if we try to merge a merge request which has a merge conflict. We
are experiencing a different behaviour, though, where we are getting a
405 error in this case. There is an open GitLab issue on this topic [2].

In our error handling we assumed that the reason for a 405 error is most
likely a required pipeline which is still running. This assumtion,
however, leads to wrong behaviour in cases where no pipeline is started
at all.

Fixing this now by explicitly checking for merge conflicts at the very
beginning of the error handling sequence.

[1]: https://docs.gitlab.com/ee/api/merge_requests.html#merge-a-merge-request
[2]: https://gitlab.com/gitlab-org/gitlab/-/issues/364102
parent 0885629d
No related branches found
No related tags found
1 merge request!156accept_merge_request: explicitly check if MR has merge conflicts
Pipeline #18946 waiting for manual action with stages
in 7 minutes and 5 seconds
......@@ -56,6 +56,17 @@ def accept_merge_request(project, mr, rebase=False, should_remove_source_branch=
if e.response_code == 405:
# Not allowed (draft, closed, pipeline pending or failed)
# Contrary to the documentation, this response is also issued when the
# merge failed due to a merge conflict. See GitLab issue:
# https://gitlab.com/gitlab-org/gitlab/-/issues/364102
if mr.has_conflicts:
# Merge conflict, automatic rebase not possible
if pipeline_pending:
print("")
print("Merge not possible, has to be rebased manually")
return False, mr.sha
# If pipeline is running, wait for completion
if not mr.head_pipeline:
# No pipeline created yet
......@@ -69,10 +80,10 @@ def accept_merge_request(project, mr, rebase=False, should_remove_source_branch=
print(".", end="", flush=True)
time.sleep(1)
else:
# Merge conflict, automatic rebase not possible
# Merge failed due to some other reason
if pipeline_pending:
print("")
print("Merge not possible, has to be rebased manually")
print("Merge not possible for unkown reason")
return False, mr.sha
elif e.response_code == 406:
......
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