Skip to content

Commit

Permalink
Versions: Add alternate tags
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Jun 14, 2024
1 parent 8bf130b commit 6001e38
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 20 deletions.
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
42 changes: 25 additions & 17 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

0 comments on commit 6001e38

Please sign in to comment.