repo.go 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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/middleware/binding"
  11. )
  12. // __________ .__ __
  13. // \______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__.
  14. // | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | |
  15. // | | \ ___/| |_> > <_> )___ \| || | ( <_> ) | \/\___ |
  16. // |____|_ /\___ > __/ \____/____ >__||__| \____/|__| / ____|
  17. // \/ \/|__| \/ \/
  18. type CreateRepoForm struct {
  19. RepoName string `form:"repo" binding:"Required;AlphaDash;MaxSize(100)"`
  20. Private bool `form:"private"`
  21. Description string `form:"desc" binding:"MaxSize(100)"`
  22. Language string `form:"language"`
  23. License string `form:"license"`
  24. InitReadme bool `form:"initReadme"`
  25. }
  26. func (f *CreateRepoForm) Name(field string) string {
  27. names := map[string]string{
  28. "RepoName": "Repository name",
  29. "Description": "Description",
  30. }
  31. return names[field]
  32. }
  33. func (f *CreateRepoForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) {
  34. data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
  35. validate(errors, data, f)
  36. }
  37. type MigrateRepoForm struct {
  38. Url string `form:"url" binding:"Url"`
  39. AuthUserName string `form:"auth_username"`
  40. AuthPasswd string `form:"auth_password"`
  41. RepoName string `form:"repo" binding:"Required;AlphaDash;MaxSize(100)"`
  42. Mirror bool `form:"mirror"`
  43. Private bool `form:"private"`
  44. Description string `form:"desc" binding:"MaxSize(100)"`
  45. }
  46. func (f *MigrateRepoForm) Name(field string) string {
  47. names := map[string]string{
  48. "Url": "Migration URL",
  49. "RepoName": "Repository name",
  50. "Description": "Description",
  51. }
  52. return names[field]
  53. }
  54. func (f *MigrateRepoForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) {
  55. data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
  56. validate(errors, data, f)
  57. }
  58. type RepoSettingForm struct {
  59. RepoName string `form:"name" binding:"Required;AlphaDash;MaxSize(100)"`
  60. Description string `form:"desc" binding:"MaxSize(100)"`
  61. Website string `form:"site" binding:"Url;MaxSize(100)"`
  62. Branch string `form:"branch"`
  63. Interval int `form:"interval"`
  64. Private bool `form:"private"`
  65. GoGet bool `form:"goget"`
  66. }
  67. func (f *RepoSettingForm) Name(field string) string {
  68. names := map[string]string{
  69. "RepoName": "Repository name",
  70. "Description": "Description",
  71. "Website": "Website address",
  72. }
  73. return names[field]
  74. }
  75. func (f *RepoSettingForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) {
  76. data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
  77. validate(errors, data, f)
  78. }
  79. // __ __ ___. .__ .__ __
  80. // / \ / \ ____\_ |__ | |__ | |__ ____ | | __
  81. // \ \/\/ // __ \| __ \| | \| | \ / _ \| |/ /
  82. // \ /\ ___/| \_\ \ Y \ Y ( <_> ) <
  83. // \__/\ / \___ >___ /___| /___| /\____/|__|_ \
  84. // \/ \/ \/ \/ \/ \/
  85. type NewWebhookForm struct {
  86. Url string `form:"url" binding:"Required;Url"`
  87. ContentType string `form:"content_type" binding:"Required"`
  88. Secret string `form:"secret""`
  89. PushOnly bool `form:"push_only"`
  90. Active bool `form:"active"`
  91. }
  92. func (f *NewWebhookForm) Name(field string) string {
  93. names := map[string]string{
  94. "Url": "Payload URL",
  95. "ContentType": "Content type",
  96. }
  97. return names[field]
  98. }
  99. func (f *NewWebhookForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) {
  100. data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
  101. validate(errors, data, f)
  102. }
  103. // .___
  104. // | | ______ ________ __ ____
  105. // | |/ ___// ___/ | \_/ __ \
  106. // | |\___ \ \___ \| | /\ ___/
  107. // |___/____ >____ >____/ \___ >
  108. // \/ \/ \/
  109. type CreateIssueForm struct {
  110. IssueName string `form:"title" binding:"Required;MaxSize(50)"`
  111. MilestoneId int64 `form:"milestoneid"`
  112. AssigneeId int64 `form:"assigneeid"`
  113. Labels string `form:"labels"`
  114. Content string `form:"content"`
  115. }
  116. func (f *CreateIssueForm) Name(field string) string {
  117. names := map[string]string{
  118. "IssueName": "Issue name",
  119. }
  120. return names[field]
  121. }
  122. func (f *CreateIssueForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) {
  123. data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
  124. validate(errors, data, f)
  125. }
  126. // _____ .__.__ __
  127. // / \ |__| | ____ _______/ |_ ____ ____ ____
  128. // / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \
  129. // / Y \ | |_\ ___/ \___ \ | | ( <_> ) | \ ___/
  130. // \____|__ /__|____/\___ >____ > |__| \____/|___| /\___ >
  131. // \/ \/ \/ \/ \/
  132. type CreateMilestoneForm struct {
  133. Title string `form:"title" binding:"Required;MaxSize(50)"`
  134. Content string `form:"content"`
  135. Deadline string `form:"due_date"`
  136. }
  137. func (f *CreateMilestoneForm) Name(field string) string {
  138. names := map[string]string{
  139. "Title": "Milestone name",
  140. }
  141. return names[field]
  142. }
  143. func (f *CreateMilestoneForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) {
  144. data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
  145. validate(errors, data, f)
  146. }
  147. // .____ ___. .__
  148. // | | _____ \_ |__ ____ | |
  149. // | | \__ \ | __ \_/ __ \| |
  150. // | |___ / __ \| \_\ \ ___/| |__
  151. // |_______ (____ /___ /\___ >____/
  152. // \/ \/ \/ \/
  153. type CreateLabelForm struct {
  154. Title string `form:"title" binding:"Required;MaxSize(50)"`
  155. Color string `form:"color" binding:"Required;Size(7)"`
  156. }
  157. func (f *CreateLabelForm) Name(field string) string {
  158. names := map[string]string{
  159. "Title": "Label name",
  160. "Color": "Label color",
  161. }
  162. return names[field]
  163. }
  164. func (f *CreateLabelForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) {
  165. data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
  166. validate(errors, data, f)
  167. }
  168. // __________ .__
  169. // \______ \ ____ | | ____ _____ ______ ____
  170. // | _// __ \| | _/ __ \\__ \ / ___// __ \
  171. // | | \ ___/| |_\ ___/ / __ \_\___ \\ ___/
  172. // |____|_ /\___ >____/\___ >____ /____ >\___ >
  173. // \/ \/ \/ \/ \/ \/
  174. type NewReleaseForm struct {
  175. TagName string `form:"tag_name" binding:"Required"`
  176. Target string `form:"tag_target" binding:"Required"`
  177. Title string `form:"title" binding:"Required"`
  178. Content string `form:"content" binding:"Required"`
  179. Draft string `form:"draft"`
  180. Prerelease bool `form:"prerelease"`
  181. }
  182. func (f *NewReleaseForm) Name(field string) string {
  183. names := map[string]string{
  184. "TagName": "Tag name",
  185. "Target": "Target",
  186. "Title": "Release title",
  187. "Content": "Release content",
  188. }
  189. return names[field]
  190. }
  191. func (f *NewReleaseForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) {
  192. data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
  193. validate(errors, data, f)
  194. }
  195. type EditReleaseForm struct {
  196. Target string `form:"tag_target" binding:"Required"`
  197. Title string `form:"title" binding:"Required"`
  198. Content string `form:"content" binding:"Required"`
  199. Draft string `form:"draft"`
  200. Prerelease bool `form:"prerelease"`
  201. }
  202. func (f *EditReleaseForm) Name(field string) string {
  203. names := map[string]string{
  204. "Target": "Target",
  205. "Title": "Release title",
  206. "Content": "Release content",
  207. }
  208. return names[field]
  209. }
  210. func (f *EditReleaseForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) {
  211. data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
  212. validate(errors, data, f)
  213. }