Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5f03160

Browse files
committed
feat(groups): add protectedbranches to group class (#3164)
1 parent10ee58a commit5f03160

File tree

4 files changed

+67
-3
lines changed

4 files changed

+67
-3
lines changed

‎docs/gl_objects/protected_branches.rst

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
Protected branches
33
##################
44

5-
You can define a list of protected branch names on a repository. Names can use
6-
wildcards (``*``).
5+
You can define a list of protected branch names on a repository or group.
6+
Names can usewildcards (``*``).
77

88
References
99
----------
@@ -13,19 +13,24 @@ References
1313
+:class:`gitlab.v4.objects.ProjectProtectedBranch`
1414
+:class:`gitlab.v4.objects.ProjectProtectedBranchManager`
1515
+:attr:`gitlab.v4.objects.Project.protectedbranches`
16+
+:class:`gitlab.v4.objects.GroupProtectedBranch`
17+
+:class:`gitlab.v4.objects.GroupProtectedBranchManager`
18+
+:attr:`gitlab.v4.objects.Group.protectedbranches`
1619

1720
* GitLab API: https://docs.gitlab.com/ce/api/protected_branches.html#protected-branches-api
1821

1922
Examples
2023
--------
2124

22-
Get the list of protected branches for a project::
25+
Get the list of protected branches for a project or group::
2326

2427
p_branches = project.protectedbranches.list()
28+
p_branches = group.protectedbranches.list()
2529

2630
Get a single protected branch::
2731

2832
p_branch = project.protectedbranches.get('main')
33+
p_branch = group.protectedbranches.get('main')
2934

3035
Update a protected branch::
3136

‎gitlab/v4/objects/branches.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,32 @@ def get(
6161
self,id:Union[str,int],lazy:bool=False,**kwargs:Any
6262
)->ProjectProtectedBranch:
6363
returncast(ProjectProtectedBranch,super().get(id=id,lazy=lazy,**kwargs))
64+
65+
66+
classGroupProtectedBranch(SaveMixin,ObjectDeleteMixin,RESTObject):
67+
_id_attr="name"
68+
69+
70+
classGroupProtectedBranchManager(CRUDMixin,RESTManager):
71+
_path="/groups/{group_id}/protected_branches"
72+
_obj_cls=GroupProtectedBranch
73+
_from_parent_attrs= {"group_id":"id"}
74+
_create_attrs=RequiredOptional(
75+
required=("name",),
76+
optional=(
77+
"push_access_level",
78+
"merge_access_level",
79+
"unprotect_access_level",
80+
"allow_force_push",
81+
"allowed_to_push",
82+
"allowed_to_merge",
83+
"allowed_to_unprotect",
84+
"code_owner_approval_required",
85+
),
86+
)
87+
_update_method=UpdateMethod.PATCH
88+
89+
defget(
90+
self,id:Union[str,int],lazy:bool=False,**kwargs:Any
91+
)->GroupProtectedBranch:
92+
returncast(GroupProtectedBranch,super().get(id=id,lazy=lazy,**kwargs))

‎gitlab/v4/objects/groups.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from .audit_eventsimportGroupAuditEventManager# noqa: F401
2323
from .badgesimportGroupBadgeManager# noqa: F401
2424
from .boardsimportGroupBoardManager# noqa: F401
25+
from .branchesimportGroupProtectedBranchManager# noqa: F401
2526
from .clustersimportGroupClusterManager# noqa: F401
2627
from .container_registryimportGroupRegistryRepositoryManager# noqa: F401
2728
from .custom_attributesimportGroupCustomAttributeManager# noqa: F401
@@ -96,6 +97,7 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject):
9697
packages:GroupPackageManager
9798
projects:GroupProjectManager
9899
shared_projects:SharedProjectManager
100+
protectedbranches:GroupProtectedBranchManager
99101
pushrules:GroupPushRulesManager
100102
registry_repositories:GroupRegistryRepositoryManager
101103
runners:GroupRunnerManager

‎tests/functional/api/test_groups.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,34 @@ def test_group_hooks(group):
284284
hook.delete()
285285

286286

287+
deftest_group_protected_branches(group,gitlab_version):
288+
# Updating a protected branch at the group level is possible from Gitlab 15.9
289+
# https://docs.gitlab.com/api/group_protected_branches/
290+
can_update_prot_branch=gitlab_version.major>15or (
291+
gitlab_version.major==15andgitlab_version.minor>=9
292+
)
293+
294+
p_b=group.protectedbranches.create(
295+
{
296+
"name":"*-stable",
297+
"allow_force_push":False,
298+
}
299+
)
300+
assertp_b.name=="*-stable"
301+
assertnotp_b.allow_force_push
302+
assertp_bingroup.protectedbranches.list()
303+
304+
ifcan_update_prot_branch:
305+
p_b.allow_force_push=True
306+
p_b.save()
307+
308+
p_b=group.protectedbranches.get("*-stable")
309+
ifcan_update_prot_branch:
310+
assertp_b.allow_force_push
311+
312+
p_b.delete()
313+
314+
287315
deftest_group_transfer(gl,group):
288316
transfer_group=gl.groups.create(
289317
{"name":"transfer-test-group","path":"transfer-test-group"}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp