Skip to content

Commit 922041d

Browse files
author
Gauvain Pocentek
committed
Fix the listing of some resources
The parent ID wasn't available in the generated objects, leading to exceptions when trying to use specific methods for these objects. Fixes #132
1 parent 92edb99 commit 922041d

File tree

2 files changed

+16
-25
lines changed

2 files changed

+16
-25
lines changed

gitlab/__init__.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -323,11 +323,12 @@ def _raw_get(self, path, content_type=None, streamed=False, **kwargs):
323323
raise GitlabConnectionError(
324324
"Can't connect to GitLab server (%s)" % e)
325325

326-
def _raw_list(self, path, cls, **kwargs):
326+
def _raw_list(self, path, cls, extra_attrs={}, **kwargs):
327327
r = self._raw_get(path, **kwargs)
328328
raise_error_from_response(r, GitlabListError)
329329

330-
cls_kwargs = kwargs.copy()
330+
cls_kwargs = extra_attrs.copy()
331+
cls_kwargs.update(kwargs.copy())
331332

332333
# Add _from_api manually, because we are not creating objects
333334
# through normal path

gitlab/objects.py

+13-23
Original file line numberDiff line numberDiff line change
@@ -1059,16 +1059,9 @@ def builds(self, **kwargs):
10591059
"""
10601060
url = '/projects/%s/repository/commits/%s/builds' % (self.project_id,
10611061
self.id)
1062-
r = self.gitlab._raw_get(url, **kwargs)
1063-
raise_error_from_response(r, GitlabListError)
1064-
1065-
l = []
1066-
for j in r.json():
1067-
o = ProjectBuild(self, j)
1068-
o._from_api = True
1069-
l.append(o)
1070-
1071-
return l
1062+
return self.gitlab._raw_list(url, ProjectBuild,
1063+
{'project_id': self.project_id},
1064+
**kwargs)
10721065

10731066

10741067
class ProjectCommitManager(BaseManager):
@@ -1413,7 +1406,9 @@ def closes_issues(self, **kwargs):
14131406
"""
14141407
url = ('/projects/%s/merge_requests/%s/closes_issues' %
14151408
(self.project_id, self.id))
1416-
return self.gitlab._raw_list(url, ProjectIssue, **kwargs)
1409+
return self.gitlab._raw_list(url, ProjectIssue,
1410+
{'project_id': self.project_id},
1411+
**kwargs)
14171412

14181413
def commits(self, **kwargs):
14191414
"""List the merge request commits.
@@ -1427,7 +1422,9 @@ def commits(self, **kwargs):
14271422
"""
14281423
url = ('/projects/%s/merge_requests/%s/commits' %
14291424
(self.project_id, self.id))
1430-
return self.gitlab._raw_list(url, ProjectCommit, **kwargs)
1425+
return self.gitlab._raw_list(url, ProjectCommit,
1426+
{'project_id': self.project_id},
1427+
**kwargs)
14311428

14321429
def changes(self, **kwargs):
14331430
"""List the merge request changes.
@@ -1497,18 +1494,11 @@ class ProjectMilestone(GitlabObject):
14971494
optionalUpdateAttrs = requiredCreateAttrs + optionalCreateAttrs
14981495
shortPrintAttr = 'title'
14991496

1500-
def issues(self):
1497+
def issues(self, **kwargs):
15011498
url = "/projects/%s/milestones/%s/issues" % (self.project_id, self.id)
1502-
r = self.gitlab._raw_get(url)
1503-
raise_error_from_response(r, GitlabDeleteError)
1504-
1505-
l = []
1506-
for j in r.json():
1507-
o = ProjectIssue(self, j)
1508-
o._from_api = True
1509-
l.append(o)
1510-
1511-
return l
1499+
return self.gitlab._raw_list(url, ProjectIssue,
1500+
{'project_id': self.project_id},
1501+
**kwargs)
15121502

15131503

15141504
class ProjectMilestoneManager(BaseManager):

0 commit comments

Comments
 (0)