refactor(migrator): own _pr/N PR-head contract
CI / test (push) Canceled after 0s

Extract the duplicated `_pr/<n>` deleted-branch PR-head branch name
into a single pure helper `refs.pr_head_branch(n)`, now the only
definition. The git-mirror layer (mirror.py) and the REST/entity
layer (issues.py) both call it instead of spelling the pattern, so
the two can no longer diverge — editing one side previously broke
the other silently and late (404/500 on PR create for deleted-branch
PRs only).

Behavior-preserving string round-trip. refs.py widens from
"cross-reference rewriting" to "reference-namespace knowledge"
(branch-name patterns + cross-ref rewriting), still pure stdlib. No
new test — a shared symbol prevents divergence by construction
(issue #3 testing decision); the deleted-branch round-trip stays
covered by the existing phase test seam.

Closes #3
This commit is contained in:
AlexKucera committed 2026-08-11 17:26:46 +02:00
1 parent 9d585f601a
commit 8ec9ce49db
8 files changed
+107 -13

No files matched your search

+4 -2
View File
@@ -31,6 +31,7 @@ from typing import Any
from .clients import ApiError, parallel
from .migration import Migration
from .refs import pr_head_branch
log = logging.getLogger(__name__)
@@ -140,10 +141,11 @@ def _create_entity(
head = item.get("head", {}) or {}
base = (item.get("base", {}) or {}).get("ref", "main")
# Source reports a deleted-branch PR's head as "refs/pull/<n>/head";
# the mirror recreated its commits on the target as branch _pr/<n>.
# the mirror recreated its commits on the target as branch _pr/<n>
# (shared branch name — see refs.pr_head_branch, the single source of truth).
head_ref = head.get("ref", "")
if not head_ref or head_ref.startswith("refs/pull/"):
head_ref = f"_pr/{item['number']}"
head_ref = pr_head_branch(item["number"])
created = m.tgt.post(
m.path("/pulls"),
body={