You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

repo_form.go 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Copyright 2017 The Gitea Authors. All rights reserved.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. package auth
  6. import (
  7. "net/url"
  8. "strings"
  9. "code.gitea.io/gitea/models"
  10. "code.gitea.io/gitea/modules/setting"
  11. "code.gitea.io/gitea/routers/utils"
  12. "gitea.com/macaron/binding"
  13. "gitea.com/macaron/macaron"
  14. "github.com/unknwon/com"
  15. )
  16. // _______________________________________ _________.______________________ _______________.___.
  17. // \______ \_ _____/\______ \_____ \ / _____/| \__ ___/\_____ \\______ \__ | |
  18. // | _/| __)_ | ___// | \ \_____ \ | | | | / | \| _// | |
  19. // | | \| \ | | / | \/ \| | | | / | \ | \\____ |
  20. // |____|_ /_______ / |____| \_______ /_______ /|___| |____| \_______ /____|_ // ______|
  21. // \/ \/ \/ \/ \/ \/ \/
  22. // CreateRepoForm form for creating repository
  23. type CreateRepoForm struct {
  24. UID int64 `binding:"Required"`
  25. RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"`
  26. Private bool
  27. Description string `binding:"MaxSize(255)"`
  28. AutoInit bool
  29. Gitignores string
  30. License string
  31. Readme string
  32. }
  33. // Validate validates the fields
  34. func (f *CreateRepoForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  35. return validate(errs, ctx.Data, f, ctx.Locale)
  36. }
  37. // MigrateRepoForm form for migrating repository
  38. type MigrateRepoForm struct {
  39. // required: true
  40. CloneAddr string `json:"clone_addr" binding:"Required"`
  41. AuthUsername string `json:"auth_username"`
  42. AuthPassword string `json:"auth_password"`
  43. // required: true
  44. UID int64 `json:"uid" binding:"Required"`
  45. // required: true
  46. RepoName string `json:"repo_name" binding:"Required;AlphaDashDot;MaxSize(100)"`
  47. Mirror bool `json:"mirror"`
  48. Private bool `json:"private"`
  49. Description string `json:"description" binding:"MaxSize(255)"`
  50. Wiki bool `json:"wiki"`
  51. Milestones bool `json:"milestones"`
  52. Labels bool `json:"labels"`
  53. Issues bool `json:"issues"`
  54. PullRequests bool `json:"pull_requests"`
  55. Releases bool `json:"releases"`
  56. }
  57. // Validate validates the fields
  58. func (f *MigrateRepoForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  59. return validate(errs, ctx.Data, f, ctx.Locale)
  60. }
  61. // ParseRemoteAddr checks if given remote address is valid,
  62. // and returns composed URL with needed username and password.
  63. // It also checks if given user has permission when remote address
  64. // is actually a local path.
  65. func (f MigrateRepoForm) ParseRemoteAddr(user *models.User) (string, error) {
  66. remoteAddr := strings.TrimSpace(f.CloneAddr)
  67. // Remote address can be HTTP/HTTPS/Git URL or local path.
  68. if strings.HasPrefix(remoteAddr, "http://") ||
  69. strings.HasPrefix(remoteAddr, "https://") ||
  70. strings.HasPrefix(remoteAddr, "git://") {
  71. u, err := url.Parse(remoteAddr)
  72. if err != nil {
  73. return "", models.ErrInvalidCloneAddr{IsURLError: true}
  74. }
  75. if len(f.AuthUsername)+len(f.AuthPassword) > 0 {
  76. u.User = url.UserPassword(f.AuthUsername, f.AuthPassword)
  77. }
  78. remoteAddr = u.String()
  79. } else if !user.CanImportLocal() {
  80. return "", models.ErrInvalidCloneAddr{IsPermissionDenied: true}
  81. } else if !com.IsDir(remoteAddr) {
  82. return "", models.ErrInvalidCloneAddr{IsInvalidPath: true}
  83. }
  84. return remoteAddr, nil
  85. }
  86. // RepoSettingForm form for changing repository settings
  87. type RepoSettingForm struct {
  88. RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"`
  89. Description string `binding:"MaxSize(255)"`
  90. Website string `binding:"ValidUrl;MaxSize(255)"`
  91. Interval string
  92. MirrorAddress string
  93. MirrorUsername string
  94. MirrorPassword string
  95. Private bool
  96. EnablePrune bool
  97. // Advanced settings
  98. EnableWiki bool
  99. EnableExternalWiki bool
  100. ExternalWikiURL string
  101. EnableIssues bool
  102. EnableExternalTracker bool
  103. ExternalTrackerURL string
  104. TrackerURLFormat string
  105. TrackerIssueStyle string
  106. EnablePulls bool
  107. PullsIgnoreWhitespace bool
  108. PullsAllowMerge bool
  109. PullsAllowRebase bool
  110. PullsAllowRebaseMerge bool
  111. PullsAllowSquash bool
  112. EnableTimetracker bool
  113. AllowOnlyContributorsToTrackTime bool
  114. EnableIssueDependencies bool
  115. IsArchived bool
  116. // Admin settings
  117. EnableHealthCheck bool
  118. EnableCloseIssuesViaCommitInAnyBranch bool
  119. }
  120. // Validate validates the fields
  121. func (f *RepoSettingForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  122. return validate(errs, ctx.Data, f, ctx.Locale)
  123. }
  124. // __________ .__
  125. // \______ \____________ ____ ____ | |__
  126. // | | _/\_ __ \__ \ / \_/ ___\| | \
  127. // | | \ | | \// __ \| | \ \___| Y \
  128. // |______ / |__| (____ /___| /\___ >___| /
  129. // \/ \/ \/ \/ \/
  130. // ProtectBranchForm form for changing protected branch settings
  131. type ProtectBranchForm struct {
  132. Protected bool
  133. EnableWhitelist bool
  134. WhitelistUsers string
  135. WhitelistTeams string
  136. EnableMergeWhitelist bool
  137. MergeWhitelistUsers string
  138. MergeWhitelistTeams string
  139. RequiredApprovals int64
  140. ApprovalsWhitelistUsers string
  141. ApprovalsWhitelistTeams string
  142. }
  143. // Validate validates the fields
  144. func (f *ProtectBranchForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  145. return validate(errs, ctx.Data, f, ctx.Locale)
  146. }
  147. // __ __ ___. .__ .__ __
  148. // / \ / \ ____\_ |__ | |__ | |__ ____ | | __
  149. // \ \/\/ // __ \| __ \| | \| | \ / _ \| |/ /
  150. // \ /\ ___/| \_\ \ Y \ Y ( <_> ) <
  151. // \__/\ / \___ >___ /___| /___| /\____/|__|_ \
  152. // \/ \/ \/ \/ \/ \/
  153. // WebhookForm form for changing web hook
  154. type WebhookForm struct {
  155. Events string
  156. Create bool
  157. Delete bool
  158. Fork bool
  159. Issues bool
  160. IssueComment bool
  161. Release bool
  162. Push bool
  163. PullRequest bool
  164. Repository bool
  165. Active bool
  166. }
  167. // PushOnly if the hook will be triggered when push
  168. func (f WebhookForm) PushOnly() bool {
  169. return f.Events == "push_only"
  170. }
  171. // SendEverything if the hook will be triggered any event
  172. func (f WebhookForm) SendEverything() bool {
  173. return f.Events == "send_everything"
  174. }
  175. // ChooseEvents if the hook will be triggered choose events
  176. func (f WebhookForm) ChooseEvents() bool {
  177. return f.Events == "choose_events"
  178. }
  179. // NewWebhookForm form for creating web hook
  180. type NewWebhookForm struct {
  181. PayloadURL string `binding:"Required;ValidUrl"`
  182. HTTPMethod string `binding:"Required;In(POST,GET)"`
  183. ContentType int `binding:"Required"`
  184. Secret string
  185. WebhookForm
  186. }
  187. // Validate validates the fields
  188. func (f *NewWebhookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  189. return validate(errs, ctx.Data, f, ctx.Locale)
  190. }
  191. // NewGogshookForm form for creating gogs hook
  192. type NewGogshookForm struct {
  193. PayloadURL string `binding:"Required;ValidUrl"`
  194. ContentType int `binding:"Required"`
  195. Secret string
  196. WebhookForm
  197. }
  198. // Validate validates the fields
  199. func (f *NewGogshookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  200. return validate(errs, ctx.Data, f, ctx.Locale)
  201. }
  202. // NewSlackHookForm form for creating slack hook
  203. type NewSlackHookForm struct {
  204. PayloadURL string `binding:"Required;ValidUrl"`
  205. Channel string `binding:"Required"`
  206. Username string
  207. IconURL string
  208. Color string
  209. WebhookForm
  210. }
  211. // Validate validates the fields
  212. func (f *NewSlackHookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  213. return validate(errs, ctx.Data, f, ctx.Locale)
  214. }
  215. // HasInvalidChannel validates the channel name is in the right format
  216. func (f NewSlackHookForm) HasInvalidChannel() bool {
  217. return !utils.IsValidSlackChannel(f.Channel)
  218. }
  219. // NewDiscordHookForm form for creating discord hook
  220. type NewDiscordHookForm struct {
  221. PayloadURL string `binding:"Required;ValidUrl"`
  222. Username string
  223. IconURL string
  224. WebhookForm
  225. }
  226. // Validate validates the fields
  227. func (f *NewDiscordHookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  228. return validate(errs, ctx.Data, f, ctx.Locale)
  229. }
  230. // NewDingtalkHookForm form for creating dingtalk hook
  231. type NewDingtalkHookForm struct {
  232. PayloadURL string `binding:"Required;ValidUrl"`
  233. WebhookForm
  234. }
  235. // Validate validates the fields
  236. func (f *NewDingtalkHookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  237. return validate(errs, ctx.Data, f, ctx.Locale)
  238. }
  239. // NewTelegramHookForm form for creating telegram hook
  240. type NewTelegramHookForm struct {
  241. BotToken string `binding:"Required"`
  242. ChatID string `binding:"Required"`
  243. WebhookForm
  244. }
  245. // Validate validates the fields
  246. func (f *NewTelegramHookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  247. return validate(errs, ctx.Data, f, ctx.Locale)
  248. }
  249. // NewMSTeamsHookForm form for creating MS Teams hook
  250. type NewMSTeamsHookForm struct {
  251. PayloadURL string `binding:"Required;ValidUrl"`
  252. WebhookForm
  253. }
  254. // Validate validates the fields
  255. func (f *NewMSTeamsHookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  256. return validate(errs, ctx.Data, f, ctx.Locale)
  257. }
  258. // .___
  259. // | | ______ ________ __ ____
  260. // | |/ ___// ___/ | \_/ __ \
  261. // | |\___ \ \___ \| | /\ ___/
  262. // |___/____ >____ >____/ \___ >
  263. // \/ \/ \/
  264. // CreateIssueForm form for creating issue
  265. type CreateIssueForm struct {
  266. Title string `binding:"Required;MaxSize(255)"`
  267. LabelIDs string `form:"label_ids"`
  268. AssigneeIDs string `form:"assignee_ids"`
  269. Ref string `form:"ref"`
  270. MilestoneID int64
  271. AssigneeID int64
  272. Content string
  273. Files []string
  274. }
  275. // Validate validates the fields
  276. func (f *CreateIssueForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  277. return validate(errs, ctx.Data, f, ctx.Locale)
  278. }
  279. // CreateCommentForm form for creating comment
  280. type CreateCommentForm struct {
  281. Content string
  282. Status string `binding:"OmitEmpty;In(reopen,close)"`
  283. Files []string
  284. }
  285. // Validate validates the fields
  286. func (f *CreateCommentForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  287. return validate(errs, ctx.Data, f, ctx.Locale)
  288. }
  289. // ReactionForm form for adding and removing reaction
  290. type ReactionForm struct {
  291. Content string `binding:"Required;In(+1,-1,laugh,confused,heart,hooray)"`
  292. }
  293. // Validate validates the fields
  294. func (f *ReactionForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  295. return validate(errs, ctx.Data, f, ctx.Locale)
  296. }
  297. // IssueLockForm form for locking an issue
  298. type IssueLockForm struct {
  299. Reason string `binding:"Required"`
  300. }
  301. // Validate validates the fields
  302. func (i *IssueLockForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  303. return validate(errs, ctx.Data, i, ctx.Locale)
  304. }
  305. // HasValidReason checks to make sure that the reason submitted in
  306. // the form matches any of the values in the config
  307. func (i IssueLockForm) HasValidReason() bool {
  308. if strings.TrimSpace(i.Reason) == "" {
  309. return true
  310. }
  311. for _, v := range setting.Repository.Issue.LockReasons {
  312. if v == i.Reason {
  313. return true
  314. }
  315. }
  316. return false
  317. }
  318. // _____ .__.__ __
  319. // / \ |__| | ____ _______/ |_ ____ ____ ____
  320. // / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \
  321. // / Y \ | |_\ ___/ \___ \ | | ( <_> ) | \ ___/
  322. // \____|__ /__|____/\___ >____ > |__| \____/|___| /\___ >
  323. // \/ \/ \/ \/ \/
  324. // CreateMilestoneForm form for creating milestone
  325. type CreateMilestoneForm struct {
  326. Title string `binding:"Required;MaxSize(50)"`
  327. Content string
  328. Deadline string
  329. }
  330. // Validate validates the fields
  331. func (f *CreateMilestoneForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  332. return validate(errs, ctx.Data, f, ctx.Locale)
  333. }
  334. // .____ ___. .__
  335. // | | _____ \_ |__ ____ | |
  336. // | | \__ \ | __ \_/ __ \| |
  337. // | |___ / __ \| \_\ \ ___/| |__
  338. // |_______ (____ /___ /\___ >____/
  339. // \/ \/ \/ \/
  340. // CreateLabelForm form for creating label
  341. type CreateLabelForm struct {
  342. ID int64
  343. Title string `binding:"Required;MaxSize(50)" locale:"repo.issues.label_title"`
  344. Description string `binding:"MaxSize(200)" locale:"repo.issues.label_description"`
  345. Color string `binding:"Required;Size(7)" locale:"repo.issues.label_color"`
  346. }
  347. // Validate validates the fields
  348. func (f *CreateLabelForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  349. return validate(errs, ctx.Data, f, ctx.Locale)
  350. }
  351. // InitializeLabelsForm form for initializing labels
  352. type InitializeLabelsForm struct {
  353. TemplateName string `binding:"Required"`
  354. }
  355. // Validate validates the fields
  356. func (f *InitializeLabelsForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  357. return validate(errs, ctx.Data, f, ctx.Locale)
  358. }
  359. // __________ .__ .__ __________ __
  360. // \______ \__ __| | | | \______ \ ____ ________ __ ____ _______/ |_
  361. // | ___/ | \ | | | | _// __ \/ ____/ | \_/ __ \ / ___/\ __\
  362. // | | | | / |_| |__ | | \ ___< <_| | | /\ ___/ \___ \ | |
  363. // |____| |____/|____/____/ |____|_ /\___ >__ |____/ \___ >____ > |__|
  364. // \/ \/ |__| \/ \/
  365. // MergePullRequestForm form for merging Pull Request
  366. // swagger:model MergePullRequestOption
  367. type MergePullRequestForm struct {
  368. // required: true
  369. // enum: merge,rebase,rebase-merge,squash
  370. Do string `binding:"Required;In(merge,rebase,rebase-merge,squash)"`
  371. MergeTitleField string
  372. MergeMessageField string
  373. }
  374. // Validate validates the fields
  375. func (f *MergePullRequestForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  376. return validate(errs, ctx.Data, f, ctx.Locale)
  377. }
  378. // CodeCommentForm form for adding code comments for PRs
  379. type CodeCommentForm struct {
  380. Content string `binding:"Required"`
  381. Side string `binding:"Required;In(previous,proposed)"`
  382. Line int64
  383. TreePath string `form:"path" binding:"Required"`
  384. IsReview bool `form:"is_review"`
  385. Reply int64 `form:"reply"`
  386. }
  387. // Validate validates the fields
  388. func (f *CodeCommentForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  389. return validate(errs, ctx.Data, f, ctx.Locale)
  390. }
  391. // SubmitReviewForm for submitting a finished code review
  392. type SubmitReviewForm struct {
  393. Content string
  394. Type string `binding:"Required;In(approve,comment,reject)"`
  395. }
  396. // Validate validates the fields
  397. func (f *SubmitReviewForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  398. return validate(errs, ctx.Data, f, ctx.Locale)
  399. }
  400. // ReviewType will return the corresponding reviewtype for type
  401. func (f SubmitReviewForm) ReviewType() models.ReviewType {
  402. switch f.Type {
  403. case "approve":
  404. return models.ReviewTypeApprove
  405. case "comment":
  406. return models.ReviewTypeComment
  407. case "reject":
  408. return models.ReviewTypeReject
  409. default:
  410. return models.ReviewTypeUnknown
  411. }
  412. }
  413. // HasEmptyContent checks if the content of the review form is empty.
  414. func (f SubmitReviewForm) HasEmptyContent() bool {
  415. reviewType := f.ReviewType()
  416. return (reviewType == models.ReviewTypeComment || reviewType == models.ReviewTypeReject) &&
  417. len(strings.TrimSpace(f.Content)) == 0
  418. }
  419. // __________ .__
  420. // \______ \ ____ | | ____ _____ ______ ____
  421. // | _// __ \| | _/ __ \\__ \ / ___// __ \
  422. // | | \ ___/| |_\ ___/ / __ \_\___ \\ ___/
  423. // |____|_ /\___ >____/\___ >____ /____ >\___ >
  424. // \/ \/ \/ \/ \/ \/
  425. // NewReleaseForm form for creating release
  426. type NewReleaseForm struct {
  427. TagName string `binding:"Required;GitRefName"`
  428. Target string `form:"tag_target" binding:"Required"`
  429. Title string `binding:"Required"`
  430. Content string
  431. Draft string
  432. Prerelease bool
  433. Files []string
  434. }
  435. // Validate validates the fields
  436. func (f *NewReleaseForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  437. return validate(errs, ctx.Data, f, ctx.Locale)
  438. }
  439. // EditReleaseForm form for changing release
  440. type EditReleaseForm struct {
  441. Title string `form:"title" binding:"Required"`
  442. Content string `form:"content"`
  443. Draft string `form:"draft"`
  444. Prerelease bool `form:"prerelease"`
  445. Files []string
  446. }
  447. // Validate validates the fields
  448. func (f *EditReleaseForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  449. return validate(errs, ctx.Data, f, ctx.Locale)
  450. }
  451. // __ __.__ __ .__
  452. // / \ / \__| | _|__|
  453. // \ \/\/ / | |/ / |
  454. // \ /| | <| |
  455. // \__/\ / |__|__|_ \__|
  456. // \/ \/
  457. // NewWikiForm form for creating wiki
  458. type NewWikiForm struct {
  459. Title string `binding:"Required"`
  460. Content string `binding:"Required"`
  461. Message string
  462. }
  463. // Validate validates the fields
  464. // FIXME: use code generation to generate this method.
  465. func (f *NewWikiForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  466. return validate(errs, ctx.Data, f, ctx.Locale)
  467. }
  468. // ___________ .___.__ __
  469. // \_ _____/ __| _/|__|/ |_
  470. // | __)_ / __ | | \ __\
  471. // | \/ /_/ | | || |
  472. // /_______ /\____ | |__||__|
  473. // \/ \/
  474. // EditRepoFileForm form for changing repository file
  475. type EditRepoFileForm struct {
  476. TreePath string `binding:"Required;MaxSize(500)"`
  477. Content string `binding:"Required"`
  478. CommitSummary string `binding:"MaxSize(100)"`
  479. CommitMessage string
  480. CommitChoice string `binding:"Required;MaxSize(50)"`
  481. NewBranchName string `binding:"GitRefName;MaxSize(100)"`
  482. LastCommit string
  483. }
  484. // Validate validates the fields
  485. func (f *EditRepoFileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  486. return validate(errs, ctx.Data, f, ctx.Locale)
  487. }
  488. // EditPreviewDiffForm form for changing preview diff
  489. type EditPreviewDiffForm struct {
  490. Content string
  491. }
  492. // Validate validates the fields
  493. func (f *EditPreviewDiffForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  494. return validate(errs, ctx.Data, f, ctx.Locale)
  495. }
  496. // ____ ___ .__ .___
  497. // | | \______ | | _________ __| _/
  498. // | | /\____ \| | / _ \__ \ / __ |
  499. // | | / | |_> > |_( <_> ) __ \_/ /_/ |
  500. // |______/ | __/|____/\____(____ /\____ |
  501. // |__| \/ \/
  502. //
  503. // UploadRepoFileForm form for uploading repository file
  504. type UploadRepoFileForm struct {
  505. TreePath string `binding:"MaxSize(500)"`
  506. CommitSummary string `binding:"MaxSize(100)"`
  507. CommitMessage string
  508. CommitChoice string `binding:"Required;MaxSize(50)"`
  509. NewBranchName string `binding:"GitRefName;MaxSize(100)"`
  510. Files []string
  511. }
  512. // Validate validates the fields
  513. func (f *UploadRepoFileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  514. return validate(errs, ctx.Data, f, ctx.Locale)
  515. }
  516. // RemoveUploadFileForm form for removing uploaded file
  517. type RemoveUploadFileForm struct {
  518. File string `binding:"Required;MaxSize(50)"`
  519. }
  520. // Validate validates the fields
  521. func (f *RemoveUploadFileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  522. return validate(errs, ctx.Data, f, ctx.Locale)
  523. }
  524. // ________ .__ __
  525. // \______ \ ____ | | _____/ |_ ____
  526. // | | \_/ __ \| | _/ __ \ __\/ __ \
  527. // | ` \ ___/| |_\ ___/| | \ ___/
  528. // /_______ /\___ >____/\___ >__| \___ >
  529. // \/ \/ \/ \/
  530. // DeleteRepoFileForm form for deleting repository file
  531. type DeleteRepoFileForm struct {
  532. CommitSummary string `binding:"MaxSize(100)"`
  533. CommitMessage string
  534. CommitChoice string `binding:"Required;MaxSize(50)"`
  535. NewBranchName string `binding:"GitRefName;MaxSize(100)"`
  536. LastCommit string
  537. }
  538. // Validate validates the fields
  539. func (f *DeleteRepoFileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  540. return validate(errs, ctx.Data, f, ctx.Locale)
  541. }
  542. // ___________.__ ___________ __
  543. // \__ ___/|__| _____ ____ \__ ___/___________ ____ | | __ ___________
  544. // | | | |/ \_/ __ \ | | \_ __ \__ \ _/ ___\| |/ // __ \_ __ \
  545. // | | | | Y Y \ ___/ | | | | \// __ \\ \___| <\ ___/| | \/
  546. // |____| |__|__|_| /\___ > |____| |__| (____ /\___ >__|_ \\___ >__|
  547. // \/ \/ \/ \/ \/ \/
  548. // AddTimeManuallyForm form that adds spent time manually.
  549. type AddTimeManuallyForm struct {
  550. Hours int `binding:"Range(0,1000)"`
  551. Minutes int `binding:"Range(0,1000)"`
  552. }
  553. // Validate validates the fields
  554. func (f *AddTimeManuallyForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  555. return validate(errs, ctx.Data, f, ctx.Locale)
  556. }
  557. // SaveTopicForm form for save topics for repository
  558. type SaveTopicForm struct {
  559. Topics []string `binding:"topics;Required;"`
  560. }
  561. // DeadlineForm hold the validation rules for deadlines
  562. type DeadlineForm struct {
  563. DateString string `form:"date" binding:"Required;Size(10)"`
  564. }
  565. // Validate validates the fields
  566. func (f *DeadlineForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  567. return validate(errs, ctx.Data, f, ctx.Locale)
  568. }