@@ -433,7 +433,21 @@ func Migrate(ctx *context.APIContext, form auth.MigrateRepoForm) {
433
433
opts .Releases = false
434
434
}
435
435
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
+
437
451
defer func () {
438
452
if e := recover (); e != nil {
439
453
var buf bytes.Buffer
@@ -443,7 +457,7 @@ func Migrate(ctx *context.APIContext, form auth.MigrateRepoForm) {
443
457
444
458
if err == nil {
445
459
repo .Status = models .RepositoryReady
446
- if err := models .UpdateRepositoryStatus (repo . ID , repo . Status ); err == nil {
460
+ if err := models .UpdateRepositoryCols (repo , "status" ); err == nil {
447
461
notification .NotifyMigrateRepository (ctx .User , ctxUser , repo )
448
462
return
449
463
}
@@ -456,13 +470,16 @@ func Migrate(ctx *context.APIContext, form auth.MigrateRepoForm) {
456
470
}
457
471
}()
458
472
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 )
463
475
return
464
476
}
465
477
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 ) {
466
483
switch {
467
484
case models .IsErrRepoAlreadyExist (err ):
468
485
ctx .Error (409 , "" , "The repository with the same name already exists." )
@@ -471,7 +488,7 @@ func Migrate(ctx *context.APIContext, form auth.MigrateRepoForm) {
471
488
case migrations .IsTwoFactorAuthError (err ):
472
489
ctx .Error (422 , "" , "Remote visit required two factors authentication." )
473
490
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 ()))
475
492
case models .IsErrNameReserved (err ):
476
493
ctx .Error (422 , "" , fmt .Sprintf ("The username '%s' is reserved." , err .(models.ErrNameReserved ).Name ))
477
494
case models .IsErrNamePatternNotAllowed (err ):
0 commit comments