docs(security): add source control ref detail diff [skip ci]

This commit is contained in:
Your Name
2026-05-13 09:16:31 +08:00
parent b63c6f9b79
commit 611093de5b
15 changed files with 1546 additions and 27 deletions

View File

@@ -63,9 +63,40 @@ def proposed_steps(event: dict[str, Any]) -> list[str]:
return steps
def detail_by_repo(path: str | None) -> dict[tuple[str, str], dict[str, Any]]:
if not path:
return {}
payload = load_json(Path(path))
return {
(str(item.get("gitea_repo", "")), str(item.get("github_repo", ""))): item
for item in payload.get("repos", [])
if isinstance(item, dict)
}
def main_shas_from_detail(detail: dict[str, Any]) -> tuple[str, str]:
branch = detail.get("branch_diff", {})
if not isinstance(branch, dict):
return "", ""
for item in branch.get("sha_mismatch", []):
if isinstance(item, dict) and item.get("name") == "main":
return str(item.get("gitea_sha", "")), str(item.get("github_sha", ""))
for key in ("matching", "only_gitea", "only_github"):
for item in branch.get(key, []):
if isinstance(item, dict) and item.get("name") == "main":
sha = str(item.get("sha", ""))
if key == "only_gitea":
return sha, ""
if key == "only_github":
return "", sha
return sha, sha
return "", ""
def build_plan(args: argparse.Namespace) -> dict[str, Any]:
events = [load_json(Path(path)) for path in args.source_events]
gitea_inventory = load_json(Path(args.gitea_inventory))
details = detail_by_repo(args.ref_detail_diff)
inventory_ready = gitea_inventory.get("status") == "ok"
inventory_gate_status = "ready" if inventory_ready else "blocked"
@@ -79,6 +110,10 @@ def build_plan(args: argparse.Namespace) -> dict[str, Any]:
for event in events:
gitea_repo = str(event.get("gitea_repo", ""))
github_repo = str(event.get("github_repo", ""))
detail = details.get((gitea_repo, github_repo), {})
branch_detail = detail.get("branch_diff", {}) if isinstance(detail, dict) else {}
tag_detail = detail.get("tag_diff", {}) if isinstance(detail, dict) else {}
detail_gitea_main, detail_github_main = main_shas_from_detail(detail)
plans.append(
{
"gitea_repo": gitea_repo,
@@ -86,13 +121,13 @@ def build_plan(args: argparse.Namespace) -> dict[str, Any]:
"risk": risk_for_repo(gitea_repo),
"source_status": str(event.get("status", "")),
"divergence_summary": {
"gitea_branch_count": int(event.get("branch_count_gitea", 0)),
"github_branch_count": int(event.get("branch_count_github", 0)),
"gitea_tag_count": int(event.get("tag_count_gitea", 0)),
"github_tag_count": int(event.get("tag_count_github", 0)),
"gitea_main_sha": str(event.get("latest_sha_gitea", "")),
"github_main_sha": str(event.get("latest_sha_github", "")),
"blocking_reason": str(event.get("blocking_reason", "")),
"gitea_branch_count": int(branch_detail.get("gitea_count", event.get("branch_count_gitea", 0))),
"github_branch_count": int(branch_detail.get("github_count", event.get("branch_count_github", 0))),
"gitea_tag_count": int(tag_detail.get("gitea_count", event.get("tag_count_gitea", 0))),
"github_tag_count": int(tag_detail.get("github_count", event.get("tag_count_github", 0))),
"gitea_main_sha": detail_gitea_main or str(event.get("latest_sha_gitea", "")),
"github_main_sha": detail_github_main or str(event.get("latest_sha_github", "")),
"blocking_reason": str(detail.get("blocking_reason") or event.get("blocking_reason", "")),
},
"proposed_plan_steps": proposed_steps(event),
"execution_gates": DEFAULT_EXECUTION_GATES,
@@ -215,6 +250,7 @@ def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("--date", required=True)
parser.add_argument("--gitea-inventory", default="docs/security/gitea-repo-inventory.snapshot.json")
parser.add_argument("--ref-detail-diff")
parser.add_argument("--source-event", action="append", dest="source_events", required=True)
parser.add_argument("--output-json", required=True)
parser.add_argument("--output-md", required=True)