| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c59fbdb commit 9656a16
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,21 +35,8 @@ Delete a repository branch:: | |||
| 35 | 35 | # or | |
| 36 | 36 | branch.delete() | |
| 37 | 37 | ||
| 38 | - Protect/unprotect a repository branch:: | ||
| 39 | - | ||
| 40 | - branch.protect() | ||
| 41 | - branch.unprotect() | ||
| 42 | - | ||
| 43 | - .. note:: | ||
| 44 | - | ||
| 45 | - By default, developers are not authorized to push or merge into protected | ||
| 46 | - branches. This can be changed by passing ``developers_can_push`` or | ||
| 47 | - ``developers_can_merge``: | ||
| 48 | - | ||
| 49 | - .. code-block:: python | ||
| 50 | - | ||
| 51 | - branch.protect(developers_can_push=True, developers_can_merge=True) | ||
| 52 | - | ||
| 53 | 38 | Delete the merged branches for a project:: | |
| 54 | 39 | ||
| 55 | 40 | project.delete_merged_branches() | |
| 41 | + | ||
| 42 | + To manage protected branches, see :doc:`/gl_objects/protected_branches`. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,3 @@ | |||
| 1 | - from gitlab import cli | ||
| 2 | - from gitlab import exceptions as exc | ||
| 3 | 1 | from gitlab.base import RequiredOptional, RESTManager, RESTObject | |
| 4 | 2 | from gitlab.mixins import NoUpdateMixin, ObjectDeleteMixin | |
| 5 | 3 | ||
@@ -14,50 +12,6 @@ | |||
| 14 | 12 | class ProjectBranch(ObjectDeleteMixin, RESTObject): | |
| 15 | 13 | _id_attr = "name" | |
| 16 | 14 | ||
| 17 | - @cli.register_custom_action( | ||
| 18 | - "ProjectBranch", tuple(), ("developers_can_push", "developers_can_merge") | ||
| 19 | - ) | ||
| 20 | - @exc.on_http_error(exc.GitlabProtectError) | ||
| 21 | - def protect(self, developers_can_push=False, developers_can_merge=False, **kwargs): | ||
| 22 | - """Protect the branch. | ||
| 23 | - | ||
| 24 | - Args: | ||
| 25 | - developers_can_push (bool): Set to True if developers are allowed | ||
| 26 | - to push to the branch | ||
| 27 | - developers_can_merge (bool): Set to True if developers are allowed | ||
| 28 | - to merge to the branch | ||
| 29 | - **kwargs: Extra options to send to the server (e.g. sudo) | ||
| 30 | - | ||
| 31 | - Raises: | ||
| 32 | - GitlabAuthenticationError: If authentication is not correct | ||
| 33 | - GitlabProtectError: If the branch could not be protected | ||
| 34 | - """ | ||
| 35 | - id = self.get_id().replace("/", "%2F") | ||
| 36 | - path = "%s/%s/protect" % (self.manager.path, id) | ||
| 37 | - post_data = { | ||
| 38 | - "developers_can_push": developers_can_push, | ||
| 39 | - "developers_can_merge": developers_can_merge, | ||
| 40 | - } | ||
| 41 | - self.manager.gitlab.http_put(path, post_data=post_data, **kwargs) | ||
| 42 | - self._attrs["protected"] = True | ||
| 43 | - | ||
| 44 | - @cli.register_custom_action("ProjectBranch") | ||
| 45 | - @exc.on_http_error(exc.GitlabProtectError) | ||
| 46 | - def unprotect(self, **kwargs): | ||
| 47 | - """Unprotect the branch. | ||
| 48 | - | ||
| 49 | - Args: | ||
| 50 | - **kwargs: Extra options to send to the server (e.g. sudo) | ||
| 51 | - | ||
| 52 | - Raises: | ||
| 53 | - GitlabAuthenticationError: If authentication is not correct | ||
| 54 | - GitlabProtectError: If the branch could not be unprotected | ||
| 55 | - """ | ||
| 56 | - id = self.get_id().replace("/", "%2F") | ||
| 57 | - path = "%s/%s/unprotect" % (self.manager.path, id) | ||
| 58 | - self.manager.gitlab.http_put(path, **kwargs) | ||
| 59 | - self._attrs["protected"] = False | ||
| 60 | - | ||
| 61 | 15 | ||
| 62 | 16 | class ProjectBranchManager(NoUpdateMixin, RESTManager): | |
| 63 | 17 | _path = "/projects/%(project_id)s/repository/branches" | |
| Back | FazBrowse Home | New Git URL |
0 commit comments