43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from engine.devops_agent.spec import WorkflowSpec
|
|
|
|
|
|
def _compile_triggers(frontmatter: dict[str, Any]) -> list[dict[str, Any]]:
|
|
triggers = frontmatter.get("on") or {}
|
|
if not isinstance(triggers, dict):
|
|
return []
|
|
|
|
compiled: list[dict[str, Any]] = []
|
|
for event_name, event_config in triggers.items():
|
|
normalized = {
|
|
"event": str(event_name),
|
|
}
|
|
if isinstance(event_config, dict):
|
|
normalized.update(event_config)
|
|
compiled.append(normalized)
|
|
return compiled
|
|
|
|
|
|
def compile_workflow(spec: WorkflowSpec) -> dict[str, Any]:
|
|
policy = spec.frontmatter.get("policy") or {}
|
|
evidence = spec.frontmatter.get("evidence") or {}
|
|
|
|
return {
|
|
"version": 1,
|
|
"workflow_name": spec.name,
|
|
"provider": spec.provider,
|
|
"source": str(spec.source_path.as_posix()),
|
|
"triggers": _compile_triggers(spec.frontmatter),
|
|
"safe_outputs": spec.frontmatter.get("safe_outputs") or {},
|
|
"required_evidence": evidence.get("required") or [],
|
|
"policy": {
|
|
"require_human_merge": bool(policy.get("require_human_merge", True)),
|
|
"require_fixed_issue": bool(policy.get("require_fixed_issue", False)),
|
|
"path_scope": policy.get("path_scope") or [],
|
|
},
|
|
"instructions": spec.body,
|
|
}
|