Skip to content

Commit ab82226

Browse files
author
Gauvain Pocentek
committed
add methods to Project objects to access related objects
1 parent 02afd17 commit ab82226

File tree

1 file changed

+75
-43
lines changed

1 file changed

+75
-43
lines changed

gitlab.py

Lines changed: 75 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -217,32 +217,38 @@ def __str__(self):
217217
class User(GitlabObject):
218218
url = '/users'
219219

220-
class Group(GitlabObject):
221-
url = '/groups'
222-
constructorTypes = {'projects': 'Project'}
223-
224-
class Project(GitlabObject):
225-
url = '/projects'
226-
constructorTypes = {'owner': 'User', 'namespace': 'Group'}
220+
class CurrentUser(GitlabObject):
221+
url = '/user'
222+
canGetList = False
223+
canCreate = False
227224
canUpdate = False
228225
canDelete = False
229226

230-
class ProjectMember(GitlabObject):
231-
url = '/projects/%(project_id)d/members'
232-
returnClass = User
227+
class CurrentUserKey(GitlabObject):
228+
url = '/user/keys'
229+
canUpdate = False
233230

234-
class ProjectHook(GitlabObject):
235-
url = '/projects/%(project_id)d/hooks'
231+
url = '/users'
236232

237-
class ProjectBranch(GitlabObject):
238-
url = '/projects/%(project_id)d/repository/branches'
233+
class Group(GitlabObject):
234+
url = '/groups'
235+
constructorTypes = {'projects': 'Project'}
236+
237+
class Issue(GitlabObject):
238+
url = '/issues'
239+
constructorTypes = {'author': 'User', 'assignee': 'User',
240+
'milestone': 'ProjectMilestone'}
241+
canGet = False
239242
canDelete = False
240243
canUpdate = False
241244
canCreate = False
242245

243-
class ProjectTag(GitlabObject):
244-
url = '/projects/%(project_id)d/repository/tags'
245-
canGet = False
246+
class Session(object):
247+
def __init__(self):
248+
raise NotImplementedError
249+
250+
class ProjectBranch(GitlabObject):
251+
url = '/projects/%(project_id)d/repository/branches'
246252
canDelete = False
247253
canUpdate = False
248254
canCreate = False
@@ -254,50 +260,76 @@ class ProjectCommit(GitlabObject):
254260
canUpdate = False
255261
canCreate = False
256262

257-
class ProjectMilestone(GitlabObject):
258-
url = '/projects/%(project_id)s/milestones'
259-
canDelete = False
263+
class ProjectHook(GitlabObject):
264+
url = '/projects/%(project_id)d/hooks'
260265

261-
class ProjectMergeRequest(GitlabObject):
262-
url = '/projects/%(project_id)d/merge_request'
263-
constructorTypes = {'author': 'User', 'assignee': 'User'}
266+
class ProjectIssue(GitlabObject):
267+
url = '/projects/%(project_id)s/issues/'
268+
returnClass = Issue
264269
canDelete = False
265270

266-
class Issue(GitlabObject):
267-
url = '/issues'
268-
constructorTypes = {'author': 'User', 'assignee': 'User',
269-
'milestone': 'ProjectMilestone'}
271+
class ProjectMember(GitlabObject):
272+
url = '/projects/%(project_id)d/members'
273+
returnClass = User
274+
275+
class ProjectTag(GitlabObject):
276+
url = '/projects/%(project_id)d/repository/tags'
270277
canGet = False
271278
canDelete = False
272279
canUpdate = False
273280
canCreate = False
274281

275-
class ProjectIssue(GitlabObject):
276-
url = '/projects/%(project_id)s/issues/'
277-
returnClass = Issue
282+
class ProjectMergeRequest(GitlabObject):
283+
url = '/projects/%(project_id)d/merge_request'
284+
constructorTypes = {'author': 'User', 'assignee': 'User'}
278285
canDelete = False
279286

280-
class Session(object):
281-
def __init__(self):
282-
raise NotImplementedError
287+
class ProjectMilestone(GitlabObject):
288+
url = '/projects/%(project_id)s/milestones'
289+
canDelete = False
283290

284291
class ProjectSnippet(GitlabObject):
285292
url = '/projects/%(project_id)d/snippets'
286293
constructorTypes = {'author': 'User'}
287294

288-
class User(GitlabObject):
289-
url = '/users'
290-
291-
class CurrentUser(GitlabObject):
292-
url = '/user'
293-
canGetList = False
294-
canCreate = False
295+
class Project(GitlabObject):
296+
url = '/projects'
297+
constructorTypes = {'owner': 'User', 'namespace': 'Group'}
295298
canUpdate = False
296299
canDelete = False
297300

298-
class CurrentUserKey(GitlabObject):
299-
url = '/user/keys'
300-
canUpdate = False
301+
def objGetter(self, cls, id):
302+
if id == None:
303+
return cls.list(self.gitlab, project_id=self.id)
304+
else:
305+
return cls.get(self.gitlab, id, project_id=self.id)
306+
307+
def Branch(self, id=None):
308+
return self.objGetter(ProjectBranch, id)
309+
310+
def Commit(self, id=None):
311+
return self.objGetter(ProjectCommit, id)
312+
313+
def Hook(self, id=None):
314+
return self.objGetter(ProjectHook, id)
315+
316+
def Issue(self, id=None):
317+
return self.objGetter(ProjectIssue, id)
318+
319+
def Member(self, id=None):
320+
return self.objGetter(ProjectMember, id)
321+
322+
def MergeRequest(self, id=None):
323+
return self.objGetter(ProjectMergeRequest, id)
324+
325+
def Milestone(self, id=None):
326+
return self.objGetter(ProjectMilestone, id)
327+
328+
def Snippet(self, id=None):
329+
return self.objGetter(ProjectSnippet, id)
330+
331+
def Tag(self, id=None):
332+
return self.objGetter(ProjectTag, id)
301333

302334
if __name__ == '__main__':
303335
# quick "doc"

0 commit comments

Comments
 (0)