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:
1 parent
9d585f601a
commit
8ec9ce49db
8 files changed
+107
-13
No files matched your search
@@ -1,10 +1,15 @@
|
||||
"""Cross-reference rewriting between source and target forges.
|
||||
"""Reference-namespace knowledge: branch-name patterns and cross-reference
|
||||
rewriting between source and target forges.
|
||||
|
||||
Source issue/PR numbers rarely line up with target numbers after migration
|
||||
(deleted source issues leave gaps; the target assigns fresh dense numbers).
|
||||
Rewriting ``#NNN`` references and full issue/PR URLs in migrated text keeps
|
||||
cross-references pointing at the *right* target entities instead of dangling
|
||||
or pointing at the wrong one.
|
||||
Two concerns share this module because both are reference-namespace knowledge:
|
||||
|
||||
* :func:`pr_head_branch` names the ``_pr/<n>`` branch a deleted-branch PR's head
|
||||
is recreated under — the single source of truth shared by the git-mirror layer
|
||||
(mirror.py) and the REST/entity layer (issues.py).
|
||||
* :class:`NumberMap` + :func:`rewrite` rewrite ``#NNN`` references and full
|
||||
issue/PR URLs in migrated text, keeping cross-references pointing at the
|
||||
*right* target entities. Source numbers are sparse after deletions; the target
|
||||
assigns fresh dense numbers.
|
||||
|
||||
Usage: build a :class:`NumberMap` as entities are created, then call
|
||||
:func:`rewrite` on every title, body, and comment before it lands on target.
|
||||
@@ -24,6 +29,18 @@ HASH_REF = re.compile(r"(?<![#\w])#(\d+)\b")
|
||||
URL_REF = re.compile(r"(?P<base>https?://[^\s/]+/[^\s]+?)/(?:issues|pulls)/(?P<num>\d+)")
|
||||
|
||||
|
||||
# -- branch-name patterns ------------------------------------------------
|
||||
def pr_head_branch(n: int) -> str:
|
||||
"""Branch name a deleted-branch PR's head is recreated under, e.g. ``_pr/42``.
|
||||
|
||||
Single source of truth for the ``_pr/<n>`` namespace. The git-mirror layer
|
||||
(mirror.py) pushes ``refs/heads/<this>`` for each PR whose source head is
|
||||
gone; the REST layer (issues.py) sends ``<this>`` as that PR's head. Both
|
||||
call this so the two cannot diverge on the prefix or the format.
|
||||
"""
|
||||
return f"_pr/{n}"
|
||||
|
||||
|
||||
class NumberMap:
|
||||
"""source issue/PR number → target issue/PR number."""
|
||||
|
||||
|
||||
Reference in new issue
Block a user