Skip to content

refactor(objects): remove deprecated branch protect methods #1598

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

Merged
merged 1 commit into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions docs/gl_objects/branches.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,8 @@ Delete a repository branch::
# or
branch.delete()

Protect/unprotect a repository branch::

branch.protect()
branch.unprotect()

.. note::

By default, developers are not authorized to push or merge into protected
branches. This can be changed by passing ``developers_can_push`` or
``developers_can_merge``:

.. code-block:: python

branch.protect(developers_can_push=True, developers_can_merge=True)

Delete the merged branches for a project::

project.delete_merged_branches()

To manage protected branches, see :doc:`/gl_objects/protected_branches`.
46 changes: 0 additions & 46 deletions gitlab/v4/objects/branches.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from gitlab import cli
from gitlab import exceptions as exc
from gitlab.base import RequiredOptional, RESTManager, RESTObject
from gitlab.mixins import NoUpdateMixin, ObjectDeleteMixin

Expand All @@ -14,50 +12,6 @@
class ProjectBranch(ObjectDeleteMixin, RESTObject):
_id_attr = "name"

@cli.register_custom_action(
"ProjectBranch", tuple(), ("developers_can_push", "developers_can_merge")
)
@exc.on_http_error(exc.GitlabProtectError)
def protect(self, developers_can_push=False, developers_can_merge=False, **kwargs):
"""Protect the branch.

Args:
developers_can_push (bool): Set to True if developers are allowed
to push to the branch
developers_can_merge (bool): Set to True if developers are allowed
to merge to the branch
**kwargs: Extra options to send to the server (e.g. sudo)

Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabProtectError: If the branch could not be protected
"""
id = self.get_id().replace("/", "%2F")
path = "%s/%s/protect" % (self.manager.path, id)
post_data = {
"developers_can_push": developers_can_push,
"developers_can_merge": developers_can_merge,
}
self.manager.gitlab.http_put(path, post_data=post_data, **kwargs)
self._attrs["protected"] = True

@cli.register_custom_action("ProjectBranch")
@exc.on_http_error(exc.GitlabProtectError)
def unprotect(self, **kwargs):
"""Unprotect the branch.

Args:
**kwargs: Extra options to send to the server (e.g. sudo)

Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabProtectError: If the branch could not be unprotected
"""
id = self.get_id().replace("/", "%2F")
path = "%s/%s/unprotect" % (self.manager.path, id)
self.manager.gitlab.http_put(path, **kwargs)
self._attrs["protected"] = False


class ProjectBranchManager(NoUpdateMixin, RESTManager):
_path = "/projects/%(project_id)s/repository/branches"
Expand Down