Parse a PR number, and the repo when the spec is a GitHub pull URL.
(spec: str)
| 61 | |
| 62 | |
| 63 | def parse_pr_spec(spec: str) -> PrSpec: |
| 64 | """Parse a PR number, and the repo when the spec is a GitHub pull URL.""" |
| 65 | match = PR_SPEC_RE.fullmatch(spec.strip()) |
| 66 | if match is None: |
| 67 | raise ReleaseError( |
| 68 | f"invalid PR spec {spec!r}; use a number on --upstream-repo " |
| 69 | "or a GitHub pull URL on that repo or --fork" |
| 70 | ) |
| 71 | owner = match.group("owner") |
| 72 | name = match.group("name") |
| 73 | repo = f"{owner}/{name}" if owner and name else None |
| 74 | return PrSpec(number=int(match.group("num")), repo=repo) |
| 75 | |
| 76 | |
| 77 | def resolve_pr_repo(spec: PrSpec, *, upstream_url: str, fork_url: str) -> str: |