diff --git a/github_app_geo_project/module/utils.py b/github_app_geo_project/module/utils.py index f69f692e43c..7063878c206 100644 --- a/github_app_geo_project/module/utils.py +++ b/github_app_geo_project/module/utils.py @@ -662,12 +662,23 @@ def get_alternate_versions(security: c2cciutils.security.Security, branch: str) _LOGGER.warning("No Version column in the SECURITY.md") return [] + last = False + result = [] for row in security.data: if row[version_index] == branch: - return [v.strip() for v in row[alternate_index].split(",") if v.strip()] + result = [v.strip() for v in row[alternate_index].split(",") if v.strip()] + last = True + elif last: + last = False + break + + if last: + result.append("latest") - _LOGGER.warning("Branch %s not found in the SECURITY.md", branch) - return [] + if not result: + _LOGGER.warning("Branch %s not found in the SECURITY.md", branch) + + return result def manage_updated(status: dict[str, Any], key: str, days_old: int = 2) -> None: diff --git a/github_app_geo_project/module/versions/__init__.py b/github_app_geo_project/module/versions/__init__.py index 811c0f3de51..4d23804beba 100644 --- a/github_app_geo_project/module/versions/__init__.py +++ b/github_app_geo_project/module/versions/__init__.py @@ -239,13 +239,16 @@ async def process( raise VersionException("Failed to clone the repository") version_status = status.versions[version] - for alternate in context.module_event_data.alternate_versions or []: - status.versions[alternate] = version_status version_status.names_by_datasource.clear() version_status.dependencies_by_datasource.clear() transversal_status = context.transversal_status - _get_names(context, version_status.names_by_datasource, version) + _get_names( + context, + version_status.names_by_datasource, + version, + alternate_versions=context.module_event_data.alternate_versions, + ) message = module_utils.HtmlMessage( utils.format_json(json.loads(version_status.model_dump_json())["names_by_datasource"]) ) @@ -418,6 +421,7 @@ def _get_names( context: module.ProcessContext[configuration.VersionsConfiguration, _EventData, _TransversalStatus], names_by_datasource: dict[str, _TransversalStatusNameByDatasource], version: str, + alternate_versions: list[str] | None = None, ) -> None: for filename in subprocess.run( # nosec ["git", "ls-files", "pyproject.toml", "*/pyproject.toml"], @@ -455,26 +459,30 @@ def _get_names( docker_config = data.get("publish", {}).get("docker", {}) if docker_config: names = names_by_datasource.setdefault("docker", _TransversalStatusNameByDatasource()).names + all_versions = [version] + if alternate_versions: + all_versions.extend(alternate_versions) for conf in docker_config.get("images", []): for tag in conf.get("tags", ["{version}"]): for repository_conf in docker_config.get( "repository", c2cciutils.configuration.DOCKER_REPOSITORY_DEFAULT ).values(): - repository_server = repository_conf.get("server", False) - add_names = [] - if repository_server: - add_names.append( - f"{repository_server}/{conf.get('name')}:{tag.format(version=version)}" - ) + for ver in all_versions: + repository_server = repository_conf.get("server", False) + add_names = [] + if repository_server: + add_names.append( + f"{repository_server}/{conf.get('name')}:{tag.format(version=ver)}" + ) - else: - add_names = [ - f"{conf.get('name')}:{tag.format(version=version)}", - f"docker.io/{conf.get('name')}:{tag.format(version=version)}", - ] - for add_name in add_names: - if add_name not in names: - names.append(add_name) + else: + add_names = [ + f"{conf.get('name')}:{tag.format(version=ver)}", + f"docker.io/{conf.get('name')}:{tag.format(version=ver)}", + ] + for add_name in add_names: + if add_name not in names: + names.append(add_name) for filename in subprocess.run( # nosec ["git", "ls-files", "package.json", "*/package.json"], @@ -611,14 +619,15 @@ def _update_upstream_versions( transversal_status = context.transversal_status for external_config in context.module_config.get("external-packages", []): package = external_config["package"] + name = f"endoflife.date/{package}" datasource = external_config["datasource"] module_utils.manage_updated_separated( - transversal_status.updated, transversal_status.repositories, package + transversal_status.updated, transversal_status.repositories, name ) package_status: _TransversalStatusRepo = context.transversal_status.repositories.setdefault( - package, _TransversalStatusRepo() + name, _TransversalStatusRepo() ) package_status.url = f"https://endoflife.date/{package}" @@ -630,7 +639,6 @@ def _update_upstream_versions( return package_status.upstream_updated = datetime.datetime.now() - package_status.url = f"https://endoflife.date/{package}" response = requests.get(f"https://endoflife.date/api/{package}.json", timeout=10) if not response.ok: _LOGGER.error("Failed to get the data for %s", package) diff --git a/tests/test_module_versions.py b/tests/test_module_versions.py index 6fd39b60969..3db8062ca3f 100644 --- a/tests/test_module_versions.py +++ b/tests/test_module_versions.py @@ -733,17 +733,29 @@ def test_update_upstream_versions() -> None: _update_upstream_versions(context) - assert list(context.transversal_status.updated.keys()) == ["package1", "package2"] - assert list(context.transversal_status.repositories.keys()) == ["package1", "package2"] - assert context.transversal_status.repositories["package1"].url == "https://endoflife.date/package1" - assert context.transversal_status.repositories["package2"].url == "https://endoflife.date/package2" - assert context.transversal_status.repositories["package1"].versions == { + assert list(context.transversal_status.updated.keys()) == [ + "endoflife.date/package1", + "endoflife.date/package2", + ] + assert list(context.transversal_status.repositories.keys()) == [ + "endoflife.date/package1", + "endoflife.date/package2", + ] + assert ( + context.transversal_status.repositories["endoflife.date/package1"].url + == "https://endoflife.date/package1" + ) + assert ( + context.transversal_status.repositories["endoflife.date/package2"].url + == "https://endoflife.date/package2" + ) + assert context.transversal_status.repositories["endoflife.date/package1"].versions == { "1.0": _TransversalStatusVersion( support="2038-12-31", names_by_datasource={"datasource1": _TransversalStatusNameByDatasource(names=["package1"])}, ) } - assert context.transversal_status.repositories["package2"].versions == { + assert context.transversal_status.repositories["endoflife.date/package2"].versions == { "v1.0": _TransversalStatusVersion( support="2038-12-31", names_by_datasource={"datasource2": _TransversalStatusNameByDatasource(names=["package2"])},