- Writing custom git flow scripts - finishing up without extensive testing

This commit is contained in:
Josako
2025-12-11 09:47:19 +01:00
parent fe9fc047ff
commit 2c8347c91b
8 changed files with 389 additions and 24 deletions

43
scripts/git/core/hooks.py Normal file
View File

@@ -0,0 +1,43 @@
from __future__ import annotations
import os
import shlex
import subprocess
from typing import Dict
from . import config, output
def run_hooks(event: str, context: Dict[str, str] | None = None) -> None:
"""Voer alle geconfigureerde hooks voor een gegeven event uit.
Hooks worden gedefinieerd in `CONFIG.hooks[event]` als een lijst van
shell-commando's. We geven context door via environment-variabelen.
"""
hooks = config.CONFIG.hooks.get(event) or []
if not hooks:
return
base_env = os.environ.copy()
base_env.setdefault("GITFLOW_EVENT", event)
if context:
for key, value in context.items():
base_env[f"GITFLOW_{key.upper()}"] = value
for cmd in hooks:
# Eenvoudige logging
output.info(f"[HOOK {event}] {cmd}")
if config.CONFIG.dry_run:
output.info("[DRY-RUN] Hook niet echt uitgevoerd.")
continue
# Gebruik shlex.split zodat eenvoudige strings netjes opgesplitst worden.
args = shlex.split(cmd)
result = subprocess.run(args, env=base_env, text=True)
if result.returncode != 0:
raise RuntimeError(
f"Hook voor event '{event}' faalde met exitcode {result.returncode}: {cmd}"
)