| 607 | |
| 608 | |
| 609 | def _extract_github_base_sha(env: dict[str, str]) -> str | None: |
| 610 | event_path = env.get("GITHUB_EVENT_PATH", "").strip() |
| 611 | if not event_path: |
| 612 | return None |
| 613 | |
| 614 | path = Path(event_path) |
| 615 | if not path.exists(): |
| 616 | return None |
| 617 | |
| 618 | try: |
| 619 | payload = json.loads(path.read_text(encoding="utf-8")) |
| 620 | except (json.JSONDecodeError, OSError): |
| 621 | return None |
| 622 | |
| 623 | base_sha = payload.get("pull_request", {}).get("base", {}).get("sha") |
| 624 | if isinstance(base_sha, str) and base_sha.strip(): |
| 625 | return base_sha.strip() |
| 626 | return None |
| 627 | |
| 628 | |
| 629 | def _resolve_default_branch_name(repo_path: Path, env: dict[str, str]) -> str | None: |