summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/api-objects.rst1
-rw-r--r--docs/gl_objects/branches.py18
-rw-r--r--gitlab/v4/objects.py12
-rw-r--r--tools/python_test_v4.py10
4 files changed, 41 insertions, 0 deletions
diff --git a/docs/api-objects.rst b/docs/api-objects.rst
index 78b9646..4b40ce1 100644
--- a/docs/api-objects.rst
+++ b/docs/api-objects.rst
@@ -7,6 +7,7 @@ API examples
gl_objects/access_requests
gl_objects/branches
+ gl_objects/protected_branches
gl_objects/messages
gl_objects/builds
gl_objects/commits
diff --git a/docs/gl_objects/branches.py b/docs/gl_objects/branches.py
index b80dfc0..431e09d 100644
--- a/docs/gl_objects/branches.py
+++ b/docs/gl_objects/branches.py
@@ -26,3 +26,21 @@ branch.delete()
branch.protect()
branch.unprotect()
# end protect
+
+# p_branch list
+p_branches = project.protectedbranches.list()
+# end p_branch list
+
+# p_branch get
+p_branch = project.protectedbranches.get('master')
+# end p_branch get
+
+# p_branch create
+p_branch = project.protectedbranches.create({'name': '*-stable'})
+# end p_branch create
+
+# p_branch delete
+project.protectedbranches.delete('*-stable')
+# or
+p_branch.delete()
+# end p_branch delete
diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py
index 92c4543..bf79deb 100644
--- a/gitlab/v4/objects.py
+++ b/gitlab/v4/objects.py
@@ -1732,6 +1732,17 @@ class ProjectDeploymentManager(RetrieveMixin, RESTManager):
_from_parent_attrs = {'project_id': 'id'}
+class ProjectProtectedBranch(ObjectDeleteMixin, RESTObject):
+ _id_attr = 'name'
+
+
+class ProjectProtectedBranchManager(NoUpdateMixin, RESTManager):
+ _path = '/projects/%(project_id)s/protected_branches'
+ _obj_cls = ProjectProtectedBranch
+ _from_parent_attrs = {'project_id': 'id'}
+ _create_attrs = (('name', ), ('push_access_level', 'merge_access_level'))
+
+
class ProjectRunner(ObjectDeleteMixin, RESTObject):
pass
@@ -1767,6 +1778,7 @@ class Project(SaveMixin, ObjectDeleteMixin, RESTObject):
('notes', 'ProjectNoteManager'),
('notificationsettings', 'ProjectNotificationSettingsManager'),
('pipelines', 'ProjectPipelineManager'),
+ ('protectedbranches', 'ProjectProtectedBranchManager'),
('runners', 'ProjectRunnerManager'),
('services', 'ProjectServiceManager'),
('snippets', 'ProjectSnippetManager'),
diff --git a/tools/python_test_v4.py b/tools/python_test_v4.py
index 0cbea33..2113830 100644
--- a/tools/python_test_v4.py
+++ b/tools/python_test_v4.py
@@ -394,6 +394,16 @@ try:
except gitlab.GitlabMRClosedError:
pass
+# protected branches
+p_b = admin_project.protectedbranches.create({'name': '*-stable'})
+assert(p_b.name == '*-stable')
+p_b = admin_project.protectedbranches.get('*-stable')
+# master is protected by default
+assert(len(admin_project.protectedbranches.list()) == 2)
+admin_project.protectedbranches.delete('master')
+p_b.delete()
+assert(len(admin_project.protectedbranches.list()) == 0)
+
# stars
admin_project.star()
assert(admin_project.star_count == 1)