summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGauvain Pocentek <gauvain@pocentek.net>2018-01-01 15:44:47 +0100
committerGauvain Pocentek <gauvain@pocentek.net>2018-01-01 15:44:47 +0100
commitfa520242b878d25e37aacfcb0d838c58d3a4b271 (patch)
tree2d63086ba96dd02765359591beab77960bf3e844
parentf5850d950a77b1d985fdc3d1639e2627468d3548 (diff)
downloadgitlab-fa520242b878d25e37aacfcb0d838c58d3a4b271.tar.gz
Add support for project and group custom variables
implements parts of #367
-rw-r--r--docs/gl_objects/groups.rst35
-rw-r--r--docs/gl_objects/projects.rst35
-rw-r--r--docs/gl_objects/users.py18
-rw-r--r--docs/gl_objects/users.rst26
-rw-r--r--gitlab/v4/objects.py24
-rw-r--r--tools/python_test_v4.py28
6 files changed, 132 insertions, 34 deletions
diff --git a/docs/gl_objects/groups.rst b/docs/gl_objects/groups.rst
index 9006ceb..9b5edb0 100644
--- a/docs/gl_objects/groups.rst
+++ b/docs/gl_objects/groups.rst
@@ -91,6 +91,41 @@ List the subgroups for a group::
subgroups = group.subgroups.list()
+Group custom attributes
+=======================
+
+Reference
+---------
+
+* v4 API:
+
+ + :class:`gitlab.v4.objects.GroupCustomAttribute`
+ + :class:`gitlab.v4.objects.GroupCustomAttributeManager`
+ + :attr:`gitlab.v4.objects.Group.customattributes`
+
+* GitLab API: https://docs.gitlab.com/ce/api/custom_attributes.html
+
+Examples
+--------
+
+List custom attributes for a group::
+
+ attrs = group.customattributes.list()
+
+Get a custom attribute for a group::
+
+ attr = group.customattributes.get(attr_key)
+
+Set (create or update) a custom attribute for a group::
+
+ attr = group.customattributes.set(attr_key, attr_value)
+
+Delete a custom attribute for a group::
+
+ attr.delete()
+ # or
+ group.customattributes.delete(attr_key)
+
Group members
=============
diff --git a/docs/gl_objects/projects.rst b/docs/gl_objects/projects.rst
index aaf0699..b7c5d78 100644
--- a/docs/gl_objects/projects.rst
+++ b/docs/gl_objects/projects.rst
@@ -172,6 +172,41 @@ Get a list of users for the repository:
:start-after: # users list
:end-before: # end users list
+Project custom attributes
+=========================
+
+Reference
+---------
+
+* v4 API:
+
+ + :class:`gitlab.v4.objects.ProjectCustomAttribute`
+ + :class:`gitlab.v4.objects.ProjectCustomAttributeManager`
+ + :attr:`gitlab.v4.objects.Project.customattributes`
+
+* GitLab API: https://docs.gitlab.com/ce/api/custom_attributes.html
+
+Examples
+--------
+
+List custom attributes for a project::
+
+ attrs = project.customattributes.list()
+
+Get a custom attribute for a project::
+
+ attr = project.customattributes.get(attr_key)
+
+Set (create or update) a custom attribute for a project::
+
+ attr = project.customattributes.set(attr_key, attr_value)
+
+Delete a custom attribute for a project::
+
+ attr.delete()
+ # or
+ project.customattributes.delete(attr_key)
+
Project files
=============
diff --git a/docs/gl_objects/users.py b/docs/gl_objects/users.py
index e452217..842e35d 100644
--- a/docs/gl_objects/users.py
+++ b/docs/gl_objects/users.py
@@ -98,24 +98,6 @@ gl.auth()
current_user = gl.user
# end currentuser get
-# ca list
-attrs = user.customeattributes.list()
-# end ca list
-
-# ca get
-attr = user.customeattributes.get(attr_key)
-# end ca get
-
-# ca set
-attr = user.customeattributes.set(attr_key, attr_value)
-# end ca set
-
-# ca delete
-attr.delete()
-# or
-user.customeattributes.delete(attr_key)
-# end ca delete
-
# it list
i_t = user.impersonationtokens.list(state='active')
i_t = user.impersonationtokens.list(state='inactive')
diff --git a/docs/gl_objects/users.rst b/docs/gl_objects/users.rst
index e520c9b..e57daf6 100644
--- a/docs/gl_objects/users.rst
+++ b/docs/gl_objects/users.rst
@@ -89,29 +89,23 @@ References
Examples
--------
-List custom attributes for a user:
+List custom attributes for a user::
-.. literalinclude:: users.py
- :start-after: # ca list
- :end-before: # end ca list
+ attrs = user.customattributes.list()
-Get a custom attribute for a user:
+Get a custom attribute for a user::
-.. literalinclude:: users.py
- :start-after: # ca get
- :end-before: # end ca get
+ attr = user.customattributes.get(attr_key)
-Set (create or update) a custom attribute for a user:
+Set (create or update) a custom attribute for a user::
-.. literalinclude:: users.py
- :start-after: # ca set
- :end-before: # end ca set
+ attr = user.customattributes.set(attr_key, attr_value)
-Delete a custom attribute for a user:
+Delete a custom attribute for a user::
-.. literalinclude:: users.py
- :start-after: # ca list
- :end-before: # end ca list
+ attr.delete()
+ # or
+ user.customattributes.delete(attr_key)
User impersonation tokens
=========================
diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py
index 0a0cebd..106b102 100644
--- a/gitlab/v4/objects.py
+++ b/gitlab/v4/objects.py
@@ -461,6 +461,17 @@ class GroupAccessRequestManager(GetFromListMixin, CreateMixin, DeleteMixin,
_from_parent_attrs = {'group_id': 'id'}
+class GroupCustomAttribute(ObjectDeleteMixin, RESTObject):
+ _id_attr = 'key'
+
+
+class GroupCustomAttributeManager(RetrieveMixin, SetMixin, DeleteMixin,
+ RESTManager):
+ _path = '/groups/%(group_id)s/custom_attributes'
+ _obj_cls = GroupCustomAttribute
+ _from_parent_attrs = {'group_id': 'id'}
+
+
class GroupIssue(RESTObject):
pass
@@ -614,6 +625,7 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject):
_short_print_attr = 'name'
_managers = (
('accessrequests', 'GroupAccessRequestManager'),
+ ('customattributes', 'GroupCustomAttributeManager'),
('issues', 'GroupIssueManager'),
('members', 'GroupMemberManager'),
('milestones', 'GroupMilestoneManager'),
@@ -839,6 +851,17 @@ class ProjectBranchManager(NoUpdateMixin, RESTManager):
_create_attrs = (('branch', 'ref'), tuple())
+class ProjectCustomAttribute(ObjectDeleteMixin, RESTObject):
+ _id_attr = 'key'
+
+
+class ProjectCustomAttributeManager(RetrieveMixin, SetMixin, DeleteMixin,
+ RESTManager):
+ _path = '/projects/%(project_id)s/custom_attributes'
+ _obj_cls = ProjectCustomAttribute
+ _from_parent_attrs = {'project_id': 'id'}
+
+
class ProjectJob(RESTObject):
@cli.register_custom_action('ProjectJob')
@exc.on_http_error(exc.GitlabJobCancelError)
@@ -2200,6 +2223,7 @@ class Project(SaveMixin, ObjectDeleteMixin, RESTObject):
('branches', 'ProjectBranchManager'),
('jobs', 'ProjectJobManager'),
('commits', 'ProjectCommitManager'),
+ ('customattributes', 'ProjectCustomAttributeManager'),
('deployments', 'ProjectDeploymentManager'),
('environments', 'ProjectEnvironmentManager'),
('events', 'ProjectEventManager'),
diff --git a/tools/python_test_v4.py b/tools/python_test_v4.py
index 9a3d5e7..4af9ea9 100644
--- a/tools/python_test_v4.py
+++ b/tools/python_test_v4.py
@@ -230,6 +230,20 @@ assert(member.access_level == gitlab.Group.OWNER_ACCESS)
group2.members.delete(gl.user.id)
+# group custom attributes
+attrs = group2.customattributes.list()
+assert(len(attrs) == 0)
+attr = group2.customattributes.set('key', 'value1')
+assert(attr.key == 'key')
+assert(attr.value == 'value1')
+assert(len(group2.customattributes.list()) == 1)
+attr = group2.customattributes.set('key', 'value2')
+attr = group2.customattributes.get('key')
+assert(attr.value == 'value2')
+assert(len(group2.customattributes.list()) == 1)
+attr.delete()
+assert(len(group2.customattributes.list()) == 0)
+
# group notification settings
settings = group2.notificationsettings.get()
settings.level = 'disabled'
@@ -285,6 +299,20 @@ assert(len(l1) == 1)
assert(len(l2) == 1)
assert(l1[0].id != l2[0].id)
+# group custom attributes
+attrs = admin_project.customattributes.list()
+assert(len(attrs) == 0)
+attr = admin_project.customattributes.set('key', 'value1')
+assert(attr.key == 'key')
+assert(attr.value == 'value1')
+assert(len(admin_project.customattributes.list()) == 1)
+attr = admin_project.customattributes.set('key', 'value2')
+attr = admin_project.customattributes.get('key')
+assert(attr.value == 'value2')
+assert(len(admin_project.customattributes.list()) == 1)
+attr.delete()
+assert(len(admin_project.customattributes.list()) == 0)
+
# project pages domains
domain = admin_project.pagesdomains.create({'domain': 'foo.domain.com'})
assert(len(admin_project.pagesdomains.list()) == 1)