diff options
Diffstat (limited to 'routers/api/v1/repo/transfer.go')
-rw-r--r-- | routers/api/v1/repo/transfer.go | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/routers/api/v1/repo/transfer.go b/routers/api/v1/repo/transfer.go index 656ace032e..2e052aa4ff 100644 --- a/routers/api/v1/repo/transfer.go +++ b/routers/api/v1/repo/transfer.go @@ -96,17 +96,27 @@ func Transfer(ctx *context.APIContext) { } } - if err = repo_service.TransferOwnership(ctx.User, newOwner, ctx.Repo.Repository, teams); err != nil { + if err := repo_service.StartRepositoryTransfer(ctx.User, newOwner, ctx.Repo.Repository, teams); err != nil { + if models.IsErrRepoTransferInProgress(err) { + ctx.Error(http.StatusConflict, "CreatePendingRepositoryTransfer", err) + return + } + + if models.IsErrRepoAlreadyExist(err) { + ctx.Error(http.StatusUnprocessableEntity, "CreatePendingRepositoryTransfer", err) + return + } + ctx.InternalServerError(err) return } - newRepo, err := models.GetRepositoryByName(newOwner.ID, ctx.Repo.Repository.Name) - if err != nil { - ctx.InternalServerError(err) + if ctx.Repo.Repository.Status == models.RepositoryPendingTransfer { + log.Trace("Repository transfer initiated: %s -> %s", ctx.Repo.Repository.FullName(), newOwner.Name) + ctx.JSON(http.StatusCreated, convert.ToRepo(ctx.Repo.Repository, models.AccessModeAdmin)) return } log.Trace("Repository transferred: %s -> %s", ctx.Repo.Repository.FullName(), newOwner.Name) - ctx.JSON(http.StatusAccepted, convert.ToRepo(newRepo, models.AccessModeAdmin)) + ctx.JSON(http.StatusAccepted, convert.ToRepo(ctx.Repo.Repository, models.AccessModeAdmin)) } |