feat: implement Codeberg → Gitea repo migrator
Replay git (mirror + LFS), labels, milestones, issues & PRs (with comments), and releases (with assets) entity-by-entity over the shared Forgejo/Gitea REST API. Two-pass issue/PR creation rewrites #NNN and URL cross-references to the target number space; deleted-branch PR heads are recreated as refs/heads/_pr/<n>. CLI: codeberg-to-gitea migrate owner/name (CODEBERG_TOKEN/GITEA_TOKEN) Verified end-to-end on AlexKucera/helm: 283 issues, 1 PR, 19 labels, 219 comments, git history, with cross-refs correctly rewritten.
This commit is contained in:
1 parent
601cf4c41e
commit
ab43b0311e
14 files changed
+1240
-23
No files matched your search
@@ -0,0 +1,59 @@
|
||||
"""Tests for cross-reference rewriting (no network)."""
|
||||
|
||||
from codeberg_to_gitea_migrator.refs import NumberMap, rewrite
|
||||
|
||||
|
||||
def _ref(numbers: dict[int, int], text: str) -> str:
|
||||
nm = NumberMap()
|
||||
for src, tgt in numbers.items():
|
||||
nm.add(src, tgt)
|
||||
return rewrite(
|
||||
text,
|
||||
nm,
|
||||
source_web_root="https://codeberg.org",
|
||||
target_web_root="https://git.babylondreams.de",
|
||||
)
|
||||
|
||||
|
||||
def test_hash_ref_rewritten_when_mapped() -> None:
|
||||
assert _ref({289: 2}, "Fixes #289 and more") == "Fixes #2 and more"
|
||||
|
||||
|
||||
def test_unknown_hash_ref_left_alone() -> None:
|
||||
assert _ref({289: 2}, "see #999 here") == "see #999 here"
|
||||
|
||||
|
||||
def test_self_mapping_left_unchanged() -> None:
|
||||
# Numbers that map to themselves aren't rewritten (keeps diffs clean).
|
||||
assert _ref({5: 5}, "ref #5") == "ref #5"
|
||||
|
||||
|
||||
def test_markdown_heading_not_matched() -> None:
|
||||
assert _ref({}, "## 2 Section") == "## 2 Section"
|
||||
|
||||
|
||||
def test_anchor_not_matched() -> None:
|
||||
# `C#123` — the '#' is glued to a word char, so not a ref.
|
||||
assert _ref({123: 1}, "use C#123 framework") == "use C#123 framework"
|
||||
|
||||
|
||||
def test_url_repointed_and_renumbered() -> None:
|
||||
out = _ref({290: 3}, "see https://codeberg.org/AlexKucera/helm/issues/290")
|
||||
assert out == "see https://git.babylondreams.de/AlexKucera/helm/issues/3"
|
||||
|
||||
|
||||
def test_url_host_only_when_number_unknown() -> None:
|
||||
out = _ref({}, "see https://codeberg.org/AlexKucera/helm/issues/42")
|
||||
assert out == "see https://git.babylondreams.de/AlexKucera/helm/issues/42"
|
||||
|
||||
|
||||
def test_number_map_any_mismatch() -> None:
|
||||
nm = NumberMap()
|
||||
assert nm.any_mismatch is False
|
||||
nm.add(1, 1)
|
||||
assert nm.any_mismatch is False
|
||||
nm.add(2, 5)
|
||||
assert nm.any_mismatch is True
|
||||
assert len(nm) == 2
|
||||
assert nm.get(2) == 5
|
||||
assert nm.get(99) is None
|
||||
Reference in new issue
Block a user