| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,6 +27,11 @@ Get a single protected branch:: | |||
| 27 | 27 | ||
| 28 | 28 | p_branch = project.protectedbranches.get('main') | |
| 29 | 29 | ||
| 30 | + Update a protected branch: | ||
| 31 | + | ||
| 32 | + p_branch.allow_force_push = True | ||
| 33 | + p_branch.save() | ||
| 34 | + | ||
| 30 | 35 | Create a protected branch:: | |
| 31 | 36 | ||
| 32 | 37 | p_branch = project.protectedbranches.create({ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,13 @@ | |||
| 1 | 1 | from typing import Any, cast, Union | |
| 2 | 2 | ||
| 3 | 3 | from gitlab.base import RESTManager, RESTObject | |
| 4 | - from gitlab.mixins import NoUpdateMixin, ObjectDeleteMixin | ||
| 4 | + from gitlab.mixins import ( | ||
| 5 | + CRUDMixin, | ||
| 6 | + NoUpdateMixin, | ||
| 7 | + ObjectDeleteMixin, | ||
| 8 | + SaveMixin, | ||
| 9 | + UpdateMethod, | ||
| 10 | + ) | ||
| 5 | 11 | from gitlab.types import RequiredOptional | |
| 6 | 12 | ||
| 7 | 13 | __all__ = [ | |
@@ -28,11 +34,11 @@ def get( | |||
| 28 | 34 | return cast(ProjectBranch, super().get(id=id, lazy=lazy, **kwargs)) | |
| 29 | 35 | ||
| 30 | 36 | ||
| 31 | - class ProjectProtectedBranch(ObjectDeleteMixin, RESTObject): | ||
| 37 | + class ProjectProtectedBranch(SaveMixin, ObjectDeleteMixin, RESTObject): | ||
| 32 | 38 | _id_attr = "name" | |
| 33 | 39 | ||
| 34 | 40 | ||
| 35 | - class ProjectProtectedBranchManager(NoUpdateMixin, RESTManager): | ||
| 41 | + class ProjectProtectedBranchManager(CRUDMixin, RESTManager): | ||
| 36 | 42 | _path = "/projects/{project_id}/protected_branches" | |
| 37 | 43 | _obj_cls = ProjectProtectedBranch | |
| 38 | 44 | _from_parent_attrs = {"project_id": "id"} | |
@@ -49,6 +55,7 @@ class ProjectProtectedBranchManager(NoUpdateMixin, RESTManager): | |||
| 49 | 55 | "code_owner_approval_required", | |
| 50 | 56 | ), | |
| 51 | 57 | ) | |
| 58 | + _update_method = UpdateMethod.PATCH | ||
| 52 | 59 | ||
| 53 | 60 | def get( | |
| 54 | 61 | self, id: Union[str, int], lazy: bool = False, **kwargs: Any | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -258,12 +258,31 @@ def test_project_pages_domains(gl, project): | |||
| 258 | 258 | assert domain not in project.pagesdomains.list() | |
| 259 | 259 | ||
| 260 | 260 | ||
| 261 | - def test_project_protected_branches(project): | ||
| 262 | - p_b = project.protectedbranches.create({"name": "*-stable"}) | ||
| 261 | + def test_project_protected_branches(project, wait_for_sidekiq, gitlab_version): | ||
| 262 | + # Updating a protected branch is possible from Gitlab 15.6 | ||
| 263 | + # https://docs.gitlab.com/ee/api/protected_branches.html#update-a-protected-branch | ||
| 264 | + can_update_prot_branch = gitlab_version.major > 15 or ( | ||
| 265 | + gitlab_version.major == 15 and gitlab_version.minor >= 6 | ||
| 266 | + ) | ||
| 267 | + | ||
| 268 | + p_b = project.protectedbranches.create( | ||
| 269 | + { | ||
| 270 | + "name": "*-stable", | ||
| 271 | + "allow_force_push": False, | ||
| 272 | + } | ||
| 273 | + ) | ||
| 263 | 274 | assert p_b.name == "*-stable" | |
| 275 | + assert not p_b.allow_force_push | ||
| 264 | 276 | assert p_b in project.protectedbranches.list() | |
| 265 | 277 | ||
| 278 | + if can_update_prot_branch: | ||
| 279 | + p_b.allow_force_push = True | ||
| 280 | + p_b.save() | ||
| 281 | + wait_for_sidekiq(timeout=60) | ||
| 282 | + | ||
| 266 | 283 | p_b = project.protectedbranches.get("*-stable") | |
| 284 | + if can_update_prot_branch: | ||
| 285 | + assert p_b.allow_force_push | ||
| 267 | 286 | p_b.delete() | |
| 268 | 287 | assert p_b not in project.protectedbranches.list() | |
| 269 | 288 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments