X Tutup
Skip to content

Commit 33ceed6

Browse files
committed
python-gitlab Issue python-gitlab#63 - implement pagination for list()
1 parent 802c144 commit 33ceed6

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

gitlab/__init__.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
import requests
2727
import six
2828

29+
import logging
30+
logger = logging.getLogger(__name__)
31+
2932
__title__ = 'python-gitlab'
3033
__version__ = '0.9.1'
3134
__author__ = 'Gauvain Pocentek'
@@ -189,6 +192,8 @@ def set_url(self, url):
189192
self._url = '%s/api/v3' % url
190193

191194
def _construct_url(self, id_, obj, parameters):
195+
if 'next_url' in parameters:
196+
return parameters['next_url']
192197
args = _sanitize_dict(parameters)
193198
url = obj._url % args
194199
if id_ is not None:
@@ -342,8 +347,14 @@ def list(self, obj_class, **kwargs):
342347
if key in cls_kwargs:
343348
del cls_kwargs[key]
344349

345-
return [cls(self, item, **cls_kwargs) for item in r.json()
346-
if item is not None]
350+
results = [cls(self, item, **cls_kwargs) for item in r.json()
351+
if item is not None]
352+
if 'next' in r.links and 'url' in r.links['next']:
353+
args = kwargs.copy()
354+
args['next_url'] = r.links['next']['url']
355+
logger.debug("Iterating results 'next' link: %s", args['next_url'])
356+
results.extend(self.list(obj_class, **args))
357+
return results
347358
else:
348359
_raise_error_from_response(r, GitlabListError)
349360

0 commit comments

Comments
 (0)
X Tutup