V0.1 de la migration vers systemd
This commit is contained in:
parent
b23c0dde53
commit
016ac85bc7
9 changed files with 142 additions and 24 deletions
|
|
@ -29,7 +29,7 @@ def classify_webhook_event(payload: Dict[str, Any]) -> Optional[str]:
|
|||
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"}:
|
||||
if payload.get("issue") or payload.get("object_attributes") or action in {"open", "reopen", "close", "closed", "updated", "created", "edited", "label_updated", "label_added", "label_removed", "label_changed"}:
|
||||
return "issue"
|
||||
|
||||
return None
|
||||
|
|
@ -82,24 +82,47 @@ def normalize_labels(labels: Any) -> list[str]:
|
|||
|
||||
def extract_label_change(payload: Dict[str, Any]) -> Optional[Dict[str, Any]]:
|
||||
"""Extrait le changement de labels d’un payload d’issue."""
|
||||
changes = payload.get("changes") or {}
|
||||
labels_change = changes.get("labels") or changes.get("label")
|
||||
if not isinstance(labels_change, dict):
|
||||
action = str(payload.get("action") or payload.get("event") or "").lower()
|
||||
if not action.startswith("label"):
|
||||
return None
|
||||
|
||||
previous = normalize_labels(labels_change.get("previous"))
|
||||
current = normalize_labels(labels_change.get("current"))
|
||||
if not previous and not current:
|
||||
issue = payload.get("issue") or {}
|
||||
current_labels = normalize_labels(issue.get("labels") or payload.get("labels"))
|
||||
if not current_labels:
|
||||
return None
|
||||
|
||||
added = [label for label in current if label not in previous]
|
||||
removed = [label for label in previous if label not in current]
|
||||
if not added and not removed:
|
||||
return None
|
||||
label_payload = payload.get("label")
|
||||
label_name = None
|
||||
if isinstance(label_payload, dict):
|
||||
label_name = label_payload.get("name") or label_payload.get("title") or label_payload.get("label")
|
||||
elif isinstance(label_payload, str):
|
||||
label_name = label_payload
|
||||
|
||||
previous_labels = []
|
||||
if isinstance(payload.get("changes"), dict):
|
||||
prev = payload["changes"].get("labels") or payload["changes"].get("label")
|
||||
if isinstance(prev, dict):
|
||||
previous_labels = normalize_labels(prev.get("previous"))
|
||||
|
||||
if not previous_labels and issue.get("labels"):
|
||||
previous_labels = []
|
||||
|
||||
if action in {"label_removed", "label_deleted"}:
|
||||
return {
|
||||
"previous": previous_labels or ([label_name] if label_name else []),
|
||||
"current": current_labels,
|
||||
"added": [],
|
||||
"removed": [label_name] if label_name else [],
|
||||
}
|
||||
|
||||
added = [label for label in current_labels if label not in previous_labels]
|
||||
removed = [label for label in previous_labels if label not in current_labels]
|
||||
if not added and not removed and label_name:
|
||||
added = [label_name]
|
||||
|
||||
return {
|
||||
"previous": previous,
|
||||
"current": current,
|
||||
"previous": previous_labels,
|
||||
"current": current_labels,
|
||||
"added": added,
|
||||
"removed": removed,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue