"""Wandelt ein ausgefuelltes 'Neues Wissen'-Issue in einen tools.yaml-Eintrag. Kern der Automatisierung (Idee): Issue -> yaml-Eintrag -> MR (mit Vorschau). Aufruf: # Issue-Text aus Datei oder STDIN: python scripts/issue_to_source.py < issue.md glab issue view 42 | python scripts/issue_to_source.py # direkt an config/tools.yaml anhaengen: python scripts/issue_to_source.py --append < issue.md Erwartet die Abschnitte der Vorlage (.gitlab/issue_templates/Neues_Wissen.md): Tool/Domaene, Link(s), Verarbeitung (Strategie), Sichtbarkeit (Scope), Ansprechpartner, Optionen, Hinweise. """ from __future__ import annotations import argparse import re import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parents[1])) from src.strategy_detect import detect_strategy, sniff_strategy # noqa: E402 FIELD_MAP = { "tool": ["welches tool", "tool", "domaene", "domäne"], "sources": ["quellen", "quelle", "link"], "owners": ["verantwortlich", "owners"], "contact": ["kontakt", "contact"], "options": ["optionen"], } def _slug(s: str) -> str: s = re.sub(r"[^a-z0-9]+", "-", s.lower()) return s.strip("-")[:40] or "neues-wissen" def parse_issue(text: str) -> dict: """Zerlegt den Issue-Text in Felder (anhand der ###-Ueberschriften). Quellen-Zeilen haben das Format: URL | Strategie | Scope (Strategie/Scope optional). Fuehrendes "- " (Markdown-Liste) wird entfernt. """ sections: dict[str, str] = {} cur = None buf: list[str] = [] for line in text.splitlines(): m = re.match(r"^#{2,4}\s+(.*)", line.strip()) if m: if cur: sections[cur] = "\n".join(buf).strip() cur = m.group(1).strip().lower() buf = [] elif cur: if line.strip().startswith("