16
16
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
"""Wrapper for the GitLab API."""
18
18
19
- from __future__ import print_function
20
- from __future__ import absolute_import
21
19
import importlib
22
20
import time
23
21
import warnings
24
22
25
23
import requests
24
+ import requests .utils
26
25
27
26
import gitlab .config
28
27
from gitlab .const import * # noqa
43
42
"must update your GitLab URL to use https:// to avoid issues."
44
43
)
45
44
45
+ ALLOWED_KEYSET_ENDPOINTS = ["/projects" ]
46
+
46
47
47
48
def _sanitize (value ):
48
49
if isinstance (value , dict ):
@@ -618,7 +619,7 @@ def http_list(self, path, query_data=None, as_list=None, **kwargs):
618
619
619
620
Args:
620
621
path (str): Path or full URL to query ('/projects' or
621
- 'http://whatever/v4/api/projecs ')
622
+ 'http://whatever/v4/api/projects ')
622
623
query_data (dict): Data to send as query parameters
623
624
**kwargs: Extra options to send to the server (e.g. sudo, page,
624
625
per_page)
@@ -642,10 +643,22 @@ def http_list(self, path, query_data=None, as_list=None, **kwargs):
642
643
get_all = kwargs .pop ("all" , False )
643
644
url = self ._build_url (path )
644
645
646
+ order_by = kwargs .get ("order_by" )
647
+ pagination = kwargs .get ("pagination" )
648
+ page = kwargs .get ("page" )
649
+ if (
650
+ path in ALLOWED_KEYSET_ENDPOINTS
651
+ and (not order_by or order_by == "id" )
652
+ and (not pagination or pagination == "keyset" )
653
+ and not page
654
+ ):
655
+ kwargs ["pagination" ] = "keyset"
656
+ kwargs ["order_by" ] = "id"
657
+
645
658
if get_all is True and as_list is True :
646
659
return list (GitlabList (self , url , query_data , ** kwargs ))
647
660
648
- if " page" in kwargs or as_list is True :
661
+ if page or as_list is True :
649
662
# pagination requested, we return a list
650
663
return list (GitlabList (self , url , query_data , get_next = False , ** kwargs ))
651
664
@@ -781,7 +794,14 @@ def _query(self, url, query_data=None, **kwargs):
781
794
query_data = query_data or {}
782
795
result = self ._gl .http_request ("get" , url , query_data = query_data , ** kwargs )
783
796
try :
784
- self ._next_url = result .links ["next" ]["url" ]
797
+ links = result .links
798
+ if links :
799
+ next_url = links ["next" ]["url" ]
800
+ else :
801
+ next_url = requests .utils .parse_header_links (result .headers ["links" ])[
802
+ 0
803
+ ]["url" ]
804
+ self ._next_url = next_url
785
805
except KeyError :
786
806
self ._next_url = None
787
807
self ._current_page = result .headers .get ("X-Page" )
0 commit comments