semantics
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# [DEF:backend.src.scripts.clean_release_cli:Module]
|
||||
# [DEF:CleanReleaseCliScript:Module]
|
||||
# @COMPLEXITY: 3
|
||||
# @SEMANTICS: cli, clean-release, candidate, artifacts, manifest
|
||||
# @PURPOSE: Provide headless CLI commands for candidate registration, artifact import and manifest build.
|
||||
@@ -12,10 +12,18 @@ from datetime import date, datetime, timezone
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from ..models.clean_release import CandidateArtifact, ReleaseCandidate
|
||||
from ..services.clean_release.approval_service import approve_candidate, reject_candidate
|
||||
from ..services.clean_release.compliance_execution_service import ComplianceExecutionService
|
||||
from ..services.clean_release.approval_service import (
|
||||
approve_candidate,
|
||||
reject_candidate,
|
||||
)
|
||||
from ..services.clean_release.compliance_execution_service import (
|
||||
ComplianceExecutionService,
|
||||
)
|
||||
from ..services.clean_release.enums import CandidateStatus
|
||||
from ..services.clean_release.publication_service import publish_candidate, revoke_publication
|
||||
from ..services.clean_release.publication_service import (
|
||||
publish_candidate,
|
||||
revoke_publication,
|
||||
)
|
||||
|
||||
|
||||
# [DEF:build_parser:Function]
|
||||
@@ -88,6 +96,8 @@ def build_parser() -> argparse.ArgumentParser:
|
||||
revoke.add_argument("--json", action="store_true")
|
||||
|
||||
return parser
|
||||
|
||||
|
||||
# [/DEF:build_parser:Function]
|
||||
|
||||
|
||||
@@ -97,6 +107,7 @@ def build_parser() -> argparse.ArgumentParser:
|
||||
# @POST: Candidate is persisted in DRAFT status.
|
||||
def run_candidate_register(args: argparse.Namespace) -> int:
|
||||
from ..dependencies import get_clean_release_repository
|
||||
|
||||
repository = get_clean_release_repository()
|
||||
existing = repository.get_candidate(args.candidate_id)
|
||||
if existing is not None:
|
||||
@@ -114,6 +125,8 @@ def run_candidate_register(args: argparse.Namespace) -> int:
|
||||
repository.save_candidate(candidate)
|
||||
print(json.dumps({"status": "ok", "candidate_id": candidate.id}))
|
||||
return 0
|
||||
|
||||
|
||||
# [/DEF:run_candidate_register:Function]
|
||||
|
||||
|
||||
@@ -123,6 +136,7 @@ def run_candidate_register(args: argparse.Namespace) -> int:
|
||||
# @POST: Artifact is persisted for candidate.
|
||||
def run_artifact_import(args: argparse.Namespace) -> int:
|
||||
from ..dependencies import get_clean_release_repository
|
||||
|
||||
repository = get_clean_release_repository()
|
||||
candidate = repository.get_candidate(args.candidate_id)
|
||||
if candidate is None:
|
||||
@@ -144,6 +158,8 @@ def run_artifact_import(args: argparse.Namespace) -> int:
|
||||
|
||||
print(json.dumps({"status": "ok", "artifact_id": artifact.id}))
|
||||
return 0
|
||||
|
||||
|
||||
# [/DEF:run_artifact_import:Function]
|
||||
|
||||
|
||||
@@ -166,8 +182,18 @@ def run_manifest_build(args: argparse.Namespace) -> int:
|
||||
print(json.dumps({"status": "error", "message": str(exc)}))
|
||||
return 1
|
||||
|
||||
print(json.dumps({"status": "ok", "manifest_id": manifest.id, "version": manifest.manifest_version}))
|
||||
print(
|
||||
json.dumps(
|
||||
{
|
||||
"status": "ok",
|
||||
"manifest_id": manifest.id,
|
||||
"version": manifest.manifest_version,
|
||||
}
|
||||
)
|
||||
)
|
||||
return 0
|
||||
|
||||
|
||||
# [/DEF:run_manifest_build:Function]
|
||||
|
||||
|
||||
@@ -180,7 +206,9 @@ def run_compliance_run(args: argparse.Namespace) -> int:
|
||||
|
||||
repository = get_clean_release_repository()
|
||||
config_manager = get_config_manager()
|
||||
service = ComplianceExecutionService(repository=repository, config_manager=config_manager)
|
||||
service = ComplianceExecutionService(
|
||||
repository=repository, config_manager=config_manager
|
||||
)
|
||||
|
||||
try:
|
||||
result = service.execute_run(
|
||||
@@ -203,6 +231,8 @@ def run_compliance_run(args: argparse.Namespace) -> int:
|
||||
}
|
||||
print(json.dumps(payload))
|
||||
return 0
|
||||
|
||||
|
||||
# [/DEF:run_compliance_run:Function]
|
||||
|
||||
|
||||
@@ -219,7 +249,9 @@ def run_compliance_status(args: argparse.Namespace) -> int:
|
||||
print(json.dumps({"status": "error", "message": "run not found"}))
|
||||
return 2
|
||||
|
||||
report = next((item for item in repository.reports.values() if item.run_id == run.id), None)
|
||||
report = next(
|
||||
(item for item in repository.reports.values() if item.run_id == run.id), None
|
||||
)
|
||||
payload = {
|
||||
"status": "ok",
|
||||
"run_id": run.id,
|
||||
@@ -231,6 +263,8 @@ def run_compliance_status(args: argparse.Namespace) -> int:
|
||||
}
|
||||
print(json.dumps(payload))
|
||||
return 0
|
||||
|
||||
|
||||
# [/DEF:run_compliance_status:Function]
|
||||
|
||||
|
||||
@@ -259,6 +293,8 @@ def _to_payload(value: Any) -> Dict[str, Any]:
|
||||
row = {column.name: getattr(value, column.name) for column in table.columns}
|
||||
return _normalize(row)
|
||||
raise TypeError(f"unsupported payload type: {type(value)!r}")
|
||||
|
||||
|
||||
# [/DEF:_to_payload:Function]
|
||||
|
||||
|
||||
@@ -275,13 +311,17 @@ def run_compliance_report(args: argparse.Namespace) -> int:
|
||||
print(json.dumps({"status": "error", "message": "run not found"}))
|
||||
return 2
|
||||
|
||||
report = next((item for item in repository.reports.values() if item.run_id == run.id), None)
|
||||
report = next(
|
||||
(item for item in repository.reports.values() if item.run_id == run.id), None
|
||||
)
|
||||
if report is None:
|
||||
print(json.dumps({"status": "error", "message": "report not found"}))
|
||||
return 2
|
||||
|
||||
print(json.dumps({"status": "ok", "report": _to_payload(report)}))
|
||||
return 0
|
||||
|
||||
|
||||
# [/DEF:run_compliance_report:Function]
|
||||
|
||||
|
||||
@@ -299,8 +339,14 @@ def run_compliance_violations(args: argparse.Namespace) -> int:
|
||||
return 2
|
||||
|
||||
violations = repository.get_violations_by_run(args.run_id)
|
||||
print(json.dumps({"status": "ok", "items": [_to_payload(item) for item in violations]}))
|
||||
print(
|
||||
json.dumps(
|
||||
{"status": "ok", "items": [_to_payload(item) for item in violations]}
|
||||
)
|
||||
)
|
||||
return 0
|
||||
|
||||
|
||||
# [/DEF:run_compliance_violations:Function]
|
||||
|
||||
|
||||
@@ -324,8 +370,14 @@ def run_approve(args: argparse.Namespace) -> int:
|
||||
print(json.dumps({"status": "error", "message": str(exc)}))
|
||||
return 2
|
||||
|
||||
print(json.dumps({"status": "ok", "decision": decision.decision, "decision_id": decision.id}))
|
||||
print(
|
||||
json.dumps(
|
||||
{"status": "ok", "decision": decision.decision, "decision_id": decision.id}
|
||||
)
|
||||
)
|
||||
return 0
|
||||
|
||||
|
||||
# [/DEF:run_approve:Function]
|
||||
|
||||
|
||||
@@ -349,8 +401,14 @@ def run_reject(args: argparse.Namespace) -> int:
|
||||
print(json.dumps({"status": "error", "message": str(exc)}))
|
||||
return 2
|
||||
|
||||
print(json.dumps({"status": "ok", "decision": decision.decision, "decision_id": decision.id}))
|
||||
print(
|
||||
json.dumps(
|
||||
{"status": "ok", "decision": decision.decision, "decision_id": decision.id}
|
||||
)
|
||||
)
|
||||
return 0
|
||||
|
||||
|
||||
# [/DEF:run_reject:Function]
|
||||
|
||||
|
||||
@@ -377,6 +435,8 @@ def run_publish(args: argparse.Namespace) -> int:
|
||||
|
||||
print(json.dumps({"status": "ok", "publication": _to_payload(publication)}))
|
||||
return 0
|
||||
|
||||
|
||||
# [/DEF:run_publish:Function]
|
||||
|
||||
|
||||
@@ -401,6 +461,8 @@ def run_revoke(args: argparse.Namespace) -> int:
|
||||
|
||||
print(json.dumps({"status": "ok", "publication": _to_payload(publication)}))
|
||||
return 0
|
||||
|
||||
|
||||
# [/DEF:run_revoke:Function]
|
||||
|
||||
|
||||
@@ -435,10 +497,12 @@ def main(argv: Optional[List[str]] = None) -> int:
|
||||
|
||||
print(json.dumps({"status": "error", "message": "unknown command"}))
|
||||
return 2
|
||||
|
||||
|
||||
# [/DEF:main:Function]
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
|
||||
# [/DEF:backend.src.scripts.clean_release_cli:Module]
|
||||
# [/DEF:CleanReleaseCliScript:Module]
|
||||
|
||||
Reference in New Issue
Block a user