Merge pull request 'correction du modules bug_report' (#237) from dev into main
Reviewed-on: #237
This commit is contained in:
commit
f6a940cb58
1 changed files with 39 additions and 0 deletions
|
|
@ -16,6 +16,45 @@ TRACKING_FILE = os.path.join(BASE_DIR, "commandes", "gitlab_issues.json")
|
|||
LEGACY_REPORTS_FILE = os.path.join(BASE_DIR, "data", "gitlab_reports.json")
|
||||
|
||||
|
||||
def classify_webhook_event(payload: Dict[str, Any]) -> Optional[str]:
|
||||
"""Détermine si un webhook correspond à une issue ou à un commentaire."""
|
||||
object_kind = payload.get("object_kind")
|
||||
if object_kind in {"issue", "note"}:
|
||||
return object_kind
|
||||
|
||||
action = str(payload.get("action", "")).lower()
|
||||
if action in {"comment_created", "comment_updated", "commented"} or "comment" in payload:
|
||||
return "note"
|
||||
|
||||
if payload.get("issue") or payload.get("object_attributes") or action in {"open", "reopen", "close", "closed", "updated"}:
|
||||
return "issue"
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def extract_issue_iid(payload: Dict[str, Any]) -> Optional[str]:
|
||||
"""Extrait l’identifiant d’issue depuis plusieurs formats Forgejo/GitLab."""
|
||||
for container in (payload.get("object_attributes", {}), payload.get("issue", {}), payload.get("comment", {})):
|
||||
if not isinstance(container, dict):
|
||||
continue
|
||||
for key in ("iid", "number", "id"):
|
||||
value = container.get(key)
|
||||
if value not in (None, ""):
|
||||
return str(value)
|
||||
return None
|
||||
|
||||
|
||||
def extract_issue_identifier(issue_payload: Optional[Dict[str, Any]]) -> Optional[str]:
|
||||
"""Récupère un identifiant stable à stocker dans le tracking."""
|
||||
if not isinstance(issue_payload, dict):
|
||||
return None
|
||||
for key in ("iid", "number", "id"):
|
||||
value = issue_payload.get(key)
|
||||
if value not in (None, ""):
|
||||
return str(value)
|
||||
return None
|
||||
|
||||
|
||||
def load_tracking():
|
||||
"""Charge le tracking depuis gitlab_issues.json (avec migration automatique)"""
|
||||
tracking = {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue