Skip to content

Commit

Permalink
python-gitlab Issue #63 - implement pagination for list()
Browse files Browse the repository at this point in the history
  • Loading branch information
jantman committed Jul 28, 2015
1 parent 802c144 commit 33ceed6
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions gitlab/__init__.py
Expand Up @@ -26,6 +26,9 @@
import requests
import six

import logging
logger = logging.getLogger(__name__)

__title__ = 'python-gitlab'
__version__ = '0.9.1'
__author__ = 'Gauvain Pocentek'
Expand Down Expand Up @@ -189,6 +192,8 @@ def set_url(self, url):
self._url = '%s/api/v3' % url

def _construct_url(self, id_, obj, parameters):
if 'next_url' in parameters:
return parameters['next_url']
args = _sanitize_dict(parameters)
url = obj._url % args
if id_ is not None:
Expand Down Expand Up @@ -342,8 +347,14 @@ def list(self, obj_class, **kwargs):
if key in cls_kwargs:
del cls_kwargs[key]

return [cls(self, item, **cls_kwargs) for item in r.json()
if item is not None]
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']:
args = kwargs.copy()
args['next_url'] = r.links['next']['url']
logger.debug("Iterating results 'next' link: %s", args['next_url'])
results.extend(self.list(obj_class, **args))
return results
else:
_raise_error_from_response(r, GitlabListError)

Expand Down

0 comments on commit 33ceed6

Please sign in to comment.