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"}: if object_kind in {"issue", "note"}:
return object_kind return object_kind
action = str(payload.get("action", "")).lower() action = str(payload.get("action") or payload.get("event") or "").lower()
if action in {"comment_created", "comment_updated", "commented"} or "comment" in payload: if action in {"comment_created", "comment_updated", "commented", "issue_comment_created", "issue_comment_updated"}:
return "note" 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 "issue"
return None return None
@ -312,17 +315,19 @@ class BugReport(commands.Cog):
kuby_logger.warning("Bot still not ready after 10s. Proceeding anyway.") kuby_logger.warning("Bot still not ready after 10s. Proceeding anyway.")
payload = await request.json() payload = await request.json()
event_type = payload.get("object_kind") event_type = classify_webhook_event(payload)
if event_type not in ["issue", "note"]: 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) return web.json_response({"status": "ignored"}, status=200)
# Récupère l'IID de l'issue # Récupère l'IID de l'issue
issue_iid = str( issue_iid = extract_issue_iid(payload)
payload.get("object_attributes", {}).get("iid") or
payload.get("issue", {}).get("iid")
)
if not issue_iid: if not issue_iid:
kuby_logger.warning("Webhook ignoré : aucun identifiant dissue trouvé dans le payload") kuby_logger.warning("Webhook ignoré : aucun identifiant dissue trouvé dans le payload")
@ -346,15 +351,26 @@ class BugReport(commands.Cog):
# 🕵️ 3. RÉCUPÉRATION DU TITRE # 🕵️ 3. RÉCUPÉRATION DU TITRE
issue_title = ( issue_title = (
payload.get("object_attributes", {}).get("title") or payload.get("object_attributes", {}).get("title") or
payload.get("issue", {}).get("title", f"#{issue_iid}") payload.get("issue", {}).get("title") or
payload.get("issue", {}).get("name") or
f"#{issue_iid}"
) )
if event_type == "note": if event_type == "note":
# ⚡ NOUVEAU: Notifie les commentaires via le webhook (instantané) # ⚡ NOUVEAU: Notifie les commentaires via le webhook (instantané)
note_attr = payload.get("object_attributes", {}) comment_payload = payload.get("comment")
is_system = note_attr.get("system", False) if isinstance(comment_payload, dict):
note_body = comment_payload.get("body") or comment_payload.get("content") or ""
if not is_system: 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_body = (
note_attr.get("note") or note_attr.get("note") or
note_attr.get("body") or note_attr.get("body") or
@ -362,17 +378,17 @@ class BugReport(commands.Cog):
) )
author_name = payload.get("user", {}).get("name", "Développeur") author_name = payload.get("user", {}).get("name", "Développeur")
if note_body: if not is_system and note_body:
try: try:
embed = disnake.Embed( embed = disnake.Embed(
title="💬 Nouveau commentaire sur votre signalement", 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}", 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() color=disnake.Color.orange()
) )
embed.set_thumbnail(url=self.bot.user.display_avatar.url) embed.set_thumbnail(url=self.bot.user.display_avatar.url)
await user.send(embed=embed) await user.send(embed=embed)
kuby_logger.info(f"Commentaire GitLab envoyé à {user} pour l'issue #{issue_iid}") kuby_logger.info(f"Commentaire envoyé à {user} pour l'issue #{issue_iid}")
except (disnake.Forbidden, disnake.HTTPException) as e: except (disnake.Forbidden, disnake.HTTPException) as e:
kuby_logger.warning(f"Impossible d'envoyer le DM à {user}: {e}") kuby_logger.warning(f"Impossible d'envoyer le DM à {user}: {e}")
if dev and dev.id != user.id: if dev and dev.id != user.id:
try: try: