You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

repo.go 2.1 kB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package repo
  5. import (
  6. "github.com/gogits/gogs/models"
  7. "github.com/gogits/gogs/modules/auth"
  8. "github.com/gogits/gogs/modules/middleware"
  9. )
  10. func Create(ctx *middleware.Context, form auth.CreateRepoForm) {
  11. ctx.Data["Title"] = "Create repository"
  12. if ctx.Req.Method == "GET" {
  13. ctx.Data["LanguageIgns"] = models.LanguageIgns
  14. ctx.Data["Licenses"] = models.Licenses
  15. ctx.Render.HTML(200, "repo/create", ctx.Data)
  16. return
  17. }
  18. if ctx.HasError() {
  19. ctx.Render.HTML(200, "repo/create", ctx.Data)
  20. return
  21. }
  22. // TODO: access check
  23. user, err := models.GetUserById(form.UserId)
  24. if err != nil {
  25. if err.Error() == models.ErrUserNotExist.Error() {
  26. ctx.RenderWithErr("User does not exist", "repo/create", &form)
  27. return
  28. }
  29. }
  30. if err == nil {
  31. if _, err = models.CreateRepository(user,
  32. form.RepoName, form.Description, form.Language, form.License,
  33. form.Visibility == "private", form.InitReadme == "on"); err == nil {
  34. ctx.Render.Redirect("/"+user.Name+"/"+form.RepoName, 302)
  35. return
  36. }
  37. }
  38. if err.Error() == models.ErrRepoAlreadyExist.Error() {
  39. ctx.RenderWithErr("Repository name has already been used", "repo/create", &form)
  40. return
  41. }
  42. ctx.Handle(200, "repo.Create", err)
  43. }
  44. func Delete(ctx *middleware.Context, form auth.DeleteRepoForm) {
  45. ctx.Data["Title"] = "Delete repository"
  46. if ctx.Req.Method == "GET" {
  47. ctx.Render.HTML(200, "repo/delete", ctx.Data)
  48. return
  49. }
  50. if err := models.DeleteRepository(form.UserId, form.RepoId, form.UserName); err != nil {
  51. ctx.Handle(200, "repo.Delete", err)
  52. return
  53. }
  54. ctx.Render.Redirect("/", 302)
  55. }
  56. func List(ctx *middleware.Context) {
  57. if ctx.User != nil {
  58. ctx.Render.Redirect("/")
  59. return
  60. }
  61. ctx.Data["Title"] = "Repositories"
  62. repos, err := models.GetRepositories(ctx.User)
  63. if err != nil {
  64. ctx.Handle(200, "repo.List", err)
  65. return
  66. }
  67. ctx.Data["Repos"] = repos
  68. ctx.Render.HTML(200, "repo/list", ctx.Data)
  69. }