Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

repo.go 8.1KB

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