Skip to content

Commit a9e8da9

Browse files
author
Gauvain Pocentek
committed
don't list everything by default
1 parent e93188e commit a9e8da9

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

gitlab/__init__.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -343,14 +343,17 @@ def list(self, obj_class, **kwargs):
343343
# through normal path
344344
cls_kwargs['_created'] = True
345345

346+
get_all_results = params.get('all', False)
347+
346348
# Remove parameters from kwargs before passing it to constructor
347-
for key in ['page', 'per_page', 'sudo']:
349+
for key in ['all', 'page', 'per_page', 'sudo']:
348350
if key in cls_kwargs:
349351
del cls_kwargs[key]
350352

351353
results = [cls(self, item, **cls_kwargs) for item in r.json()
352354
if item is not None]
353-
if 'next' in r.links and 'url' in r.links['next']:
355+
if ('next' in r.links and 'url' in r.links['next']
356+
and get_all_results is True):
354357
args = kwargs.copy()
355358
args['next_url'] = r.links['next']['url']
356359
results.extend(self.list(obj_class, **args))

gitlab/tests/test_gitlab.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,7 @@ def resp_cont(url, request):
180180

181181
def test_list_next_link(self):
182182
@urlmatch(scheme="http", netloc="localhost",
183-
path='/api/v3/projects/1/repository/branches', method="get",
184-
query=r'per_page=1')
183+
path='/api/v3/projects/1/repository/branches', method="get")
185184
def resp_one(url, request):
186185
"""First request:
187186
@@ -217,9 +216,9 @@ def resp_two(url, request):
217216
resp = response(200, content, headers, None, 5, request)
218217
return resp
219218

220-
with HTTMock(resp_one, resp_two):
221-
data = self.gl.list(ProjectBranch, project_id=1,
222-
per_page=1)
219+
with HTTMock(resp_two, resp_one):
220+
data = self.gl.list(ProjectBranch, project_id=1, per_page=1,
221+
all=True)
223222
self.assertEqual(data[1].branch_name, "testbranch")
224223
self.assertEqual(data[1].project_id, 1)
225224
self.assertEqual(data[1].ref, "a")

0 commit comments

Comments
 (0)