(repo_path: Path, diff_base: str | None, env: dict[str, str])
| 646 | |
| 647 | |
| 648 | def _resolve_base_ref(repo_path: Path, diff_base: str | None, env: dict[str, str]) -> str: |
| 649 | if diff_base and diff_base.strip(): |
| 650 | return diff_base.strip() |
| 651 | |
| 652 | github_base_ref = env.get("GITHUB_BASE_REF", "").strip() |
| 653 | if github_base_ref: |
| 654 | github_candidate = f"refs/remotes/origin/{github_base_ref}" |
| 655 | if _git_ref_exists(repo_path, github_candidate): |
| 656 | return github_candidate |
| 657 | |
| 658 | github_base_sha = _extract_github_base_sha(env) |
| 659 | if github_base_sha and _git_ref_exists(repo_path, github_base_sha): |
| 660 | return github_base_sha |
| 661 | |
| 662 | origin_head = _resolve_origin_head_ref(repo_path) |
| 663 | if origin_head and _git_ref_exists(repo_path, origin_head): |
| 664 | return origin_head |
| 665 | |
| 666 | if _git_ref_exists(repo_path, "refs/remotes/origin/main"): |
| 667 | return "refs/remotes/origin/main" |
| 668 | |
| 669 | if _git_ref_exists(repo_path, "refs/remotes/origin/master"): |
| 670 | return "refs/remotes/origin/master" |
| 671 | |
| 672 | raise ValueError( |
| 673 | "Unable to resolve a base ref for diff-scope. Pass --diff-base explicitly " |
| 674 | "(for example: --diff-base origin/main)." |
| 675 | ) |
| 676 | |
| 677 | |
| 678 | def _get_current_branch_name(repo_path: Path) -> str | None: |
no test coverage detected