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

repo.go 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 auth
  5. import (
  6. "net/http"
  7. "reflect"
  8. "github.com/go-martini/martini"
  9. "github.com/gogits/binding"
  10. "github.com/gogits/gogs/modules/base"
  11. "github.com/gogits/gogs/modules/log"
  12. )
  13. type CreateRepoForm struct {
  14. RepoName string `form:"repo" binding:"Required;AlphaDash"`
  15. Private bool `form:"private"`
  16. Description string `form:"desc" binding:"MaxSize(100)"`
  17. Language string `form:"language"`
  18. License string `form:"license"`
  19. InitReadme bool `form:"initReadme"`
  20. }
  21. func (f *CreateRepoForm) Name(field string) string {
  22. names := map[string]string{
  23. "RepoName": "Repository name",
  24. "Description": "Description",
  25. }
  26. return names[field]
  27. }
  28. func (f *CreateRepoForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) {
  29. if req.Method == "GET" || errors.Count() == 0 {
  30. return
  31. }
  32. data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
  33. data["HasError"] = true
  34. AssignForm(f, data)
  35. if len(errors.Overall) > 0 {
  36. for _, err := range errors.Overall {
  37. log.Error("CreateRepoForm.Validate: %v", err)
  38. }
  39. return
  40. }
  41. validate(errors, data, f)
  42. }
  43. type MigrateRepoForm struct {
  44. Url string `form:"url" binding:"Url"`
  45. AuthUserName string `form:"auth_username"`
  46. AuthPasswd string `form:"auth_password"`
  47. RepoName string `form:"repo" binding:"Required;AlphaDash"`
  48. Mirror bool `form:"mirror"`
  49. Private bool `form:"private"`
  50. Description string `form:"desc" binding:"MaxSize(100)"`
  51. }
  52. func (f *MigrateRepoForm) Name(field string) string {
  53. names := map[string]string{
  54. "Url": "Migration URL",
  55. "RepoName": "Repository name",
  56. "Description": "Description",
  57. }
  58. return names[field]
  59. }
  60. func (f *MigrateRepoForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) {
  61. if req.Method == "GET" || errors.Count() == 0 {
  62. return
  63. }
  64. data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
  65. data["HasError"] = true
  66. AssignForm(f, data)
  67. if len(errors.Overall) > 0 {
  68. for _, err := range errors.Overall {
  69. log.Error("MigrateRepoForm.Validate: %v", err)
  70. }
  71. return
  72. }
  73. validate(errors, data, f)
  74. }