repo_form.go 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. "github.com/Unknwon/macaron"
  7. "github.com/macaron-contrib/binding"
  8. )
  9. // _______________________________________ _________.______________________ _______________.___.
  10. // \______ \_ _____/\______ \_____ \ / _____/| \__ ___/\_____ \\______ \__ | |
  11. // | _/| __)_ | ___// | \ \_____ \ | | | | / | \| _// | |
  12. // | | \| \ | | / | \/ \| | | | / | \ | \\____ |
  13. // |____|_ /_______ / |____| \_______ /_______ /|___| |____| \_______ /____|_ // ______|
  14. // \/ \/ \/ \/ \/ \/ \/
  15. type CreateRepoForm struct {
  16. Uid int64 `binding:"Required"`
  17. RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"`
  18. Private bool
  19. Description string `binding:"MaxSize(255)"`
  20. AutoInit bool
  21. Gitignores string
  22. License string
  23. Readme string
  24. }
  25. func (f *CreateRepoForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  26. return validate(errs, ctx.Data, f, ctx.Locale)
  27. }
  28. type MigrateRepoForm struct {
  29. CloneAddr string `binding:"Required"`
  30. AuthUsername string
  31. AuthPassword string
  32. Mirror bool
  33. Uid int64 `binding:"Required"`
  34. RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"`
  35. Private bool
  36. Description string `binding:"MaxSize(255)"`
  37. }
  38. func (f *MigrateRepoForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  39. return validate(errs, ctx.Data, f, ctx.Locale)
  40. }
  41. type RepoSettingForm struct {
  42. RepoName string `form:"repo_name" binding:"Required;AlphaDashDot;MaxSize(100)"`
  43. Description string `form:"desc" binding:"MaxSize(255)"`
  44. Website string `form:"site" binding:"Url;MaxSize(100)"`
  45. Branch string `form:"branch"`
  46. Interval int `form:"interval"`
  47. Private bool `form:"private"`
  48. }
  49. func (f *RepoSettingForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  50. return validate(errs, ctx.Data, f, ctx.Locale)
  51. }
  52. // __ __ ___. .__ .__ __
  53. // / \ / \ ____\_ |__ | |__ | |__ ____ | | __
  54. // \ \/\/ // __ \| __ \| | \| | \ / _ \| |/ /
  55. // \ /\ ___/| \_\ \ Y \ Y ( <_> ) <
  56. // \__/\ / \___ >___ /___| /___| /\____/|__|_ \
  57. // \/ \/ \/ \/ \/ \/
  58. type WebhookForm struct {
  59. Events string
  60. Create bool
  61. Push bool
  62. Active bool
  63. }
  64. func (f WebhookForm) PushOnly() bool {
  65. return f.Events == "push_only"
  66. }
  67. func (f WebhookForm) SendEverything() bool {
  68. return f.Events == "send_everything"
  69. }
  70. func (f WebhookForm) ChooseEvents() bool {
  71. return f.Events == "choose_events"
  72. }
  73. type NewWebhookForm struct {
  74. PayloadURL string `binding:"Required;Url"`
  75. ContentType int `binding:"Required"`
  76. Secret string
  77. WebhookForm
  78. }
  79. func (f *NewWebhookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  80. return validate(errs, ctx.Data, f, ctx.Locale)
  81. }
  82. type NewSlackHookForm struct {
  83. PayloadURL string `binding:"Required`
  84. Channel string `binding:"Required"`
  85. WebhookForm
  86. }
  87. func (f *NewSlackHookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  88. return validate(errs, ctx.Data, f, ctx.Locale)
  89. }
  90. // .___
  91. // | | ______ ________ __ ____
  92. // | |/ ___// ___/ | \_/ __ \
  93. // | |\___ \ \___ \| | /\ ___/
  94. // |___/____ >____ >____/ \___ >
  95. // \/ \/ \/
  96. type CreateIssueForm struct {
  97. Title string `binding:"Required;MaxSize(255)"`
  98. LabelIDs string `form:"label_ids"`
  99. MilestoneID int64
  100. AssigneeID int64
  101. Content string
  102. Attachments []string
  103. }
  104. func (f *CreateIssueForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  105. return validate(errs, ctx.Data, f, ctx.Locale)
  106. }
  107. type CreateCommentForm struct {
  108. Content string
  109. Status string `binding:"OmitEmpty;In(reopen,close)"`
  110. Attachments []string
  111. }
  112. func (f *CreateCommentForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  113. return validate(errs, ctx.Data, f, ctx.Locale)
  114. }
  115. // _____ .__.__ __
  116. // / \ |__| | ____ _______/ |_ ____ ____ ____
  117. // / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \
  118. // / Y \ | |_\ ___/ \___ \ | | ( <_> ) | \ ___/
  119. // \____|__ /__|____/\___ >____ > |__| \____/|___| /\___ >
  120. // \/ \/ \/ \/ \/
  121. type CreateMilestoneForm struct {
  122. Title string `binding:"Required;MaxSize(50)"`
  123. Content string
  124. Deadline string
  125. }
  126. func (f *CreateMilestoneForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  127. return validate(errs, ctx.Data, f, ctx.Locale)
  128. }
  129. // .____ ___. .__
  130. // | | _____ \_ |__ ____ | |
  131. // | | \__ \ | __ \_/ __ \| |
  132. // | |___ / __ \| \_\ \ ___/| |__
  133. // |_______ (____ /___ /\___ >____/
  134. // \/ \/ \/ \/
  135. type CreateLabelForm struct {
  136. ID int64
  137. Title string `binding:"Required;MaxSize(50)" locale:"repo.issues.label_name"`
  138. Color string `binding:"Required;Size(7)" locale:"repo.issues.label_color"`
  139. }
  140. func (f *CreateLabelForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  141. return validate(errs, ctx.Data, f, ctx.Locale)
  142. }
  143. // __________ .__
  144. // \______ \ ____ | | ____ _____ ______ ____
  145. // | _// __ \| | _/ __ \\__ \ / ___// __ \
  146. // | | \ ___/| |_\ ___/ / __ \_\___ \\ ___/
  147. // |____|_ /\___ >____/\___ >____ /____ >\___ >
  148. // \/ \/ \/ \/ \/ \/
  149. type NewReleaseForm struct {
  150. TagName string `form:"tag_name" binding:"Required"`
  151. Target string `form:"tag_target" binding:"Required"`
  152. Title string `form:"title" binding:"Required"`
  153. Content string `form:"content" binding:"Required"`
  154. Draft string `form:"draft"`
  155. Prerelease bool `form:"prerelease"`
  156. }
  157. func (f *NewReleaseForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  158. return validate(errs, ctx.Data, f, ctx.Locale)
  159. }
  160. type EditReleaseForm struct {
  161. Title string `form:"title" binding:"Required"`
  162. Content string `form:"content" binding:"Required"`
  163. Draft string `form:"draft"`
  164. Prerelease bool `form:"prerelease"`
  165. }
  166. func (f *EditReleaseForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  167. return validate(errs, ctx.Data, f, ctx.Locale)
  168. }