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

Commitfa52024

Browse files
author
Gauvain Pocentek
committed
Add support for project and group custom variables
implements parts of#367
1 parentf5850d9 commitfa52024

File tree

6 files changed

+132
-34
lines changed

6 files changed

+132
-34
lines changed

‎docs/gl_objects/groups.rst

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,41 @@ List the subgroups for a group::
9191

9292
subgroups = group.subgroups.list()
9393

94+
Group custom attributes
95+
=======================
96+
97+
Reference
98+
---------
99+
100+
* v4 API:
101+
102+
+:class:`gitlab.v4.objects.GroupCustomAttribute`
103+
+:class:`gitlab.v4.objects.GroupCustomAttributeManager`
104+
+:attr:`gitlab.v4.objects.Group.customattributes`
105+
106+
* GitLab API: https://docs.gitlab.com/ce/api/custom_attributes.html
107+
108+
Examples
109+
--------
110+
111+
List custom attributes for a group::
112+
113+
attrs = group.customattributes.list()
114+
115+
Get a custom attribute for a group::
116+
117+
attr = group.customattributes.get(attr_key)
118+
119+
Set (create or update) a custom attribute for a group::
120+
121+
attr = group.customattributes.set(attr_key, attr_value)
122+
123+
Delete a custom attribute for a group::
124+
125+
attr.delete()
126+
# or
127+
group.customattributes.delete(attr_key)
128+
94129
Group members
95130
=============
96131

‎docs/gl_objects/projects.rst

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,41 @@ Get a list of users for the repository:
172172
:start-after: # users list
173173
:end-before: # end users list
174174

175+
Project custom attributes
176+
=========================
177+
178+
Reference
179+
---------
180+
181+
* v4 API:
182+
183+
+:class:`gitlab.v4.objects.ProjectCustomAttribute`
184+
+:class:`gitlab.v4.objects.ProjectCustomAttributeManager`
185+
+:attr:`gitlab.v4.objects.Project.customattributes`
186+
187+
* GitLab API: https://docs.gitlab.com/ce/api/custom_attributes.html
188+
189+
Examples
190+
--------
191+
192+
List custom attributes for a project::
193+
194+
attrs = project.customattributes.list()
195+
196+
Get a custom attribute for a project::
197+
198+
attr = project.customattributes.get(attr_key)
199+
200+
Set (create or update) a custom attribute for a project::
201+
202+
attr = project.customattributes.set(attr_key, attr_value)
203+
204+
Delete a custom attribute for a project::
205+
206+
attr.delete()
207+
# or
208+
project.customattributes.delete(attr_key)
209+
175210
Project files
176211
=============
177212

‎docs/gl_objects/users.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -98,24 +98,6 @@
9898
current_user=gl.user
9999
# end currentuser get
100100

101-
# ca list
102-
attrs=user.customeattributes.list()
103-
# end ca list
104-
105-
# ca get
106-
attr=user.customeattributes.get(attr_key)
107-
# end ca get
108-
109-
# ca set
110-
attr=user.customeattributes.set(attr_key,attr_value)
111-
# end ca set
112-
113-
# ca delete
114-
attr.delete()
115-
# or
116-
user.customeattributes.delete(attr_key)
117-
# end ca delete
118-
119101
# it list
120102
i_t=user.impersonationtokens.list(state='active')
121103
i_t=user.impersonationtokens.list(state='inactive')

‎docs/gl_objects/users.rst

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -89,29 +89,23 @@ References
8989
Examples
9090
--------
9191

92-
List custom attributes for a user:
92+
List custom attributes for a user::
9393

94-
..literalinclude::users.py
95-
:start-after: # ca list
96-
:end-before: # end ca list
94+
attrs = user.customattributes.list()
9795

98-
Get a custom attribute for a user:
96+
Get a custom attribute for a user::
9997

100-
..literalinclude::users.py
101-
:start-after: # ca get
102-
:end-before: # end ca get
98+
attr = user.customattributes.get(attr_key)
10399

104-
Set (create or update) a custom attribute for a user:
100+
Set (create or update) a custom attribute for a user::
105101

106-
..literalinclude::users.py
107-
:start-after: # ca set
108-
:end-before: # end ca set
102+
attr = user.customattributes.set(attr_key, attr_value)
109103

110-
Delete a custom attribute for a user:
104+
Delete a custom attribute for a user::
111105

