Skip to content

Commit 4f1adaa

Browse files
committed
Handle the pagination Link headers for _list requests
The patchwork REST API defaults to sending a maximum of 30 items for API requests which return a list. This makes pwclient list fail to return more than 30 items when using the REST API. To handle this, the API includes 'Link' headers in the response which indicate whether there is more data and what URL the data is available at. Processing the Link header is done automatically by the requests library. Handle this in the _list implementation by checking whether the response had a 'next' header, and request that data as well. This allows the pwclient to list everything instead of being limited to 30 patches. Signed-off-by: Jacob Keller <[email protected]>
1 parent 4cb4036 commit 4f1adaa

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

pwclient/api.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,17 @@ def _list(
587587
r = self._get(url, params)
588588
if r.status_code == http.HTTPStatus.NOT_FOUND:
589589
return []
590-
return r.json()
590+
591+
items = r.json()
592+
593+
while 'next' in r.links:
594+
r = self._get(r.links['next']['url'], params)
595+
if r.status_code == http.HTTPStatus.NOT_FOUND:
596+
break
597+
598+
items += r.json()
599+
600+
return items
591601

592602
# project
593603

0 commit comments

Comments
 (0)