@@ -433,17 +433,32 @@ 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
440
454
fmt .Fprintf (& buf , "Handler crashed with error: %v" , log .Stack (2 ))
455
+
441
456
err = errors .New (buf .String ())
442
457
}
443
458
444
459
if err == nil {
445
460
repo .Status = models .RepositoryReady
446
- if err := models .UpdateRepositoryStatus (repo . ID , repo . Status ); err == nil {
461
+ if err := models .UpdateRepositoryCols (repo , "status" ); err == nil {
447
462
notification .NotifyMigrateRepository (ctx .User , ctxUser , repo )
448
463
return
449
464
}
@@ -456,13 +471,16 @@ func Migrate(ctx *context.APIContext, form auth.MigrateRepoForm) {
456
471
}
457
472
}()
458
473
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 ))
474
+ if _ , err = migrations .MigrateRepository (ctx .User , ctxUser .Name , opts ); err != nil {
475
+ handleMigrateError (ctx , ctxUser , remoteAddr , err )
463
476
return
464
477
}
465
478
479
+ log .Trace ("Repository migrated: %s/%s" , ctxUser .Name , form .RepoName )
480
+ ctx .JSON (201 , repo .APIFormat (models .AccessModeAdmin ))
481
+ }
482
+
483
+ func handleMigrateError (ctx * context.APIContext , repoOwner * models.User , remoteAddr string , err error ) {
466
484
switch {
467
485
case models .IsErrRepoAlreadyExist (err ):
468
486
ctx .Error (409 , "" , "The repository with the same name already exists." )
@@ -471,7 +489,7 @@ func Migrate(ctx *context.APIContext, form auth.MigrateRepoForm) {
471
489
case migrations .IsTwoFactorAuthError (err ):
472
490
ctx .Error (422 , "" , "Remote visit required two factors authentication." )
473
491
case models .IsErrReachLimitOfRepo (err ):
474
- ctx .Error (422 , "" , fmt .Sprintf ("You have already reached your limit of %d repositories." , ctxUser .MaxCreationLimit ()))
492
+ ctx .Error (422 , "" , fmt .Sprintf ("You have already reached your limit of %d repositories." , repoOwner .MaxCreationLimit ()))
475
493
case models .IsErrNameReserved (err ):
476
494
ctx .Error (422 , "" , fmt .Sprintf ("The username '%s' is reserved." , err .(models.ErrNameReserved ).Name ))
477
495
case models .IsErrNamePatternNotAllowed (err ):
0 commit comments