fix(api): delete the repository when an API migration fails (v17) #255
No reviewers
Labels
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
codefloe/forgejo-codefloe!255
Loading…
Reference in a new issue
No description provided.
Delete branch "pat-s/fix-migrate-api-cleanup-orphan-v17"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Port of arbinel/arbinel#30 to v17, which is the branch codefloe.com builds from.
Why
MigrateRepositoryreturns a nil repository on failure, and assigning that torepomade the deferred delete inPOST /api/v1/repos/migrateskip itsif repo != nilguard.The API path creates no task, so nothing can finish or retry such a repository: its subpages redirect to the home page, which breaks the repository switcher, and SSH fails with an internal error while HTTPS keeps working.
Production had 17 repositories in this state, reported in forum topic 232; all of them have been repaired by hand.
What
POST /api/v1/repos/migratenow deletes the repository it created, as the existing cleanup intended, including when the git data had already landed.Context
The regression test replays the reported failure: a Gitea-type migration whose source token lacks
read:issue, which fails after the git data was imported.It fails without the fix on this branch, because the repository survives;
TestAPIRepoMigrateConflictstill passes.This only covers migrations that return an error.
A process killed mid-migration runs no deferred cleanup, so it can still leave a repository in this state:
krmbzds/jumpstart-pro-railsleft no failure notice and may be such a case, though that is unconfirmed.Written with Claude Code (Opus 5.5).
Only the two migration tests were run locally.
🤖 Generated with Claude Code
b1fac11eaff13dc808e4f13dc808e42868fab0e02868fab0e0a4e36184bc