"""Liest den Gitea-Actions-Event-Kontext (GitHub-kompatible Env-Vars). Gitea spiegelt die GITHUB_*-Variablen: GITHUB_REPOSITORY (owner/repo), GITHUB_EVENT_PATH (JSON des auslösenden Events), GITHUB_EVENT_NAME. """ import json import os def repo_slug(): """(owner, repo) aus GITHUB_REPOSITORY.""" full = os.environ.get("GITHUB_REPOSITORY", "") if "/" not in full: raise SystemExit("[context] GITHUB_REPOSITORY fehlt oder ist ungültig.") owner, repo = full.split("/", 1) return owner, repo def event(): """Geparstes Event-JSON (oder {} wenn nicht vorhanden).""" path = os.environ.get("GITHUB_EVENT_PATH", "") if path and os.path.exists(path): with open(path, encoding="utf-8") as fh: return json.load(fh) return {} def pull_request(): """PR-Infos aus dem Event oder None, wenn das Event kein PR ist. Liefert dict: index, title, body, author, base_ref, head_sha. """ pr = event().get("pull_request") if not pr: return None return { "index": pr.get("number"), "title": pr.get("title", ""), "body": pr.get("body", "") or "", "author": (pr.get("user") or {}).get("login", ""), "base_ref": (pr.get("base") or {}).get("ref", ""), "head_sha": (pr.get("head") or {}).get("sha", ""), }