diff options
author | Unknown <joe2010xtmf@163.com> | 2014-04-12 20:35:35 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-04-12 20:35:35 -0400 |
commit | 90f6aa8cd19e489723ddffc40d6507782c29756c (patch) | |
tree | e247229573a4d32ca1d508619951a9868690840f /routers | |
parent | 23bba7633bbd8ae8f9f41404352c327f9e8c9fdc (diff) | |
download | gitea-90f6aa8cd19e489723ddffc40d6507782c29756c.tar.gz gitea-90f6aa8cd19e489723ddffc40d6507782c29756c.zip |
Add repo mirror and import
Diffstat (limited to 'routers')
-rw-r--r-- | routers/repo/repo.go | 50 | ||||
-rw-r--r-- | routers/user/user.go | 14 |
2 files changed, 46 insertions, 18 deletions
diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 3ffbde1a1e..f19ae02ee7 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -40,8 +40,8 @@ func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) { return } - _, err := models.CreateRepository(ctx.User, form.RepoName, form.Description, - form.Language, form.License, form.Private == "on", form.InitReadme == "on") + repo, err := models.CreateRepository(ctx.User, form.RepoName, form.Description, + form.Language, form.License, form.Private, false, form.InitReadme) if err == nil { log.Trace("%s Repository created: %s/%s", ctx.Req.RequestURI, ctx.User.LowerName, form.RepoName) ctx.Redirect("/" + ctx.User.Name + "/" + form.RepoName) @@ -53,38 +53,56 @@ func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) { ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), "repo/create", &form) return } + + if repo != nil { + if errDelete := models.DeleteRepository(ctx.User.Id, repo.Id, ctx.User.Name); errDelete != nil { + log.Error("repo.MigratePost(CreatePost): %v", errDelete) + } + } ctx.Handle(500, "repo.Create", err) } -func Mirror(ctx *middleware.Context) { - ctx.Data["Title"] = "Mirror repository" +func Migrate(ctx *middleware.Context) { + ctx.Data["Title"] = "Migrate repository" ctx.Data["PageIsNewRepo"] = true - ctx.HTML(200, "repo/mirror") + ctx.HTML(200, "repo/migrate") } -func MirrorPost(ctx *middleware.Context, form auth.CreateRepoForm) { - ctx.Data["Title"] = "Mirror repository" +func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) { + ctx.Data["Title"] = "Migrate repository" ctx.Data["PageIsNewRepo"] = true if ctx.HasError() { - ctx.HTML(200, "repo/mirror") + ctx.HTML(200, "repo/migrate") return } - _, err := models.CreateRepository(ctx.User, form.RepoName, form.Description, - "", form.License, form.Private == "on", false) + url := strings.Replace(form.Url, "://", fmt.Sprintf("://%s:%s@", form.AuthUserName, form.AuthPasswd), 1) + repo, err := models.MigrateRepository(ctx.User, form.RepoName, form.Description, form.Private, + form.Mirror, url) if err == nil { - log.Trace("%s Repository created: %s/%s", ctx.Req.RequestURI, ctx.User.LowerName, form.RepoName) + log.Trace("%s Repository migrated: %s/%s", ctx.Req.RequestURI, ctx.User.LowerName, form.RepoName) ctx.Redirect("/" + ctx.User.Name + "/" + form.RepoName) return } else if err == models.ErrRepoAlreadyExist { - ctx.RenderWithErr("Repository name has already been used", "repo/mirror", &form) + ctx.RenderWithErr("Repository name has already been used", "repo/migrate", &form) return } else if err == models.ErrRepoNameIllegal { - ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), "repo/mirror", &form) + ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), "repo/migrate", &form) + return + } + + if repo != nil { + if errDelete := models.DeleteRepository(ctx.User.Id, repo.Id, ctx.User.Name); errDelete != nil { + log.Error("repo.MigratePost(DeleteRepository): %v", errDelete) + } + } + + if strings.Contains(err.Error(), "Authentication failed") { + ctx.RenderWithErr(err.Error(), "repo/migrate", &form) return } - ctx.Handle(500, "repo.Mirror", err) + ctx.Handle(500, "repo.Migrate", err) } func Single(ctx *middleware.Context, params martini.Params) { @@ -425,7 +443,3 @@ func Action(ctx *middleware.Context, params martini.Params) { "ok": true, }) } - -func Import(ctx *middleware.Context, params martini.Params) { - ctx.ResponseWriter.Write([]byte("not done yet")) -} diff --git a/routers/user/user.go b/routers/user/user.go index 8585267a64..e5328173a2 100644 --- a/routers/user/user.go +++ b/routers/user/user.go @@ -74,6 +74,20 @@ func Profile(ctx *middleware.Context, params martini.Params) { ctx.HTML(200, "user/profile") } +func Email2User(ctx *middleware.Context) { + u, err := models.GetUserByEmail(ctx.Query("email")) + if err != nil { + if err == models.ErrUserNotExist { + ctx.Handle(404, "user.Email2User", err) + } else { + ctx.Handle(500, "user.Email2User(GetUserByEmail)", err) + } + return + } + + ctx.Redirect("/user/" + u.Name) +} + func SignIn(ctx *middleware.Context) { ctx.Data["Title"] = "Log In" |