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

Commita867c48

Browse files
authored
feat(api): allow updating protected branches (#2771)
* feat(api): allow updating protected branchesCloses#2390
1 parent9440a32 commita867c48

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

‎docs/gl_objects/protected_branches.rst‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ Get a single protected branch::
2727

2828
p_branch = project.protectedbranches.get('main')
2929

30+
Update a protected branch:
31+
32+
p_branch.allow_force_push = True
33+
p_branch.save()
34+
3035
Create a protected branch::
3136

3237
p_branch = project.protectedbranches.create({

‎gitlab/v4/objects/branches.py‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
fromtypingimportAny,cast,Union
22

33
fromgitlab.baseimportRESTManager,RESTObject
4-
fromgitlab.mixinsimportNoUpdateMixin,ObjectDeleteMixin
4+
fromgitlab.mixinsimport (
5+
CRUDMixin,
6+
NoUpdateMixin,
7+
ObjectDeleteMixin,
8+
SaveMixin,
9+
UpdateMethod,
10+
)
511
fromgitlab.typesimportRequiredOptional
612

713
__all__= [
@@ -28,11 +34,11 @@ def get(
2834
returncast(ProjectBranch,super().get(id=id,lazy=lazy,**kwargs))
2935

3036

31-
classProjectProtectedBranch(ObjectDeleteMixin,RESTObject):
37+
classProjectProtectedBranch(SaveMixin,ObjectDeleteMixin,RESTObject):
3238
_id_attr="name"
3339

3440

35-
classProjectProtectedBranchManager(NoUpdateMixin,RESTManager):
41+
classProjectProtectedBranchManager(CRUDMixin,RESTManager):
3642
_path="/projects/{project_id}/protected_branches"
3743
_obj_cls=ProjectProtectedBranch
3844
_from_parent_attrs= {"project_id":"id"}
@@ -49,6 +55,7 @@ class ProjectProtectedBranchManager(NoUpdateMixin, RESTManager):
4955
"code_owner_approval_required",
5056
),
5157
)
58+
_update_method=UpdateMethod.PATCH
5259

5360
defget(
5461
self,id:Union[str,int],lazy:bool=False,**kwargs:Any

‎tests/functional/api/test_projects.py‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,31 @@ def test_project_pages_domains(gl, project):
258258
assertdomainnotinproject.pagesdomains.list()
259259

260260

261-
deftest_project_protected_branches(project):
262-
p_b=project.protectedbranches.create({"name":"*-stable"})
261+
deftest_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>15or (
265+
gitlab_version.major==15andgitlab_version.minor>=6
266+
)
267+
268+
p_b=project.protectedbranches.create(
269+
{
270+
"name":"*-stable",
271+
"allow_force_push":False,
272+
}
273+
)
263274
assertp_b.name=="*-stable"
275+
assertnotp_b.allow_force_push
264276
assertp_binproject.protectedbranches.list()
265277

278+
ifcan_update_prot_branch:
279+
p_b.allow_force_push=True
280+
p_b.save()
281+
wait_for_sidekiq(timeout=60)
282+
266283
p_b=project.protectedbranches.get("*-stable")
284+
ifcan_update_prot_branch:
285+
assertp_b.allow_force_push
267286
p_b.delete()
268287
assertp_bnotinproject.protectedbranches.list()
269288

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp