Misc: update version fetching to the new branches

master is now used for main development, so PyPI has to be used instead to get
the latest release
This commit is contained in:
Valentin Lorentz 2024-05-29 21:49:23 +02:00
parent dcd95d3a77
commit 9a4dca8054

View File

@ -342,21 +342,31 @@ class Misc(callbacks.Plugin):
Returns the version of the current bot. Returns the version of the current bot.
""" """
try: try:
newestUrl = 'https://api.github.com/repos/progval/Limnoria/' + \ versions = []
'commits/%s'
versions = {} # fetch from PyPI
for branch in ('master', 'testing'): data = json.loads(utils.web.getUrl(
data = json.loads(utils.web.getUrl(newestUrl % branch) 'https://pypi.org/pypi/limnoria/json'
.decode('utf8')) ).decode('utf8'))
version = data['commit']['committer']['date'] release_version = data['info']['version']
# zero-left-pad months and days
release_version = re.sub(
r'\.([0-9])\b', lambda m: '.0' + m.group(1), release_version
)
# fetch from Git
data = json.loads(utils.web.getUrl(
'https://api.github.com/repos/progval/Limnoria/'
'commits/master'
).decode('utf8'))
git_version = data['commit']['committer']['date']
# Strip the last 'Z': # Strip the last 'Z':
version = version.rsplit('T', 1)[0].replace('-', '.') git_version = git_version.rsplit('T', 1)[0].replace('-', '.')
if minisix.PY2 and isinstance(version, unicode):
version = version.encode('utf8') newest = _(
versions[branch] = version 'The newest version available online is %(release_version)s, '
newest = _('The newest versions available online are %s.') % \ 'or %(git_version)s in Git'
', '.join([_('%s (in %s)') % (y,x) ) % {'release_version': release_version, 'git_version': git_version}
for x,y in versions.items()])
except utils.web.Error as e: except utils.web.Error as e:
self.log.info('Couldn\'t get website version: %s', e) self.log.info('Couldn\'t get website version: %s', e)
newest = _('I couldn\'t fetch the newest version ' newest = _('I couldn\'t fetch the newest version '