V1.1 de l'amélioration du suivi des issues #266
1 changed files with 41 additions and 1 deletions
|
|
@ -231,6 +231,34 @@ def normalize_tracking_issue_id(issue_iid: Any) -> Optional[str]:
|
|||
return None
|
||||
|
||||
|
||||
def extract_requester_id_from_payload(payload: Dict[str, Any]) -> Optional[int]:
|
||||
"""Essaie d'extraire l'ID Discord du demandeur depuis la description du ticket ou le payload webhook."""
|
||||
text_candidates = []
|
||||
for key in ("description", "body", "content"):
|
||||
value = payload.get(key)
|
||||
if isinstance(value, str) and value.strip():
|
||||
text_candidates.append(value)
|
||||
|
||||
issue_payload = payload.get("issue") or {}
|
||||
for key in ("description", "body", "content"):
|
||||
value = issue_payload.get(key)
|
||||
if isinstance(value, str) and value.strip():
|
||||
text_candidates.append(value)
|
||||
|
||||
object_attributes = payload.get("object_attributes") or {}
|
||||
for key in ("description", "body", "content"):
|
||||
value = object_attributes.get(key)
|
||||
if isinstance(value, str) and value.strip():
|
||||
text_candidates.append(value)
|
||||
|
||||
for text in text_candidates:
|
||||
matches = re.findall(r"\b(\d{15,20})\b", text)
|
||||
if matches:
|
||||
return int(matches[0])
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def load_tracking():
|
||||
"""Charge le tracking depuis gitlab_issues.json (avec migration automatique)"""
|
||||
tracking = {}
|
||||
|
|
@ -605,7 +633,19 @@ class BugReport(commands.Cog):
|
|||
|
||||
issue_data = self.issue_data.get(issue_iid)
|
||||
if not issue_data:
|
||||
return web.json_response({"status": "untracked issue"}, status=200)
|
||||
inferred_requester_id = extract_requester_id_from_payload(payload)
|
||||
if inferred_requester_id is None:
|
||||
kuby_logger.warning(f"Webhook issue #{issue_iid} without tracked requester_id and no Discord ID found in payload")
|
||||
return web.json_response({"status": "untracked issue"}, status=200)
|
||||
|
||||
self.issue_data[issue_iid] = {
|
||||
"requester_id": inferred_requester_id,
|
||||
"last_note_id": 0,
|
||||
"type": "webhook-recovered"
|
||||
}
|
||||
save_tracking(self.issue_data)
|
||||
issue_data = self.issue_data[issue_iid]
|
||||
kuby_logger.info(f"Tracking entry recreated for issue #{issue_iid} from webhook payload")
|
||||
|
||||
user_id = issue_data.get("requester_id")
|
||||
if not user_id:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue