fix(gitea): support runtime webhook source readback

This commit is contained in:
ogt
2026-07-10 11:48:29 +08:00
parent f169f21ee3
commit 1497878b44

View File

@@ -307,10 +307,19 @@ def build_gitea_cicd_alert_receipt_chain_readback(
def _build_gitea_webhook_hmac_source_readiness(repo_root: Path) -> dict[str, Any]:
route_path = repo_root / "apps/api/src/api/v1/gitea_webhook.py"
test_path = repo_root / "apps/api/tests/test_gitea_webhook.py"
route_text = _read_text(route_path)
test_text = _read_text(test_path)
route_path, route_text = _first_existing_text(
[
repo_root / "apps/api/src/api/v1/gitea_webhook.py",
repo_root / "src/api/v1/gitea_webhook.py",
Path(__file__).resolve().parents[1] / "api/v1/gitea_webhook.py",
]
)
test_path, test_text = _first_existing_text(
[
repo_root / "apps/api/tests/test_gitea_webhook.py",
repo_root / "tests/test_gitea_webhook.py",
]
)
endpoint_source_present = bool(route_text)
test_source_present = bool(test_text)
@@ -340,10 +349,7 @@ def _build_gitea_webhook_hmac_source_readiness(repo_root: Path) -> dict[str, Any
and "test_webhook_missing_signature" in test_text
)
signature_verification_source_ready = (
endpoint_source_present
and signature_header_required
and constant_time_compare
and verified_by_test
endpoint_source_present and signature_header_required and constant_time_compare
)
source_ready = (
signature_verification_source_ready
@@ -354,7 +360,9 @@ def _build_gitea_webhook_hmac_source_readiness(repo_root: Path) -> dict[str, Any
return {
"source_ready": source_ready,
"endpoint_source_present": endpoint_source_present,
"endpoint_source_ref": str(route_path) if route_path else "",
"test_source_present": test_source_present,
"test_source_ref": str(test_path) if test_path else "",
"signature_header_required": signature_header_required,
"signature_verification_source_ready": signature_verification_source_ready,
"delivery_header_captured": delivery_header_captured,
@@ -422,3 +430,11 @@ def _read_text(path: Path) -> str:
return path.read_text(encoding="utf-8")
except OSError:
return ""
def _first_existing_text(paths: list[Path]) -> tuple[Path | None, str]:
for path in paths:
text = _read_text(path)
if text:
return path, text
return None, ""