Skip to content

Commit

Permalink
fix: v4 pagination when there is only one page of results
Browse files Browse the repository at this point in the history
  • Loading branch information
user2589 committed Sep 25, 2020
1 parent 39a5690 commit c877e3f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions stscraper/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,20 +390,25 @@ def v4(self, query, object_path=(), **params):
raise VCSError('Invalid object path "%s" in:\n %s' %
(object_path, json.dumps(data)))

has_next_page = json_path(objects, ('pageInfo', 'hasNextPage'))
if not json_path(objects, ('pageInfo', 'hasNextPage')):
page_info = json_path(objects, ('pageInfo',))
if page_info is None:
yield objects
return
# This is due to inconsistency in graphql API.
# In most cases, requests returning lists of objects put them in
# 'nodes', but in few legacy methods they use 'edges'
nodes = objects.get('nodes') or objects.get('edges')
if not nodes:
break
if nodes is None:
raise EnvironmentError(
'Unexpected result format. Please report an issue:\n'
'https://github.com/CMUSTRUDEL/strudel.scraper/issues/new')

for obj in nodes:
yield obj
if not json_path(page_info, ('hasNextPage',)):
break
# the result is single page, or there are no more pages
params['cursor'] = json_path(objects, ('pageInfo', 'endCursor'))
params['cursor'] = json_path(page_info, ('endCursor',))

def repo_issues(self, repo_slug, cursor=None):
owner, repo = repo_slug.split('/')
Expand Down

0 comments on commit c877e3f

Please sign in to comment.