14 Commits
Author SHA1 Message Date
AlexKucera 8b19ea502b chore(release): 1.0.0
CI / test (push) Canceled after 0s
Bump version to 1.0.0 across __init__.py, pyproject.toml, and
CITATION.cff (adds date-released); regenerate uv.lock. Promote the
accumulated Unreleased changelog entries to [1.0.0] - 2026-08-13.
2026-08-13 16:23:43 +02:00
AlexKucera e6fc0c7fb9 fix(migrator): retry failed writes serially
CI / test (push) Canceled after 0s
Pass-B writes (issue body rewrite + each comment) ran only at the
caller's --concurrency, so a transient target 5xx either aborted the
run or silently lost the write. A self-hosted Gitea throws bursts of
500s under concurrent writes, losing comments and leaving bodies with
stale cross-refs.

Failed writes are now deferred and replayed once serially (concurrency
1) after the concurrent wave -- serial load removes the backpressure
causing the 500s, so nearly all recover. Writes still failing serially
are logged and skipped; a genuinely-down target still aborts via
CircuitOpenError.

Adds two phase tests: persistent-fail (no abort) and transient (recover).
2026-08-13 16:10:10 +02:00
AlexKucera 8449a2bd81 chore: ignore local .secrets file
Holds live forge API tokens; must never be tracked.
2026-08-13 16:10:10 +02:00
AlexKucera 2a73e018b0 docs: add domain glossary for shared vocabulary
CI / test (push) Canceled after 0s
Establishes plain-language definitions for the codebase's core
concepts so that architecture reviews, ADRs, and module naming stay
consistent as the project evolves.
2026-08-11 17:27:53 +02:00
AlexKucera 8ec9ce49db 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
2026-08-11 17:26:46 +02:00
AlexKucera 9d585f601a refactor(migrator): bind repo-transfer context in Migration
CI / test (push) Canceled after 0s
Introduce a frozen Migration handle binding the identity quintet
(src/tgt clients, owner, name, NumberMap) the four entity phases
previously received as five loose params. The phases now take the
handle; migrate_repo builds one and drives all phases with it.
Retire RefCtx and the shared _path helper (absorbed into the
handle's .path()/.rewrite() accessors), deleting code rather than
leaving dead types. migrate_issues_and_prs mutates m.numbers in
place (returns None).

Add tests/test_phases.py: the previously-untested entity layer is
now reachable through the Migration seam (two mock-transport
clients + a number map, no network), covering the two-pass issue/PR
flow, label/milestone mappings, state-setting, best-effort PR merge,
the deleted-branch head fallback, and release+asset re-upload.

Closes #2
2026-08-11 16:31:58 +02:00
AlexKucera 1613ec72b8 refactor(migrator): centralize git in GitRunner
CI / test (push) Canceled after 0s
Introduce git.GitRunner as the sole git-op seam: the only place git is
invoked. It owns subprocess execution, per-op timeout, error redaction, and
auth delivery. Forge tokens move off the remote URL entirely onto a
non-persisted per-op http.<host>.extraHeader, so they never reach the
command line, a remote URL, or .git/config.

Rewrite the mirror procedure to drive GitRunner and retire the URL-token
helpers (_authed/_bare/_redact/_scrub_remote_tokens) plus the try/finally
scrub -- their reason to exist vanishes. mirror_repo's signature and report
stay unchanged; cli/migrate import the re-exported GitError/timeout
unchanged. The procedure's ordering invariants are now locked by a
recording-fake test, and an AST guard fails the suite if any git op bypasses
the seam.

Closes the 2026-08-11 audit's HIGH (token in GitError) and MEDIUM (token
in .git/config) at one structural root cause.

Closes #1
2026-08-11 15:36:35 +02:00
AlexKucera 137734673d perf(migrator): parallelize and harden migration
CI / test (push) Canceled after 0s
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
AlexKucera 867d982786 chore: ignore agent tooling, record GitNexus docs
Add .pi-subagents/, .claude/, and CLAUDE.md to .gitignore, and append the GitNexus code-intelligence instructions to the root AGENTS.md.
2026-08-11 13:35:47 +02:00
AlexKucera 299c061f26 fix(security): mask forge tokens in logs and disk
CI / test (push) Canceled after 0s
Close two token-leak paths in the git mirror and harden the supply
chain per the OWASP audit (audit/2026-08-11/security-report.md).

Runtime fixes:
- mirror GitError masks the embedded oauth2:<token> in both the
  failing command line and git's stderr before raising; cli now
  catches GitError with a clean message instead of an uncaught
  traceback that printed the live token.
- Scrub token-bearing remote URLs from the bare config at the end
  of each run so tokens aren't persisted in .git/config.
- Default mirror workdir is per-user 0700 (/tmp/cb2gitea-<uid>),
  not a world-readable /tmp/cb2gitea.

Supply chain:
- Commit uv.lock; CI installs via uv sync --frozen (hash-verified).
- Pin Gitea Actions to commit SHAs, not mutable @vN tags.
- Pin the ruff rule set and exclude audit/ for reproducible linting.

Adds tests/test_mirror.py for the redaction helpers.
2026-08-11 11:48:32 +02:00
AlexKucera 7d26e2d4ca docs: record one-shot/cutover migration model as intentional design 2026-08-11 11:18:42 +02:00
AlexKucera ab43b0311e 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.
2026-08-11 11:12:06 +02:00
AlexKucera 601cf4c41e chore: bootstrap project scaffold
CI / test (push) Canceled after 0s
Set up the codeberg-to-gitea-migrator project: Python package
with src/ layout (hatchling, ruff, pytest), GPL-3.0-or-later
license, CITATION.cff, README, ADRs for stack/license/forge, and
DOX-structured AGENTS.md. Add Gitea Actions CI.

The package is a stub; migration modules land in follow-up commits.
2026-08-11 09:46:13 +02:00
AlexKucera ddca225fde Initial commit 2026-08-11 09:15:57 +02:00