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.7 kB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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/martini-contrib/render"
  7. "github.com/martini-contrib/sessions"
  8. "net/http"
  9. "github.com/gogits/gogs/models"
  10. "github.com/gogits/gogs/modules/auth"
  11. "github.com/gogits/gogs/modules/base"
  12. "github.com/gogits/gogs/modules/log"
  13. )
  14. func Create(form auth.CreateRepoForm, req *http.Request, r render.Render, data base.TmplData, session sessions.Session) {
  15. data["Title"] = "Create repository"
  16. if req.Method == "GET" {
  17. data["LanguageIgns"] = models.LanguageIgns
  18. data["Licenses"] = models.Licenses
  19. r.HTML(200, "repo/create", data)
  20. return
  21. }
  22. if hasErr, ok := data["HasError"]; ok && hasErr.(bool) {
  23. r.HTML(200, "repo/create", data)
  24. return
  25. }
  26. // TODO: access check
  27. user, err := models.GetUserById(form.UserId)
  28. if err != nil {
  29. if err.Error() == models.ErrUserNotExist.Error() {
  30. data["HasError"] = true
  31. data["ErrorMsg"] = "User does not exist"
  32. auth.AssignForm(form, data)
  33. r.HTML(200, "repo/create", data)
  34. return
  35. }
  36. }
  37. if err == nil {
  38. if _, err = models.CreateRepository(user,
  39. form.RepoName, form.Description, form.Language, form.License,
  40. form.Visibility == "private", form.InitReadme == "true"); err == nil {
  41. if err == nil {
  42. data["RepoName"] = user.Name + "/" + form.RepoName
  43. r.HTML(200, "repo/created", data)
  44. return
  45. }
  46. }
  47. }
  48. if err.Error() == models.ErrRepoAlreadyExist.Error() {
  49. data["HasError"] = true
  50. data["ErrorMsg"] = "Repository name has already been used"
  51. auth.AssignForm(form, data)
  52. r.HTML(200, "repo/create", data)
  53. return
  54. }
  55. data["ErrorMsg"] = err
  56. log.Error("repo.Create: %v", err)
  57. r.HTML(200, "base/error", data)
  58. }
  59. func Delete(form auth.DeleteRepoForm, req *http.Request, r render.Render, data base.TmplData, session sessions.Session) {
  60. data["Title"] = "Delete repository"
  61. if req.Method == "GET" {
  62. r.HTML(200, "repo/delete", data)
  63. return
  64. }
  65. if err := models.DeleteRepository(form.UserId, form.RepoId, form.UserName); err != nil {
  66. data["ErrorMsg"] = err
  67. log.Error("repo.Delete: %v", err)
  68. r.HTML(200, "base/error", data)
  69. return
  70. }
  71. r.Redirect("/", 200)
  72. }
  73. func List(req *http.Request, r render.Render, data base.TmplData, session sessions.Session) {
  74. u := auth.SignedInUser(session)
  75. if u != nil {
  76. r.Redirect("/")
  77. return
  78. }
  79. data["Title"] = "Repositories"
  80. repos, err := models.GetRepositories(u)
  81. if err != nil {
  82. data["ErrorMsg"] = err
  83. log.Error("repo.List: %v", err)
  84. r.HTML(200, "base/error", data)
  85. return
  86. }
  87. data["Repos"] = repos
  88. r.HTML(200, "repo/list", data)
  89. }