@@ -193,12 +193,21 @@ def delete(cls, gl, id, **kwargs):
193
193
194
194
return gl .delete (cls , id , ** kwargs )
195
195
196
+ def getObject (self , k , v ):
197
+ if self .constructorTypes and k in self .constructorTypes :
198
+ return globals ()[self .constructorTypes [k ]](v )
199
+ else :
200
+ return v
201
+
196
202
def __init__ (self , data ):
197
203
for k , v in data .items ():
198
- if self .constructorTypes and k in self .constructorTypes :
199
- self .__dict__ [k ] = self .constructorTypes [k ](v )
204
+ if isinstance (v , list ):
205
+ self .__dict__ [k ] = []
206
+ for i in v :
207
+ self .__dict__ [k ].append (self .getObject (k ,i ))
208
+
200
209
else :
201
- self .__dict__ [k ] = v
210
+ self .__dict__ [k ] = self . getObject ( k , v )
202
211
203
212
def __str__ (self ):
204
213
return '%s => %s' % (type (self ), str (self .__dict__ ))
@@ -207,9 +216,13 @@ def __str__(self):
207
216
class User (GitlabObject ):
208
217
url = '/users'
209
218
219
+ class Group (GitlabObject ):
220
+ url = '/groups'
221
+ constructorTypes = {'projects' : 'Project' }
222
+
210
223
class Project (GitlabObject ):
211
224
url = '/projects'
212
- constructorTypes = {'owner' : User }
225
+ constructorTypes = {'owner' : ' User' , 'namespace' : 'Group' }
213
226
canUpdate = False
214
227
canDelete = False
215
228
@@ -246,10 +259,13 @@ class ProjectMilestone(GitlabObject):
246
259
247
260
class ProjectMergeRequest (GitlabObject ):
248
261
url = '/projects/%(project_id)d/merge_request'
262
+ constructorTypes = {'author' : 'User' , 'assignee' : 'User' }
249
263
canDelete = False
250
264
251
265
class Issue (GitlabObject ):
252
266
url = '/issues'
267
+ constructorTypes = {'author' : 'User' , 'assignee' : 'User' ,
268
+ 'milestone' : 'ProjectMilestone' }
253
269
canGet = False
254
270
canDelete = False
255
271
canUpdate = False
@@ -260,15 +276,13 @@ class ProjectIssue(GitlabObject):
260
276
returnClass = Issue
261
277
canDelete = False
262
278
263
- class Group (GitlabObject ):
264
- url = '/groups'
265
-
266
279
class Session (object ):
267
280
def __init__ (self ):
268
281
raise NotImplementedError
269
282
270
- class Snippet (GitlabObject ):
283
+ class ProjectSnippet (GitlabObject ):
271
284
url = '/projects/%(project_id)d/snippets'
285
+ constructorTypes = {'author' : 'User' }
272
286
273
287
class User (GitlabObject ):
274
288
url = '/users'
0 commit comments