résolution de conflit
This commit is contained in:
commit
2a2ed11156
1 changed files with 42 additions and 67 deletions
|
|
@ -16,41 +16,6 @@ TRACKING_FILE = os.path.join(BASE_DIR, "commandes", "gitlab_issues.json")
|
||||||
LEGACY_REPORTS_FILE = os.path.join(BASE_DIR, "data", "gitlab_reports.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 "comment" in action or "comment" in payload:
|
|
||||||
return "note"
|
|
||||||
|
|
||||||
if "issue" in payload or "object_attributes" in payload or payload.get("issue"):
|
|
||||||
return "issue"
|
|
||||||
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def extract_issue_iid(payload: Dict[str, Any]) -> Optional[str]:
|
|
||||||
"""Extrait l’identifiant d’issue depuis plusieurs formats Forgejo/GitLab."""
|
|
||||||
candidates = [
|
|
||||||
payload.get("object_attributes", {}).get("iid"),
|
|
||||||
payload.get("object_attributes", {}).get("id"),
|
|
||||||
payload.get("object_attributes", {}).get("number"),
|
|
||||||
payload.get("issue", {}).get("iid"),
|
|
||||||
payload.get("issue", {}).get("number"),
|
|
||||||
payload.get("issue", {}).get("id"),
|
|
||||||
payload.get("comment", {}).get("issue_id"),
|
|
||||||
payload.get("comment", {}).get("issue_number"),
|
|
||||||
]
|
|
||||||
|
|
||||||
for candidate in candidates:
|
|
||||||
if candidate is not None:
|
|
||||||
return str(candidate)
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def load_tracking():
|
def load_tracking():
|
||||||
"""Charge le tracking depuis gitlab_issues.json (avec migration automatique)"""
|
"""Charge le tracking depuis gitlab_issues.json (avec migration automatique)"""
|
||||||
tracking = {}
|
tracking = {}
|
||||||
|
|
@ -139,8 +104,12 @@ class BugReportModal(disnake.ui.Modal):
|
||||||
)
|
)
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
issue_iid = str(result.get("iid"))
|
issue_iid = extract_issue_identifier(result)
|
||||||
# ⚡ NOUVEAU: Utilise le tracking unifié
|
if not issue_iid:
|
||||||
|
kuby_logger.warning("Impossible de déterminer l’ID de l’issue créée depuis le retour Forgejo/GitLab")
|
||||||
|
await interaction.edit_original_response(content="✅ Votre rapport a été envoyé, mais l’identifiant de l’issue n’a pas pu être récupéré automatiquement.")
|
||||||
|
return
|
||||||
|
|
||||||
self.cog.issue_data[issue_iid] = {
|
self.cog.issue_data[issue_iid] = {
|
||||||
"requester_id": interaction.user.id,
|
"requester_id": interaction.user.id,
|
||||||
"last_note_id": 0,
|
"last_note_id": 0,
|
||||||
|
|
@ -151,7 +120,7 @@ class BugReportModal(disnake.ui.Modal):
|
||||||
content=(
|
content=(
|
||||||
"✅ Votre bug a été signalé avec succès ! "
|
"✅ Votre bug a été signalé avec succès ! "
|
||||||
"Nous avons bien été averti et le bug sera réglé dans la prochaine mise à jour. "
|
"Nous avons bien été averti et le bug sera réglé dans la prochaine mise à jour. "
|
||||||
f"[Voir l'issue]({result.get('web_url')})"
|
f"[Voir l'issue]({result.get('web_url') or result.get('html_url')})"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
|
@ -204,8 +173,12 @@ class FeatureSuggestionModal(disnake.ui.Modal):
|
||||||
)
|
)
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
issue_iid = str(result.get("iid"))
|
issue_iid = extract_issue_identifier(result)
|
||||||
# ⚡ NOUVEAU: Utilise le tracking unifié
|
if not issue_iid:
|
||||||
|
kuby_logger.warning("Impossible de déterminer l’ID de l’issue créée depuis le retour Forgejo/GitLab")
|
||||||
|
await interaction.edit_original_response(content="✅ Votre suggestion a été envoyée, mais l’identifiant de l’issue n’a pas pu être récupéré automatiquement.")
|
||||||
|
return
|
||||||
|
|
||||||
self.cog.issue_data[issue_iid] = {
|
self.cog.issue_data[issue_iid] = {
|
||||||
"requester_id": interaction.user.id,
|
"requester_id": interaction.user.id,
|
||||||
"last_note_id": 0,
|
"last_note_id": 0,
|
||||||
|
|
@ -216,7 +189,7 @@ class FeatureSuggestionModal(disnake.ui.Modal):
|
||||||
content=(
|
content=(
|
||||||
"✅ Votre suggestion a été envoyée avec succès ! "
|
"✅ Votre suggestion a été envoyée avec succès ! "
|
||||||
"Merci de contribuer à l'amélioration du bot. "
|
"Merci de contribuer à l'amélioration du bot. "
|
||||||
f"[Voir l'issue]({result.get('web_url')})"
|
f"[Voir l'issue]({result.get('web_url') or result.get('html_url')})"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
|
@ -300,15 +273,18 @@ 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")
|
||||||
|
|
||||||
# 🕵️ 1. DÉTECTION DU TYPE (Compatibilité Forgejo vs GitLab)
|
|
||||||
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")
|
||||||
return web.json_response({"status": "ignored"}, status=200)
|
return web.json_response({"status": "ignored"}, status=200)
|
||||||
|
|
||||||
# 🕵️ 2. RÉCUPÉRATION DE L'ID DU TICKET
|
# Récupère l'IID de l'issue
|
||||||
issue_iid = extract_issue_iid(payload)
|
issue_iid = str(
|
||||||
|
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 d’issue trouvé dans le payload")
|
kuby_logger.warning("Webhook ignoré : aucun identifiant d’issue trouvé dans le payload")
|
||||||
return web.json_response({"status": "no issue id"}, status=200)
|
return web.json_response({"status": "no issue id"}, status=200)
|
||||||
|
|
@ -335,16 +311,11 @@ class BugReport(commands.Cog):
|
||||||
)
|
)
|
||||||
|
|
||||||
if event_type == "note":
|
if event_type == "note":
|
||||||
# 🕵️ 4. EXTRACTION DU COMMENTAIRE FORGEJO / GITLAB
|
# ⚡ NOUVEAU: Notifie les commentaires via le webhook (instantané)
|
||||||
if "comment" in payload:
|
note_attr = payload.get("object_attributes", {})
|
||||||
# Mode Forgejo
|
is_system = note_attr.get("system", False)
|
||||||
note_body = payload["comment"].get("body", "")
|
|
||||||
author_name = payload.get("sender", {}).get("username", "Développeur")
|
if not is_system:
|
||||||
is_system = False
|
|
||||||
else:
|
|
||||||
# Mode GitLab
|
|
||||||
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
|
||||||
|
|
@ -352,19 +323,23 @@ class BugReport(commands.Cog):
|
||||||
)
|
)
|
||||||
author_name = payload.get("user", {}).get("name", "Développeur")
|
author_name = payload.get("user", {}).get("name", "Développeur")
|
||||||
|
|
||||||
if not is_system and note_body:
|
if note_body:
|
||||||
try:
|
try:
|
||||||
embed = disnake.Embed(
|
embed = disnake.Embed(
|
||||||
title="💬 Nouveau commentaire sur votre signalement",
|
title="💬 Nouveau commentaire sur votre signalement",
|
||||||
description=f"L'équipe 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()
|
||||||
)
|
)
|
||||||
if self.bot.user.display_avatar:
|
|
||||||
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 envoyé à {user} pour l'issue #{issue_iid}")
|
kuby_logger.info(f"Commentaire GitLab 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:
|
||||||
|
try:
|
||||||
|
await dev.send(f"⚠️ [DM BLOQUÉ] Impossible d'envoyer le commentaire à {user} pour l'issue #{issue_iid}")
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
elif event_type == "issue":
|
elif event_type == "issue":
|
||||||
# 🕵️ 5. GESTION DES CLÔTURES (Optionnel : si tu fermes le ticket sur Forgejo)
|
# 🕵️ 5. GESTION DES CLÔTURES (Optionnel : si tu fermes le ticket sur Forgejo)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue