@@ -433,7 +433,21 @@ func Migrate(ctx *context.APIContext, form auth.MigrateRepoForm) {
433433 opts .Releases = false
434434 }
435435
436- var repo * models.Repository
436+ repo , err := models .CreateRepository (ctx .User , ctxUser , models.CreateRepoOptions {
437+ Name : opts .RepoName ,
438+ Description : opts .Description ,
439+ OriginalURL : opts .CloneAddr ,
440+ IsPrivate : opts .Private ,
441+ IsMirror : opts .Mirror ,
442+ Status : models .RepositoryBeingMigrated ,
443+ })
444+ if err != nil {
445+ handleMigrateError (ctx , ctxUser , remoteAddr , err )
446+ return
447+ }
448+
449+ opts .MigrateToRepoID = repo .ID
450+
437451 defer func () {
438452 if e := recover (); e != nil {
439453 var buf bytes.Buffer
@@ -443,7 +457,7 @@ func Migrate(ctx *context.APIContext, form auth.MigrateRepoForm) {
443457
444458 if err == nil {
445459 repo .Status = models .RepositoryReady
446- if err := models .UpdateRepositoryStatus (repo . ID , repo . Status ); err == nil {
460+ if err := models .UpdateRepositoryCols (repo , "status" ); err == nil {
447461 notification .NotifyMigrateRepository (ctx .User , ctxUser , repo )
448462 return
449463 }
@@ -456,13 +470,16 @@ func Migrate(ctx *context.APIContext, form auth.MigrateRepoForm) {
456470 }
457471 }()
458472
459- repo , err = migrations .MigrateRepository (ctx .User , ctxUser .Name , opts )
460- if err == nil {
461- log .Trace ("Repository migrated: %s/%s" , ctxUser .Name , form .RepoName )
462- ctx .JSON (201 , repo .APIFormat (models .AccessModeAdmin ))
473+ if _ , err = migrations .MigrateRepository (ctx .User , ctxUser .Name , opts ); err != nil {
474+ handleMigrateError (ctx , ctxUser , remoteAddr , err )
463475 return
464476 }
465477
478+ log .Trace ("Repository migrated: %s/%s" , ctxUser .Name , form .RepoName )
479+ ctx .JSON (201 , repo .APIFormat (models .AccessModeAdmin ))
480+ }
481+
482+ func handleMigrateError (ctx * context.APIContext , repoOwner * models.User , remoteAddr string , err error ) {
466483 switch {
467484 case models .IsErrRepoAlreadyExist (err ):
468485 ctx .Error (409 , "" , "The repository with the same name already exists." )
@@ -471,7 +488,7 @@ func Migrate(ctx *context.APIContext, form auth.MigrateRepoForm) {
471488 case migrations .IsTwoFactorAuthError (err ):
472489 ctx .Error (422 , "" , "Remote visit required two factors authentication." )
473490 case models .IsErrReachLimitOfRepo (err ):
474- ctx .Error (422 , "" , fmt .Sprintf ("You have already reached your limit of %d repositories." , ctxUser .MaxCreationLimit ()))
491+ ctx .Error (422 , "" , fmt .Sprintf ("You have already reached your limit of %d repositories." , repoOwner .MaxCreationLimit ()))
475492 case models .IsErrNameReserved (err ):
476493 ctx .Error (422 , "" , fmt .Sprintf ("The username '%s' is reserved." , err .(models.ErrNameReserved ).Name ))
477494 case models .IsErrNamePatternNotAllowed (err ):
0 commit comments