feat(release): synthesize initial catalog entries
This commit is contained in:
@@ -15,6 +15,10 @@ from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey
|
||||
from govoplan_core.core.module_package_catalog import validate_module_package_catalog
|
||||
|
||||
from .catalog import DEFAULT_PUBLIC_BASE_URL, canonical_hash, fetch_json
|
||||
from .catalog_entry_synthesis import (
|
||||
synthesize_repository_catalog_entries,
|
||||
validate_initial_entry_closure,
|
||||
)
|
||||
from .contracts import collect_contracts
|
||||
from .git_state import collect_repository_snapshot
|
||||
from .model import CatalogEntryChange, SelectiveCatalogCandidate
|
||||
@@ -98,6 +102,7 @@ def build_selective_catalog_candidate(
|
||||
repo_versions=repo_versions,
|
||||
repo_contracts=repo_contracts,
|
||||
repository_base=repository_base.rstrip("/"),
|
||||
workspace=workspace,
|
||||
)
|
||||
enforce_complete_catalog_source_provenance(
|
||||
payload=candidate,
|
||||
@@ -290,6 +295,7 @@ def apply_repo_updates(
|
||||
repo_versions: dict[str, str],
|
||||
repo_contracts: dict[str, Any],
|
||||
repository_base: str,
|
||||
workspace: Path,
|
||||
) -> list[CatalogEntryChange]:
|
||||
changes: list[CatalogEntryChange] = []
|
||||
modules = payload.get("modules")
|
||||
@@ -345,8 +351,43 @@ def apply_repo_updates(
|
||||
handled.add(repo)
|
||||
|
||||
missing = sorted(set(repo_versions) - handled)
|
||||
if missing:
|
||||
raise ValueError(f"Selected repositories are not represented in the catalog: {', '.join(missing)}")
|
||||
initial_module_ids: set[str] = set()
|
||||
existing_module_ids = {
|
||||
str(entry.get("module_id") or "")
|
||||
for entry in modules
|
||||
if isinstance(entry, dict)
|
||||
}
|
||||
for repo in missing:
|
||||
entries = synthesize_repository_catalog_entries(
|
||||
repo=repo,
|
||||
version=repo_versions[repo],
|
||||
workspace=workspace,
|
||||
repository_base=repository_base,
|
||||
)
|
||||
for entry in entries:
|
||||
module_id = str(entry["module_id"])
|
||||
if module_id in existing_module_ids:
|
||||
raise ValueError(
|
||||
f"Cannot synthesize {repo}: module id {module_id!r} already belongs to another catalog entry."
|
||||
)
|
||||
modules.append(entry)
|
||||
existing_module_ids.add(module_id)
|
||||
initial_module_ids.add(module_id)
|
||||
changes.append(
|
||||
CatalogEntryChange(
|
||||
repo=repo,
|
||||
module_id=module_id,
|
||||
field="catalog_entry",
|
||||
before=None,
|
||||
after=json.dumps(entry, sort_keys=True),
|
||||
)
|
||||
)
|
||||
handled.add(repo)
|
||||
if initial_module_ids:
|
||||
validate_initial_entry_closure(
|
||||
catalog_modules=modules,
|
||||
initial_module_ids=initial_module_ids,
|
||||
)
|
||||
return changes
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user