support/scripts/pkg-stats: add better checking in check_package_get_latest_version_by_guess()

The 'rtl8723ds' name, when queried from release-monitoring.org at
https://release-monitoring.org/api/projects/?pattern=rtl8723ds returns
one project, with one "stable_versions" array, which is empty. This
was not expected by the pkg-stats code, causing an exception:

Task exception was never retrieved
future: <Task finished name='Task-764' coro=<check_package_latest_version_get() done, defined at /home/thomas/projets/buildroot/./support/scripts/pkg-stats:558> exception=IndexError('list index out of range')>
Traceback (most recent call last):
  File "/home/thomas/projets/buildroot/./support/scripts/pkg-stats", line 566, in check_package_latest_version_get
    if await check_package_get_latest_version_by_guess(session, pkg):
  File "/home/thomas/projets/buildroot/./support/scripts/pkg-stats", line 544, in check_package_get_latest_version_by_guess
    projects[0]['stable_versions'][0],
IndexError: list index out of range

This commit therefore improves the checks done on the results received
from release-monitoring.org to avoid this issue.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
(cherry picked from commit f1e3b2bb01)
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
This commit is contained in:
Thomas Petazzoni 2022-07-27 23:09:18 +02:00 committed by Peter Korsgaard
parent 96ccfcaa66
commit d236f924ea

View File

@ -536,12 +536,17 @@ async def check_package_get_latest_version_by_guess(session, pkg, retry=True):
projects = [p for p in data['projects'] if p['name'] == pkg.name and 'stable_versions' in p]
projects.sort(key=lambda x: x['id'])
if len(projects) > 0:
check_package_latest_version_set_status(pkg,
RM_API_STATUS_FOUND_BY_PATTERN,
projects[0]['stable_versions'][0],
projects[0]['id'])
return True
if len(projects) == 0:
return False
if len(projects[0]['stable_versions']) == 0:
return False
check_package_latest_version_set_status(pkg,
RM_API_STATUS_FOUND_BY_PATTERN,
projects[0]['stable_versions'][0],
projects[0]['id'])
return True
except (aiohttp.ClientError, asyncio.TimeoutError):
if retry: