1616# along with this program. If not, see <http://www.gnu.org/licenses/>.
1717"""Wrapper for the GitLab API."""
1818
19- from __future__ import print_function
20- from __future__ import absolute_import
2119import importlib
2220import time
2321import warnings
2422
2523import requests
24+ import requests .utils
2625
2726import gitlab .config
2827from gitlab .const import * # noqa
4342 "must update your GitLab URL to use https:// to avoid issues."
4443)
4544
45+ ALLOWED_KEYSET_ENDPOINTS = ["/projects" ]
46+
4647
4748def _sanitize (value ):
4849 if isinstance (value , dict ):
@@ -618,7 +619,7 @@ def http_list(self, path, query_data=None, as_list=None, **kwargs):
618619
619620 Args:
620621 path (str): Path or full URL to query ('/projects' or
621- 'http://whatever/v4/api/projecs ')
622+ 'http://whatever/v4/api/projects ')
622623 query_data (dict): Data to send as query parameters
623624 **kwargs: Extra options to send to the server (e.g. sudo, page,
624625 per_page)
@@ -642,6 +643,16 @@ def http_list(self, path, query_data=None, as_list=None, **kwargs):
642643 get_all = kwargs .pop ("all" , False )
643644 url = self ._build_url (path )
644645
646+ order_by = kwargs .get ("order_by" )
647+ pagination = kwargs .get ("pagination" )
648+ if (
649+ path in ALLOWED_KEYSET_ENDPOINTS
650+ and (not order_by or order_by == "id" )
651+ and (not pagination or pagination == "keyset" )
652+ ):
653+ kwargs ["pagination" ] = "keyset"
654+ kwargs ["order_by" ] = "id"
655+
645656 if get_all is True and as_list is True :
646657 return list (GitlabList (self , url , query_data , ** kwargs ))
647658
@@ -781,7 +792,14 @@ def _query(self, url, query_data=None, **kwargs):
781792 query_data = query_data or {}
782793 result = self ._gl .http_request ("get" , url , query_data = query_data , ** kwargs )
783794 try :
784- self ._next_url = result .links ["next" ]["url" ]
795+ links = result .links
796+ if links :
797+ next_url = links ["next" ]["url" ]
798+ else :
799+ next_url = requests .utils .parse_header_links (result .headers ["links" ])[
800+ 0
801+ ]["url" ]
802+ self ._next_url = next_url
785803 except KeyError :
786804 self ._next_url = None
787805 self ._current_page = result .headers .get ("X-Page" )
0 commit comments