Skip to content

Problem setting protection for branch with naming "<part1>/<part2>" #493

Closed
@kduchno

Description

@kduchno

Description of the problem, including code/CLI snippet

Hi,
I wanted to set protection for branch "strange/stranger" - naming not important, but "/" (slash) is super important.

I was able to create such branch, get such branch from project, but setting protection raises exceptions.

image

import gitlab.exceptions

# of course gitlab connection is set and auth() without problems
# connection is set not to use SSL and to use token - root almighty token
gitlab_projects = gitlab.projects.list(search="test_project_1")
project = gitlab_projects[0]  # I know for certain there is only one project

project_branches = project.branches.list()
for project_branch in project_branches:
    print("Setting protection for branch {}".format(branch_name))
    try:
        project_branch.protect(
            developers_can_push=False,
            developers_can_merge=False
        )
    except gitlab.exceptions.GitlabProtectError as e:
        print("Exception caught while setting protection "
                "for branch {} -> {} -> branch protection skipped, rest "
                "will proceed as usual"
                .format(branch_name, e.__str__()))

Recreate

Just create any project with at least two branches like master and "something/something"

Expected Behavior

No exception throw and no message.

Actual Behavior

Setting protection for branch strange/stranger
Exception caught while setting protection for branch strange/stranger -> 404: b'{"error":"404 Not Found"}' -> branch protection skipped, rest will proceed as usual

Or without try - except block:

Setting protection for branch strange/stranger
Traceback (most recent call last):
  File "/home/kduchno/Envs/pythoning/lib/python3.6/site-packages/gitlab/exceptions.py", line 251, in wrapped_f
    return f(*args, **kwargs)
  File "/home/kduchno/Envs/pythoning/lib/python3.6/site-packages/gitlab/v4/objects.py", line 874, in protect
    self.manager.gitlab.http_put(path, post_data=post_data, **kwargs)
  File "/home/kduchno/Envs/pythoning/lib/python3.6/site-packages/gitlab/__init__.py", line 827, in http_put
    post_data=post_data, **kwargs)
  File "/home/kduchno/Envs/pythoning/lib/python3.6/site-packages/gitlab/__init__.py", line 706, in http_request
    response_body=result.content)
gitlab.exceptions.GitlabHttpError: 404: b'{"error":"404 Not Found"}'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "main.py", line 155, in <module>
    __create_additional_branches_in_project(project)
  File "main.py", line 123, in __create_additional_branches_in_project
    __setup_branch_protection_in_project(project, branches)
  File "main.py", line 81, in __setup_branch_protection_in_project
    developers_can_merge=dev_merge
  File "/home/kduchno/Envs/pythoning/lib/python3.6/site-packages/gitlab/cli.py", line 42, in wrapped_f
    return f(*args, **kwargs)
  File "/home/kduchno/Envs/pythoning/lib/python3.6/site-packages/gitlab/exceptions.py", line 253, in wrapped_f
    raise error(e.error_message, e.response_code, e.response_body)
gitlab.exceptions.GitlabProtectError: 404: b'{"error":"404 Not Found"}'

Specifications

  • python-gitlab version: 1.3.0
  • python version: 3.6.5
  • API version you are using (v3/v4): v4
  • Gitlab server version (or gitlab.com): GitLab Community Edition 10.7.1

Aditional notes

I tried filtering open and closed issues, but either I am blind (then I am sorry and please link issue) or filter couldn't find.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions