-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
grab maximum amount of comments to fix issue with --merge-pr if there any many comments in a PR #2553
base: develop
Are you sure you want to change the base?
Conversation
… any many comments in a PR
@boegel I think it is possible to disable pagination altogether: https://github.com/api-platform/docs/blob/master/core/pagination.md Whether that makes sense or not..... I am not sure. It could potentially be a problem, but I doubt in reality it will happen, as it would need a very large number of comments to be an issue. |
'-D', | ||
'--github-user=%s' % GITHUB_TEST_ACCOUNT, | ||
] | ||
stdout, stderr = self._run_mock_eb(args, do_build=True, raise_error=True, testing=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a silly comment: Doesn't it make sense to set do_build=False
and testing=True
? I took a brief look at the _run_mock_eb
code (and eb_main
, and main
), and I don't think it makes any difference, but still.....
easybuild/tools/github.py
Outdated
@@ -1004,7 +1005,7 @@ def merge_pr(pr): | |||
|
|||
# also fetch comments | |||
comments_url = lambda g: g.repos[pr_target_account][pr_target_repo].issues[pr].comments | |||
status, comments_data = github_api_get_request(comments_url, github_user) | |||
status, comments_data = github_api_get_request(comments_url, github_user, per_page=GITHUB_MAX_PER_PAGE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a comment here stating that a PR with lots of comments (> GITHUB_MAX_PER_PAGE
) might fail?
more generically (since other types of API calls can also be paginated and the defaults can be different), we could traverse pages whenever they are present (according to the Link header) I had to slightly change --- a/lib/vsc/utils/rest.py
+++ b/lib/vsc/utils/rest.py
@@ -174,11 +174,14 @@ class Client(object):
# TODO: in recent python: Context manager
conn = self.get_connection(method, url, body, headers)
status = conn.code
- body = conn.read()
- try:
- pybody = json.loads(body)
- except ValueError:
- pybody = body
+ if method == self.HEAD:
+ pybody = conn.headers
+ else:
+ body = conn.read()
+ try:
+ pybody = json.loads(body)
+ except ValueError:
+ pybody = body
fancylogger.getLogger().debug('reponse len: %s ', len(pybody))
conn.close()
return status, pybody but once we have the headers, --- a/easybuild/tools/github.py
+++ b/easybuild/tools/github.py
@@ -243,10 +243,36 @@ def github_api_get_request(request_f, github_user=None, token=None, **kwargs):
url = request_f(RestClient(GITHUB_API_URL, username=github_user, token=token))
try:
- status, data = url.get(**kwargs)
+ status, headers = url.head(**kwargs)
except socket.gaierror as err:
- _log.warning("Error occurred while performing get request: %s", err)
- status, data = 0, None
+ _log.warning("Error occurred while getting headers from request: %s", err)
+ status, headers = 0, None
+
+ npages = 1
+ if headers:
+ links = headers.getheader('Link')
+ if links:
+ match = re.search(r"page=(\d+)>; rel=\"last\"", links)
+ if match:
+ npages = int(match.groups()[0])
+
+ if npages > 1:
+ data = []
+ for page in range(1, npages+1):
+ kwargs['page'] = page
+ try:
+ status, page_data = url.get(**kwargs)
+ except socket.gaierror as err:
+ _log.warning("Error occurred while performing get request: %s", err)
+ status, page_data = 0, None
+ break
+ data.extend(page_data)
+ else:
+ try:
+ status, data = url.get(**kwargs)
+ except socket.gaierror as err:
+ _log.warning("Error occurred while performing get request: %s", err)
+ status, data = 0, None
_log.debug("get request result for %s: status: %d, data: %s", url, status, data)
return (status, data) ? |
@migueldiascosta Are you up for opening a PR to We'll need to keep in mind to port that change into the |
This fixes a problem I ran into when merging easybuilders/easybuild-easyconfigs#6677 using
eb --merge-pr
:The problem is that this PR has many comments, exceeded the default number of comments that are returned by the GitHub API.
There's still a problem when a PR has more than 100 comments, but to fix that we'll need to make the fetching of comments page-aware, cfr. https://developer.github.com/v3/#pagination + https://developer.github.com/v3/guides/traversing-with-pagination/