Branch: refs/heads/master Author: Enrico Tröger enrico.troeger@uvena.de Committer: Enrico Tröger enrico.troeger@uvena.de Date: Tue, 17 Oct 2023 21:36:57 UTC Commit: b2788b810f62be85f04702b47503ec3ceea707bb https://github.com/geany/www.geany.org/commit/b2788b810f62be85f04702b47503ec...
Log Message: ----------- Download file content from Github directly if content is missing
The Github API seems to return the requested file content only until a certain content size. If it missing, we use the provided download URL to download the file contents explicitly.
Modified Paths: -------------- static_docs/github_client.py
Modified: static_docs/github_client.py 21 lines changed, 14 insertions(+), 7 deletions(-) =================================================================== @@ -75,13 +75,15 @@ def _factor_authorization_header(self):
# ---------------------------------------------------------------------- def _log_rate_limit(self, response): - rate_limit_remaining = int(response.headers['X-RateLimit-Remaining']) - rate_limit = response.headers['X-RateLimit-Limit'] - log_message = f'Github rate limits: {rate_limit_remaining}/{rate_limit}' - if rate_limit_remaining > 0: - logger.info(log_message) - else: - logger.warning(log_message) + rate_limit_remaining = response.headers.get('X-RateLimit-Remaining') + if rate_limit_remaining: + rate_limit_remaining = int(rate_limit_remaining) + rate_limit = response.headers['X-RateLimit-Limit'] + log_message = f'Github rate limits: {rate_limit_remaining}/{rate_limit}' + if rate_limit_remaining > 0: + logger.info(log_message) + else: + logger.warning(log_message)
# ---------------------------------------------------------------------- def _log_request(self, response, status_404_expected): @@ -118,6 +120,11 @@ def _parse_fetch_file_response(self, response_json): # standard_b64decode returns a byte string but we want a unicode string content_utf8 = standard_b64decode(content) return content_utf8.decode('utf-8') + elif response_json['encoding'] == 'none' and not content: + # the API did not return the file content, so download it explicitly + file_content = self._request(response_json['download_url']) + return file_content.text + return content
# ----------------------------------------------------------------------
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).