AlexKucera 137734673d
CI / test (push) Canceled after 0s
perf(migrator): parallelize and harden migration
The migrator was fully synchronous — every HTTP round-trip and git
op serialized over one blocking client, and a stalled git push could
hang it forever. Overlap the independent phases and bound the slow /
memory-heavy paths.

- clients: ApiClient is now thread-safe (per-thread httpx.Client) so
  labels, milestones, Pass-B comments, and release assets overlap via
  parallel(); --concurrency sizes it (default 8). Pass A issue/PR
  creation stays serial — entities are created in source-number order
  so the number map resolves forward cross-references.
- releases: stream assets through a spooled temp file instead of
  buffering each whole into memory; upload them concurrently.
- reliability: per-op --git-timeout (was unbounded hangs), a circuit
  breaker that aborts on a degraded target, jittered retry backoff,
  and a bulk timeout for large asset transfers.
- round-trips: set an issue's milestone in the create body; batch the
  deleted-branch PR-head git push and refs/pull/* pruning.
- fix: raw_get_stream 4xx/5xx raised AttributeError (resp.read().text
  on bytes) instead of ApiError — now decodes. Wrap mirror git ops in
  try/finally so tokenized remote URLs are scrubbed even on timeout.
- refactor: drop the typer dependency — the CLI is now stdlib argparse
  (same subcommands, flags, and env vars); remove dead code surfaced by
  a whole-repo audit (has_lfs, name_map, unused owner_repo param,
  stored-but-unread _base_url).
- ci: enable the uv download cache.

Tests cover parallel ordering, the circuit breaker, and the streamed
4xx path. CHANGELOG updated; the runtime dependency is now just httpx.
2026-08-11 13:36:11 +02:00
2026-08-11 09:46:13 +02:00
2026-08-11 09:46:13 +02:00
2026-08-11 09:46:13 +02:00

codeberg-to-gitea-migrator

Migrate a repository from Codeberg (Forgejo) to a self-hosted Gitea instance — code, full git history, issues & PRs (with comments), releases & assets, labels, milestones, and LFS objects.

Gitea ships its own POST /repos/migrate importer, but it failed on the target repo across several settings, so this tool replays every entity directly via the shared Forgejo/Gitea REST API for full control.

What it migrates

  • Code & history — git clone --mirror + push --mirror (branches, tags, notes).
  • LFS — objects fetched and pushed alongside the mirror (no-op when absent).
  • Labels — recreated with colour, description, exclusive/archived flags.
  • Milestones — title, description, state, due date.
  • Issues & PRs — created in source-number order with comments; #NNN references and source URLs are rewritten to the target's number space.
  • Pull-request heads — when the source branch was deleted (common for merged/closed PRs), the head commits are recreated on the target as refs/heads/_pr/<n> so the PR can be rebuilt.
  • Releases & assets — non-draft releases with binary assets re-uploaded.

Requirements

  • Python ≥ 3.11
  • git on PATH (git-lfs optional — used automatically when present)
  • A Codeberg API token (read:issue, read:repository)
  • A Gitea API token (write:issue, write:repository; write:user if you want the tool to create the target repo for you)

Usage

python -m pip install -e ".[dev]"

export CODEBERG_TOKEN=***      # source (read)
export GITEA_TOKEN=***         # target (write)

codeberg-to-gitea migrate AlexKucera/helm          # owner defaults to your user
codeberg-to-gitea migrate AlexKucera/helm -v        # verbose
codeberg-to-gitea migrate someorg/somerepo --delete-existing   # clean re-run

Options: --source-url (default https://codeberg.org), --target-url (default https://git.babylondreams.de), --skip-git / --skip-issues / --skip-releases, --delete-existing, -v.

If the target token lacks write:user, create the empty target repo by hand (via the web UI) first; the migrator then populates it.

Fidelity notes

The public Gitea API stamps author and timestamp server-side, so migrated issues/PRs/comments are attributed to the migration token user with migration timestamps — original authors and dates are not preserved. Assignees and reactions are not migrated. Cross-references (#NNN, issue/PR URLs) are rewritten to stay correct.

Development

pytest                    # tests (network-free)
ruff check .              # lint
ruff format --check .     # format check

License

GPL-3.0-or-later — see LICENSE.

S
Description
No description provided
Readme GPL-3.0 Cite this repository
164 KiB
0 Stars 1 Watchers 0 Forks
Languages
Python 100%