summaryrefslogtreecommitdiff
path: root/gitlab/__init__.py
diff options
context:
space:
mode:
authorGauvain Pocentek <gauvain@pocentek.net>2016-02-18 18:17:06 +0000
committerGauvain Pocentek <gauvain@pocentek.net>2016-02-18 18:19:48 +0000
commit453224aaf64c37196b7211de8dd4a60061954987 (patch)
treea77a85c92cc3f50b6ce05345d24fed5c8d76782d /gitlab/__init__.py
parent44d0dc54fb7edf7de4e50ca34d430fe734c0e8cc (diff)
downloadgitlab-453224aaf64c37196b7211de8dd4a60061954987.tar.gz
Re-implement _custom_list in the Gitlab class
Rename the method _raw_list. This adds support for the ``all=True`` option to enable automatic recursion and avoid pagination if requested by the user. Fixes #93
Diffstat (limited to 'gitlab/__init__.py')
-rw-r--r--gitlab/__init__.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/gitlab/__init__.py b/gitlab/__init__.py
index a947084..ef39cd5 100644
--- a/gitlab/__init__.py
+++ b/gitlab/__init__.py
@@ -269,6 +269,31 @@ class Gitlab(object):
raise GitlabConnectionError(
"Can't connect to GitLab server (%s)" % e)
+ def _raw_list(self, path, cls, **kwargs):
+ r = self._raw_get(path, **kwargs)
+ raise_error_from_response(r, GitlabListError)
+
+ cls_kwargs = kwargs.copy()
+
+ # Add _from_api manually, because we are not creating objects
+ # through normal path
+ cls_kwargs['_from_api'] = True
+ get_all_results = kwargs.get('all', False)
+
+ # Remove parameters from kwargs before passing it to constructor
+ for key in ['all', 'page', 'per_page', 'sudo']:
+ if key in cls_kwargs:
+ del cls_kwargs[key]
+
+ results = [cls(self, item, **cls_kwargs) for item in r.json()
+ if item is not None]
+ if ('next' in r.links and 'url' in r.links['next']
+ and get_all_results is True):
+ args = kwargs.copy()
+ args['next_url'] = r.links['next']['url']
+ results.extend(self.list(cls, **args))
+ return results
+
def _raw_post(self, path, data=None, content_type=None, **kwargs):
url = '%s%s' % (self._url, path)
headers = self._create_headers(content_type)