112-
..literalinclude::users.py
113-
:start-after: #ca list
114-
:end-before: # end ca list
106+
attr.delete()
107+
#or
108+
user.customattributes.delete(attr_key)
115109

116110
User impersonation tokens
117111
=========================

‎gitlab/v4/objects.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,17 @@ class GroupAccessRequestManager(GetFromListMixin, CreateMixin, DeleteMixin,
461461
_from_parent_attrs= {'group_id':'id'}
462462

463463

464+
classGroupCustomAttribute(ObjectDeleteMixin,RESTObject):
465+
_id_attr='key'
466+
467+
468+
classGroupCustomAttributeManager(RetrieveMixin,SetMixin,DeleteMixin,
469+
RESTManager):
470+
_path='/groups/%(group_id)s/custom_attributes'
471+
_obj_cls=GroupCustomAttribute
472+
_from_parent_attrs= {'group_id':'id'}
473+
474+
464475
classGroupIssue(RESTObject):
465476
pass
466477

@@ -614,6 +625,7 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject):
614625
_short_print_attr='name'
615626
_managers= (
616627
('accessrequests','GroupAccessRequestManager'),
628+
('customattributes','GroupCustomAttributeManager'),
617629
('issues','GroupIssueManager'),
618630
('members','GroupMemberManager'),
619631
('milestones','GroupMilestoneManager'),
@@ -839,6 +851,17 @@ class ProjectBranchManager(NoUpdateMixin, RESTManager):
839851
_create_attrs= (('branch','ref'),tuple())
840852

841853

854+
classProjectCustomAttribute(ObjectDeleteMixin,RESTObject):
855+
_id_attr='key'
856+
857+
858+
classProjectCustomAttributeManager(RetrieveMixin,SetMixin,DeleteMixin,
859+
RESTManager):
860+
_path='/projects/%(project_id)s/custom_attributes'
861+
_obj_cls=ProjectCustomAttribute
862+
_from_parent_attrs= {'project_id':'id'}
863+
864+
842865
classProjectJob(RESTObject):
843866
@cli.register_custom_action('ProjectJob')
844867
@exc.on_http_error(exc.GitlabJobCancelError)
@@ -2200,6 +2223,7 @@ class Project(SaveMixin, ObjectDeleteMixin, RESTObject):
22002223
('branches','ProjectBranchManager'),
22012224
('jobs','ProjectJobManager'),
22022225
('commits','ProjectCommitManager'),
2226+
('customattributes','ProjectCustomAttributeManager'),
22032227
('deployments','ProjectDeploymentManager'),
22042228
('environments','ProjectEnvironmentManager'),
22052229
('events','ProjectEventManager'),

‎tools/python_test_v4.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,20 @@
230230

231231
group2.members.delete(gl.user.id)
232232

233+
# group custom attributes
234+
attrs=group2.customattributes.list()
235+
assert(len(attrs)==0)
236+
attr=group2.customattributes.set('key','value1')
237+
assert(attr.key=='key')
238+
assert(attr.value=='value1')
239+
assert(len(group2.customattributes.list())==1)
240+
attr=group2.customattributes.set('key','value2')
241+
attr=group2.customattributes.get('key')
242+
assert(attr.value=='value2')
243+
assert(len(group2.customattributes.list())==1)
244+
attr.delete()
245+
assert(len(group2.customattributes.list())==0)
246+
233247
# group notification settings
234248
settings=group2.notificationsettings.get()
235249
settings.level='disabled'
@@ -285,6 +299,20 @@
285299
assert(len(l2)==1)
286300
assert(l1[0].id!=l2[0].id)
287301

302+
# group custom attributes
303+
attrs=admin_project.customattributes.list()
304+
assert(len(attrs)==0)
305+
attr=admin_project.customattributes.set('key','value1')
306+
assert(attr.key=='key')
307+
assert(attr.value=='value1')
308+
assert(len(admin_project.customattributes.list())==1)
309+
attr=admin_project.customattributes.set('key','value2')
310+
attr=admin_project.customattributes.get('key')
311+
assert(attr.value=='value2')
312+
assert(len(admin_project.customattributes.list())==1)
313+
attr.delete()
314+
assert(len(admin_project.customattributes.list())==0)
315+
288316
# project pages domains
289317
domain=admin_project.pagesdomains.create({'domain':'foo.domain.com'})
290318
assert(len(admin_project.pagesdomains.list())==1)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp