(node: object, path_hint: str = "")
| 16 | |
| 17 | |
| 18 | def _collect_alerts(node: object, path_hint: str = "") -> list[dict[str, object]]: |
| 19 | alerts: list[dict[str, object]] = [] |
| 20 | |
| 21 | if isinstance(node, dict): |
| 22 | if _is_alert(node): |
| 23 | alert = dict(node) |
| 24 | if path_hint and not alert.get("Path"): |
| 25 | alert["Path"] = path_hint |
| 26 | alerts.append(alert) |
| 27 | return alerts |
| 28 | |
| 29 | node_path = path_hint |
| 30 | path_value = node.get("Path") |
| 31 | if isinstance(path_value, str) and path_value: |
| 32 | node_path = path_value |
| 33 | |
| 34 | alert_list = node.get("alerts") |
| 35 | if isinstance(alert_list, list): |
| 36 | alerts.extend(_collect_alerts(alert_list, node_path)) |
| 37 | |
| 38 | file_map = node.get("files") |
| 39 | if isinstance(file_map, dict): |
| 40 | for file_path, file_node in file_map.items(): |
| 41 | hint = file_path if isinstance(file_path, str) else node_path |
| 42 | alerts.extend(_collect_alerts(file_node, hint)) |
| 43 | |
| 44 | for key, value in node.items(): |
| 45 | if key in {"alerts", "files", "Path"}: |
| 46 | continue |
| 47 | hint = node_path |
| 48 | if isinstance(key, str) and ("/" in key or key.endswith(".adoc") or key.endswith(".asciidoc")): |
| 49 | hint = key |
| 50 | alerts.extend(_collect_alerts(value, hint)) |
| 51 | |
| 52 | elif isinstance(node, list): |
| 53 | for item in node: |
| 54 | alerts.extend(_collect_alerts(item, path_hint)) |
| 55 | |
| 56 | return alerts |
| 57 | |
| 58 | |
| 59 | def parse_args() -> argparse.Namespace: |
no test coverage detected