Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I differentiate between "405 Method Not Allowed" due to the source branch not being updated or due to conflicts? #2854

Closed
zj5220924 opened this issue May 6, 2024 · 1 comment
Labels

Comments

@zj5220924
Copy link

python 3.10
python-gitlab 4.4.0

def merge_git_branch(self, project_id, source_branch, target_branch):
    try:
        project = self.gl.projects.get(project_id)
        merge_request = project.mergerequests.create(
            {
                'source_branch': source_branch,
                'target_branch': target_branch,
                'title': 'Merge ' + source_branch + ' into ' + target_branch
            }
        )
        print(merge_request.merge_status)
        print(merge_request.iid)
        for _ in range(60):
            if merge_request.merge_status != "checking":
                break
            time.sleep(0.5)
        merge_request.save()
        merge_request.merge()
        print('Merge ' + source_branch + ' into ' + target_branch + ' done.')
    except Exception as e:
        print("Merge error:", e)

How do I differentiate between "405 Method Not Allowed" due to the source branch not being updated or due to conflicts?

@nejch
Copy link
Member

nejch commented May 27, 2024

@zj5220924 on the python-gitlab side we're just an API wrapper so unfortunately can't do much except for always checking the response messages and status code.

Here's an example of how we look at 409 status code specifically with Resource lock error messages:
https://github.com/python-gitlab/python-gitlab/blob/main/gitlab/client.py#L759

You should be able to do something similar for your use case. I'll close this issue for now but if you have any more questions feel free to reopen!

@nejch nejch closed this as completed May 27, 2024
@nejch nejch added the support label May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants