From 58c3cd055958d7d659dc4b2555490ff1cabc3a63 Mon Sep 17 00:00:00 2001 From: Torsten Wierschin Date: Tue, 4 Aug 2026 19:44:36 +0200 Subject: [PATCH] Fix PR policy target ref resolution --- ci/check_pr_policies.py | 39 ++++++++++++++++++++++++++++++++++- {test => tests}/test_main.cpp | 0 2 files changed, 38 insertions(+), 1 deletion(-) rename {test => tests}/test_main.cpp (100%) diff --git a/ci/check_pr_policies.py b/ci/check_pr_policies.py index fb0cf7d..26e385b 100644 --- a/ci/check_pr_policies.py +++ b/ci/check_pr_policies.py @@ -22,8 +22,45 @@ TEST_PATTERNS = [ def run(cmd: str) -> str: return subprocess.check_output(cmd, shell=True, text=True).strip() +def git_ref_exists(ref: str) -> bool: + try: + subprocess.check_call( + f"git rev-parse --verify --quiet '{ref}'", + shell=True, + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + ) + return True + except subprocess.CalledProcessError: + return False + +def resolve_target_ref() -> str: + raw = os.environ.get("CHANGE_TARGET", "").strip() + + candidates = [] + if raw: + candidates.append(raw) + if not raw.startswith("origin/"): + candidates.append(f"origin/{raw}") + + candidates.extend([ + "origin/main", + "main", + ]) + + seen = set() + for ref in candidates: + if ref and ref not in seen: + seen.add(ref) + if git_ref_exists(ref): + return ref + + print("ERROR: Kein gültiger Ziel-Branch-Ref gefunden. Geprüft:", ", ".join(candidates)) + sys.exit(1) + def changed_files(): - target = os.environ.get("CHANGE_TARGET", "origin/main") + target = resolve_target_ref() + print(f"Vergleiche gegen Ziel-Ref: {target}") out = run(f"git diff --name-only {target}...HEAD") return [line.strip() for line in out.splitlines() if line.strip()] diff --git a/test/test_main.cpp b/tests/test_main.cpp similarity index 100% rename from test/test_main.cpp rename to tests/test_main.cpp