swh.lister.gitlab: Read next page from headers

This commit is contained in:
Antoine R. Dumont (@ardumont) 2018-07-12 11:29:36 +02:00
parent d640fdcc96
commit 2648f1ae2e
No known key found for this signature in database
GPG key ID: 52E2E9840D10C3B8
2 changed files with 4 additions and 15 deletions

View file

@ -3,7 +3,6 @@
# See top-level LICENSE file for more information
import random
import re
import time
from .. import utils
@ -14,7 +13,6 @@ from .models import GitLabModel
class GitLabLister(PageByPageHttpLister):
# Template path expecting an integer that represents the page id
PATH_TEMPLATE = '/projects?page=%d&order_by=id'
API_URL_INDEX_RE = re.compile(r'^.*/projects.*page=(\d+).*')
MODEL = GitLabModel
LISTER_NAME = 'gitlab'
@ -98,10 +96,9 @@ class GitLabLister(PageByPageHttpLister):
"""Determine the next page identifier.
"""
if 'next' in response.links:
next_url = response.links['next']['url']
return int(self.API_URL_INDEX_RE.match(next_url).group(1))
return None
_next = utils.get(response.headers, ['X-Next-Page', 'x-next-page'])
if _next:
return int(_next)
def get_pages_information(self):
"""Determine pages information.

View file

@ -24,15 +24,7 @@ class GitLabListerTester(HttpListerTesterBase, unittest.TestCase):
headers = {'RateLimit-Remaining': '1'}
if self.request_index(request) == str(self.first_index):
headers.update({
'Link': '<https://gitlab.com/v4/projects?page=2>;'
' rel="next",'
'<https://gitlab.com/v4/projects{?page}>;'
' rel="first"'
})
else:
headers.update({
'Link': '<https://gitlab.com/v4/projects{?page}>;'
' rel="first"'
'x-next-page': '3',
})
return headers