func createRepo(ctx *middleware.Context, owner *models.User, opt api.CreateRepoOption) { repo, err := models.CreateRepository(owner, models.CreateRepoOptions{ Name: opt.Name, Description: opt.Description, Gitignores: opt.Gitignores, License: opt.License, Readme: opt.Readme, IsPrivate: opt.Private, AutoInit: opt.AutoInit, }) if err != nil { if models.IsErrRepoAlreadyExist(err) || models.IsErrNameReserved(err) || models.IsErrNamePatternNotAllowed(err) { ctx.JSON(422, &base.ApiJsonErr{err.Error(), base.DOC_URL}) } else { log.Error(4, "CreateRepository: %v", err) if repo != nil { if err = models.DeleteRepository(ctx.User.Id, repo.ID); err != nil { log.Error(4, "DeleteRepository: %v", err) } } ctx.Error(500) } return } ctx.JSON(201, ToApiRepository(owner, repo, api.Permission{true, true, true})) }
func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) { ctx.Data["Title"] = ctx.Tr("new_repo") ctx.Data["Gitignores"] = models.Gitignores ctx.Data["Licenses"] = models.Licenses ctx.Data["Readmes"] = models.Readmes ctxUser := checkContextUser(ctx, form.Uid) if ctx.Written() { return } ctx.Data["ContextUser"] = ctxUser if ctx.HasError() { ctx.HTML(200, CREATE) return } repo, err := models.CreateRepository(ctxUser, models.CreateRepoOptions{ Name: form.RepoName, Description: form.Description, Gitignores: form.Gitignores, License: form.License, Readme: form.Readme, IsPrivate: form.Private, AutoInit: form.AutoInit, }) if err == nil { log.Trace("Repository created: %s/%s", ctxUser.Name, repo.Name) ctx.Redirect(setting.AppSubUrl + "/" + ctxUser.Name + "/" + repo.Name) return } if repo != nil { if errDelete := models.DeleteRepository(ctxUser.Id, repo.ID); errDelete != nil { log.Error(4, "DeleteRepository: %v", errDelete) } } handleCreateError(ctx, err, "CreatePost", CREATE, &form) }