|
|
@ -6,6 +6,8 @@ |
|
|
|
package repo |
|
|
|
package repo |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
|
|
|
|
"bytes" |
|
|
|
|
|
|
|
"errors" |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
"net/http" |
|
|
|
"net/http" |
|
|
|
"net/url" |
|
|
|
"net/url" |
|
|
@ -425,15 +427,54 @@ func Migrate(ctx *context.APIContext, form auth.MigrateRepoForm) { |
|
|
|
opts.Releases = false |
|
|
|
opts.Releases = false |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
repo, err := migrations.MigrateRepository(ctx.User, ctxUser.Name, opts) |
|
|
|
repo, err := models.CreateRepository(ctx.User, ctxUser, models.CreateRepoOptions{ |
|
|
|
if err == nil { |
|
|
|
Name: opts.RepoName, |
|
|
|
notification.NotifyMigrateRepository(ctx.User, ctxUser, repo) |
|
|
|
Description: opts.Description, |
|
|
|
|
|
|
|
OriginalURL: opts.CloneAddr, |
|
|
|
|
|
|
|
IsPrivate: opts.Private, |
|
|
|
|
|
|
|
IsMirror: opts.Mirror, |
|
|
|
|
|
|
|
Status: models.RepositoryBeingMigrated, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
handleMigrateError(ctx, ctxUser, remoteAddr, err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
opts.MigrateToRepoID = repo.ID |
|
|
|
|
|
|
|
|
|
|
|
log.Trace("Repository migrated: %s/%s", ctxUser.Name, form.RepoName) |
|
|
|
defer func() { |
|
|
|
ctx.JSON(201, repo.APIFormat(models.AccessModeAdmin)) |
|
|
|
if e := recover(); e != nil { |
|
|
|
|
|
|
|
var buf bytes.Buffer |
|
|
|
|
|
|
|
fmt.Fprintf(&buf, "Handler crashed with error: %v", log.Stack(2)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
err = errors.New(buf.String()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err == nil { |
|
|
|
|
|
|
|
repo.Status = models.RepositoryReady |
|
|
|
|
|
|
|
if err := models.UpdateRepositoryCols(repo, "status"); err == nil { |
|
|
|
|
|
|
|
notification.NotifyMigrateRepository(ctx.User, ctxUser, repo) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if repo != nil { |
|
|
|
|
|
|
|
if errDelete := models.DeleteRepository(ctx.User, ctxUser.ID, repo.ID); errDelete != nil { |
|
|
|
|
|
|
|
log.Error("DeleteRepository: %v", errDelete) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if _, err = migrations.MigrateRepository(ctx.User, ctxUser.Name, opts); err != nil { |
|
|
|
|
|
|
|
handleMigrateError(ctx, ctxUser, remoteAddr, err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.Trace("Repository migrated: %s/%s", ctxUser.Name, form.RepoName) |
|
|
|
|
|
|
|
ctx.JSON(201, repo.APIFormat(models.AccessModeAdmin)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func handleMigrateError(ctx *context.APIContext, repoOwner *models.User, remoteAddr string, err error) { |
|
|
|
switch { |
|
|
|
switch { |
|
|
|
case models.IsErrRepoAlreadyExist(err): |
|
|
|
case models.IsErrRepoAlreadyExist(err): |
|
|
|
ctx.Error(409, "", "The repository with the same name already exists.") |
|
|
|
ctx.Error(409, "", "The repository with the same name already exists.") |
|
|
@ -442,7 +483,7 @@ func Migrate(ctx *context.APIContext, form auth.MigrateRepoForm) { |
|
|
|
case migrations.IsTwoFactorAuthError(err): |
|
|
|
case migrations.IsTwoFactorAuthError(err): |
|
|
|
ctx.Error(422, "", "Remote visit required two factors authentication.") |
|
|
|
ctx.Error(422, "", "Remote visit required two factors authentication.") |
|
|
|
case models.IsErrReachLimitOfRepo(err): |
|
|
|
case models.IsErrReachLimitOfRepo(err): |
|
|
|
ctx.Error(422, "", fmt.Sprintf("You have already reached your limit of %d repositories.", ctxUser.MaxCreationLimit())) |
|
|
|
ctx.Error(422, "", fmt.Sprintf("You have already reached your limit of %d repositories.", repoOwner.MaxCreationLimit())) |
|
|
|
case models.IsErrNameReserved(err): |
|
|
|
case models.IsErrNameReserved(err): |
|
|
|
ctx.Error(422, "", fmt.Sprintf("The username '%s' is reserved.", err.(models.ErrNameReserved).Name)) |
|
|
|
ctx.Error(422, "", fmt.Sprintf("The username '%s' is reserved.", err.(models.ErrNameReserved).Name)) |
|
|
|
case models.IsErrNamePatternNotAllowed(err): |
|
|
|
case models.IsErrNamePatternNotAllowed(err): |
|
|
|