Files
Heimdall/scripts/ci/post_cve_comment.py
T

40 lines
1.3 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
"""Poste un commentaire CVE (Trivy + Dependency-Check) sur une PR Forgejo.
Usage: post_cve_comment.py
Env: FORGEJO_TOKEN, TRIVY_REPORT, DC_REPORT, REPO, PR_NUMBER"""
import json
import os
import urllib.request
body = ""
trivy = os.environ.get("TRIVY_REPORT", "")
dc = os.environ.get("DC_REPORT", "")
if trivy:
body += "\n" + trivy + "\n"
if dc:
body += "\n" + dc + "\n"
if not body.strip():
print("Aucune CVE à signaler — pas de commentaire")
raise SystemExit(0)
body = "## 🛡️ Rapport sécurité — CVE détectées\n\n" + body + "\n\n_Généré automatiquement par la CI (Trivy / OWASP Dependency-Check)._"
repo = os.environ.get("REPO", "")
pr = os.environ.get("PR_NUMBER", "")
token = os.environ.get("FORGEJO_TOKEN", "")
if not repo or not pr or not token:
print("::warning::REPO/PR_NUMBER/FORGEJO_TOKEN manquants — commentaire ignoré")
raise SystemExit(0)
url = f"https://forgejo.tordais.cc/api/v1/repos/{repo}/issues/{pr}/comments"
req = urllib.request.Request(
url,
data=json.dumps({"body": body}).encode(),
headers={"Authorization": f"token {token}", "Content-Type": "application/json"},
method="POST",
)
try:
urllib.request.urlopen(req)
print(f"Commentaire CVE posté sur la PR #{pr}")
except Exception as e:
print(f"::warning::Impossible de poster le commentaire CVE: {e}")