Corrections commentaires des suivi de fonctionnalité et bug

This commit is contained in:
Mathis 2026-07-12 00:10:09 +02:00
parent a87178b36d
commit 187541f644

View file

@ -22,11 +22,14 @@ def classify_webhook_event(payload: Dict[str, Any]) -> Optional[str]:
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:
action = str(payload.get("action") or payload.get("event") or "").lower()
if action in {"comment_created", "comment_updated", "commented", "issue_comment_created", "issue_comment_updated"}:
return "note"
if payload.get("issue") or payload.get("object_attributes") or action in {"open", "reopen", "close", "closed", "updated"}:
if "comment" in payload or payload.get("comment") or "comment" in action:
return "note"
if payload.get("issue") or payload.get("object_attributes") or action in {"open", "reopen", "close", "closed", "updated", "created", "edited"}:
return "issue"
return None
@ -312,18 +315,20 @@ class BugReport(commands.Cog):
kuby_logger.warning("Bot still not ready after 10s. Proceeding anyway.")
payload = await request.json()
event_type = payload.get("object_kind")
event_type = classify_webhook_event(payload)
if event_type not in ["issue", "note"]:
kuby_logger.info("Webhook ignoré : type dévénement non reconnu")
kuby_logger.info(
"Webhook ignoré : type dévénement non reconnu (keys=%s action=%s object_kind=%s)",
list(payload.keys()),
payload.get("action") or payload.get("event"),
payload.get("object_kind"),
)
return web.json_response({"status": "ignored"}, status=200)
# Récupère l'IID de l'issue
issue_iid = str(
payload.get("object_attributes", {}).get("iid") or
payload.get("issue", {}).get("iid")
)
issue_iid = extract_issue_iid(payload)
if not issue_iid:
kuby_logger.warning("Webhook ignoré : aucun identifiant dissue trouvé dans le payload")
return web.json_response({"status": "no issue id"}, status=200)
@ -345,34 +350,45 @@ class BugReport(commands.Cog):
# 🕵️ 3. RÉCUPÉRATION DU TITRE
issue_title = (
payload.get("object_attributes", {}).get("title") or
payload.get("issue", {}).get("title", f"#{issue_iid}")
payload.get("object_attributes", {}).get("title") or
payload.get("issue", {}).get("title") or
payload.get("issue", {}).get("name") or
f"#{issue_iid}"
)
if event_type == "note":
# ⚡ NOUVEAU: Notifie les commentaires via le webhook (instantané)
note_attr = payload.get("object_attributes", {})
is_system = note_attr.get("system", False)
if not is_system:
comment_payload = payload.get("comment")
if isinstance(comment_payload, dict):
note_body = comment_payload.get("body") or comment_payload.get("content") or ""
author_name = (
payload.get("sender", {}).get("username")
or payload.get("sender", {}).get("login")
or payload.get("user", {}).get("name")
or "Développeur"
)
is_system = False
else:
note_attr = payload.get("object_attributes", {})
is_system = note_attr.get("system", False)
note_body = (
note_attr.get("note") or
note_attr.get("body") or
payload.get("note", "") or ""
)
author_name = payload.get("user", {}).get("name", "Développeur")
if note_body:
try:
embed = disnake.Embed(
title="💬 Nouveau commentaire sur votre signalement",
description=f"Le développeur a répondu à votre rapport **{issue_title}** :\n\n>>> {note_body}\n\n✍️ **Par :** {author_name}",
color=disnake.Color.orange()
)
embed.set_thumbnail(url=self.bot.user.display_avatar.url)
await user.send(embed=embed)
kuby_logger.info(f"Commentaire GitLab envoyé à {user} pour l'issue #{issue_iid}")
except (disnake.Forbidden, disnake.HTTPException) as e:
if not is_system and note_body:
try:
embed = disnake.Embed(
title="💬 Nouveau commentaire sur votre signalement",
description=f"Le développeur a répondu à votre rapport **{issue_title}** :\n\n>>> {note_body}\n\n✍️ **Par :** {author_name}",
color=disnake.Color.orange()
)
embed.set_thumbnail(url=self.bot.user.display_avatar.url)
await user.send(embed=embed)
kuby_logger.info(f"Commentaire envoyé à {user} pour l'issue #{issue_iid}")
except (disnake.Forbidden, disnake.HTTPException) as e:
kuby_logger.warning(f"Impossible d'envoyer le DM à {user}: {e}")
if dev and dev.id != user.id:
try: