0
votes

I have everything set up to create a branch, make a merge request, commit and merge the request, but it seems to fail on the last step. The commit gets through to gitlab, but the merge request fails with the exception from the title.

Example below;

import gitlab
gl = gitlab.Gitlab.from_config()
project = gl.projects.get(...)
branch = project.branches.create(...)

mr_data = dict(source_branch=branch.name, target_branch='master', title='title')
merge_request = project.mergerequests.create(mr_data)
action = dict(action='create', file_path='test.txt', content='test')
data = dict(branch=branch.name, commit_message='test', actions=[action])
commit = project.commits.create(data)

merge_request.merge()    <<< fails here

Weirdly, when I try to merge the request later from a console, it merges fine. Any ideas what could be the issue here?

1

1 Answers

0
votes

In the end, this seemed to be the gitlab server unable to keep up with the python script. Simply adding a time.sleep(1) between the commit and the merge seemed to do the trick.