Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Versions: Prefix external package, add alternate tags #365

Merged
merged 2 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions github_app_geo_project/module/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
48 changes: 28 additions & 20 deletions github_app_geo_project/module/versions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
)
Expand Down Expand Up @@ -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"],
Expand Down Expand Up @@ -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"],
Expand Down Expand Up @@ -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}"

Expand All @@ -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)
Expand Down
24 changes: 18 additions & 6 deletions tests/test_module_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])},
Expand Down
Loading