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

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