Upgrade bot to be compatible with PyGithub v2.1.1#224
Conversation
|
PyGithub 2.1.1 requires Python >= 3.7, so applying this fix implies that the bot will no longer support Python 3.6 (see also failing CI)... That's painful because Python 3.6 is the default Python in RHEL 8 & derivates, so ideally we retain compatibility with that. I wonder if there's a smart way in which can check whether or not we need to compare with a |
|
Hmm, I can't find a direct way to check the PyGithub version, but we can do it by proxy: the |
| 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() |
There was a problem hiding this comment.
if ... is False is kind of silly, and positive logic is easier to follow, and there's a lot of copy-pasting, so I would change this to:
# PyGithub 2.x expects a datetime object with timezone info,
# PyGithub 1.x requires one without timezone info;
# see also https://github.com/PyGithub/PyGithub/pull/2565
if hasattr(github, 'GithubRetry'):
# PyGithub 2.x
time_now = datetime.now(timezone.utc)
else:
# PyGithub 1.x
time_now = datetime.utcnow()
if not _gh or (_token and time_now > _token.expires_at):
_gh = connect()|
Did some test runs with Python/3.6.8 and Python/3.9.16. See trz42/software-layer#67 Looks good. |
I tested the changes with python 3.8
resolves the following issue: #223