Skip to content

Commit

Permalink
Fix the listing of some resources
Browse files Browse the repository at this point in the history
The parent ID wasn't available in the generated objects, leading to
exceptions when trying to use specific methods for these objects.

Fixes #132
  • Loading branch information
Gauvain Pocentek committed Aug 7, 2016
1 parent 92edb99 commit 922041d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 25 deletions.
5 changes: 3 additions & 2 deletions gitlab/__init__.py
Expand Up @@ -323,11 +323,12 @@ def _raw_get(self, path, content_type=None, streamed=False, **kwargs):
raise GitlabConnectionError(
"Can't connect to GitLab server (%s)" % e)

def _raw_list(self, path, cls, **kwargs):
def _raw_list(self, path, cls, extra_attrs={}, **kwargs):
r = self._raw_get(path, **kwargs)
raise_error_from_response(r, GitlabListError)

cls_kwargs = kwargs.copy()
cls_kwargs = extra_attrs.copy()
cls_kwargs.update(kwargs.copy())

# Add _from_api manually, because we are not creating objects
# through normal path
Expand Down
36 changes: 13 additions & 23 deletions gitlab/objects.py
Expand Up @@ -1059,16 +1059,9 @@ def builds(self, **kwargs):
"""
url = '/projects/%s/repository/commits/%s/builds' % (self.project_id,
self.id)
r = self.gitlab._raw_get(url, **kwargs)
raise_error_from_response(r, GitlabListError)

l = []
for j in r.json():
o = ProjectBuild(self, j)
o._from_api = True
l.append(o)

return l
return self.gitlab._raw_list(url, ProjectBuild,
{'project_id': self.project_id},
**kwargs)


class ProjectCommitManager(BaseManager):
Expand Down Expand Up @@ -1413,7 +1406,9 @@ def closes_issues(self, **kwargs):
"""
url = ('/projects/%s/merge_requests/%s/closes_issues' %
(self.project_id, self.id))
return self.gitlab._raw_list(url, ProjectIssue, **kwargs)
return self.gitlab._raw_list(url, ProjectIssue,
{'project_id': self.project_id},
**kwargs)

def commits(self, **kwargs):
"""List the merge request commits.
Expand All @@ -1427,7 +1422,9 @@ def commits(self, **kwargs):
"""
url = ('/projects/%s/merge_requests/%s/commits' %
(self.project_id, self.id))
return self.gitlab._raw_list(url, ProjectCommit, **kwargs)
return self.gitlab._raw_list(url, ProjectCommit,
{'project_id': self.project_id},
**kwargs)

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

def issues(self):
def issues(self, **kwargs):
url = "/projects/%s/milestones/%s/issues" % (self.project_id, self.id)
r = self.gitlab._raw_get(url)
raise_error_from_response(r, GitlabDeleteError)

l = []
for j in r.json():
o = ProjectIssue(self, j)
o._from_api = True
l.append(o)

return l
return self.gitlab._raw_list(url, ProjectIssue,
{'project_id': self.project_id},
**kwargs)


class ProjectMilestoneManager(BaseManager):
Expand Down

0 comments on commit 922041d

Please sign in to comment.