From e3373475c8529593931f0bed2766eb18cf30c6fb Mon Sep 17 00:00:00 2001 From: vsc46128 vscuser Date: Mon, 23 Oct 2023 14:43:32 +0200 Subject: [PATCH] add fix that is compatible with python 3.6 and PyGithub < 1.56 --- connections/github.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/connections/github.py b/connections/github.py index ee7c5e34..9770d915 100644 --- a/connections/github.py +++ b/connections/github.py @@ -15,7 +15,7 @@ import time # Third party imports (anything installed into the local Python environment) -from github import Github, GithubIntegration +import github # Local application imports (anything from EESSI/eessi-bot-software-layer) from tools import config, logging @@ -57,7 +57,7 @@ def get_token(): # If the config keys are not set, get_access_token will raise a NotImplementedError # Returning NoneType token will stop the connection in get_instance try: - github_integration = GithubIntegration(app_id, private_key) + github_integration = github.GithubIntegration(app_id, private_key) _token = github_integration.get_access_token(installation_id) break except NotImplementedError as err: @@ -84,7 +84,7 @@ def connect(): Returns: Instance of Github """ - return Github(get_token().token) + return github.Github(get_token().token) def get_instance(): @@ -102,11 +102,13 @@ def get_instance(): # TODO Possibly renew token already if expiry date is soon, not only # after it has expired. - # Check if PyGithub version is <1.56 - if - - if not _gh or (_token and datetime.datetime.now(datetimezone.utc) > _token.expires_at): - _gh = connect() + # Check if PyGithub version is < 1.56 + if hasattr(github, 'GithubRetry' is False: + if not _gh or (_token and datetime.utcnow() > _token.expires_at): + _gh = connect() + elif hasattr(github, 'GithubRetry' is True: + if not _gh or (_token and datetime.now(timezone.utc) > _token.expires_at): + _gh = connect() return _gh