repo.go 2.3 KB

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