Fix PR policy target ref resolution
sandbox/pipeline/pr-main There was a failure building this commit

This commit is contained in:
torsten committed 2026-08-04 19:44:36 +02:00
1 parent 5910e6747d
commit 58c3cd0559
2 files changed
+38 -1

No files matched your search

+38 -1
View File
@@ -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()]
File renamed without changes.