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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  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. "github.com/Unknwon/com"
  13. "github.com/go-macaron/binding"
  14. macaron "gopkg.in/macaron.v1"
  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. Private bool
  94. EnablePrune bool
  95. // Advanced settings
  96. EnableWiki bool
  97. EnableExternalWiki bool
  98. ExternalWikiURL string
  99. EnableIssues bool
  100. EnableExternalTracker bool
  101. ExternalTrackerURL string
  102. TrackerURLFormat string
  103. TrackerIssueStyle string
  104. EnablePulls bool
  105. PullsIgnoreWhitespace bool
  106. PullsAllowMerge bool
  107. PullsAllowRebase bool
  108. PullsAllowRebaseMerge bool
  109. PullsAllowSquash bool
  110. EnableTimetracker bool
  111. AllowOnlyContributorsToTrackTime bool
  112. EnableIssueDependencies bool
  113. IsArchived bool
  114. // Admin settings
  115. EnableHealthCheck bool
  116. EnableCloseIssuesViaCommitInAnyBranch bool
  117. }
  118. // Validate validates the fields
  119. func (f *RepoSettingForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  120. return validate(errs, ctx.Data, f, ctx.Locale)
  121. }
  122. // __________ .__
  123. // \______ \____________ ____ ____ | |__
  124. // | | _/\_ __ \__ \ / \_/ ___\| | \
  125. // | | \ | | \// __ \| | \ \___| Y \
  126. // |______ / |__| (____ /___| /\___ >___| /
  127. // \/ \/ \/ \/ \/
  128. // ProtectBranchForm form for changing protected branch settings
  129. type ProtectBranchForm struct {
  130. Protected bool
  131. EnableWhitelist bool
  132. WhitelistUsers string
  133. WhitelistTeams string
  134. EnableMergeWhitelist bool
  135. MergeWhitelistUsers string
  136. MergeWhitelistTeams string
  137. RequiredApprovals int64
  138. ApprovalsWhitelistUsers string
  139. ApprovalsWhitelistTeams string
  140. }
  141. // Validate validates the fields
  142. func (f *ProtectBranchForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  143. return validate(errs, ctx.Data, f, ctx.Locale)
  144. }
  145. // __ __ ___. .__ .__ __
  146. // / \ / \ ____\_ |__ | |__ | |__ ____ | | __
  147. // \ \/\/ // __ \| __ \| | \| | \ / _ \| |/ /
  148. // \ /\ ___/| \_\ \ Y \ Y ( <_> ) <
  149. // \__/\ / \___ >___ /___| /___| /\____/|__|_ \
  150. // \/ \/ \/ \/ \/ \/
  151. // WebhookForm form for changing web hook
  152. type WebhookForm struct {
  153. Events string
  154. Create bool
  155. Delete bool
  156. Fork bool
  157. Issues bool
  158. IssueComment bool
  159. Release bool
  160. Push bool
  161. PullRequest bool
  162. Repository bool
  163. Active bool
  164. }
  165. // PushOnly if the hook will be triggered when push
  166. func (f WebhookForm) PushOnly() bool {
  167. return f.Events == "push_only"
  168. }
  169. // SendEverything if the hook will be triggered any event
  170. func (f WebhookForm) SendEverything() bool {
  171. return f.Events == "send_everything"
  172. }
  173. // ChooseEvents if the hook will be triggered choose events
  174. func (f WebhookForm) ChooseEvents() bool {
  175. return f.Events == "choose_events"
  176. }
  177. // NewWebhookForm form for creating web hook
  178. type NewWebhookForm struct {
  179. PayloadURL string `binding:"Required;ValidUrl"`
  180. HTTPMethod string `binding:"Required;In(POST,GET)"`
  181. ContentType int `binding:"Required"`
  182. Secret string
  183. WebhookForm
  184. }
  185. // Validate validates the fields
  186. func (f *NewWebhookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  187. return validate(errs, ctx.Data, f, ctx.Locale)
  188. }
  189. // NewGogshookForm form for creating gogs hook
  190. type NewGogshookForm struct {
  191. PayloadURL string `binding:"Required;ValidUrl"`
  192. ContentType int `binding:"Required"`
  193. Secret string
  194. WebhookForm
  195. }
  196. // Validate validates the fields
  197. func (f *NewGogshookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  198. return validate(errs, ctx.Data, f, ctx.Locale)
  199. }
  200. // NewSlackHookForm form for creating slack hook
  201. type NewSlackHookForm struct {
  202. PayloadURL string `binding:"Required;ValidUrl"`
  203. Channel string `binding:"Required"`
  204. Username string
  205. IconURL string
  206. Color string
  207. WebhookForm
  208. }
  209. // Validate validates the fields
  210. func (f *NewSlackHookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  211. return validate(errs, ctx.Data, f, ctx.Locale)
  212. }
  213. // HasInvalidChannel validates the channel name is in the right format
  214. func (f NewSlackHookForm) HasInvalidChannel() bool {
  215. return !utils.IsValidSlackChannel(f.Channel)
  216. }
  217. // NewDiscordHookForm form for creating discord hook
  218. type NewDiscordHookForm struct {
  219. PayloadURL string `binding:"Required;ValidUrl"`
  220. Username string
  221. IconURL string
  222. WebhookForm
  223. }
  224. // Validate validates the fields
  225. func (f *NewDiscordHookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  226. return validate(errs, ctx.Data, f, ctx.Locale)
  227. }
  228. // NewDingtalkHookForm form for creating dingtalk hook
  229. type NewDingtalkHookForm struct {
  230. PayloadURL string `binding:"Required;ValidUrl"`
  231. WebhookForm
  232. }
  233. // Validate validates the fields
  234. func (f *NewDingtalkHookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  235. return validate(errs, ctx.Data, f, ctx.Locale)
  236. }
  237. // NewTelegramHookForm form for creating telegram hook
  238. type NewTelegramHookForm struct {
  239. BotToken string `binding:"Required"`
  240. ChatID string `binding:"Required"`
  241. WebhookForm
  242. }
  243. // Validate validates the fields
  244. func (f *NewTelegramHookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  245. return validate(errs, ctx.Data, f, ctx.Locale)
  246. }
  247. // NewMSTeamsHookForm form for creating MS Teams hook
  248. type NewMSTeamsHookForm struct {
  249. PayloadURL string `binding:"Required;ValidUrl"`
  250. WebhookForm
  251. }
  252. // Validate validates the fields
  253. func (f *NewMSTeamsHookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  254. return validate(errs, ctx.Data, f, ctx.Locale)
  255. }
  256. // .___
  257. // | | ______ ________ __ ____
  258. // | |/ ___// ___/ | \_/ __ \
  259. // | |\___ \ \___ \| | /\ ___/
  260. // |___/____ >____ >____/ \___ >
  261. // \/ \/ \/
  262. // CreateIssueForm form for creating issue
  263. type CreateIssueForm struct {
  264. Title string `binding:"Required;MaxSize(255)"`
  265. LabelIDs string `form:"label_ids"`
  266. AssigneeIDs string `form:"assignee_ids"`
  267. Ref string `form:"ref"`
  268. MilestoneID int64
  269. AssigneeID int64
  270. Content string
  271. Files []string
  272. }
  273. // Validate validates the fields
  274. func (f *CreateIssueForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  275. return validate(errs, ctx.Data, f, ctx.Locale)
  276. }
  277. // CreateCommentForm form for creating comment
  278. type CreateCommentForm struct {
  279. Content string
  280. Status string `binding:"OmitEmpty;In(reopen,close)"`
  281. Files []string
  282. }
  283. // Validate validates the fields
  284. func (f *CreateCommentForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  285. return validate(errs, ctx.Data, f, ctx.Locale)
  286. }
  287. // ReactionForm form for adding and removing reaction
  288. type ReactionForm struct {
  289. Content string `binding:"Required;In(+1,-1,laugh,confused,heart,hooray)"`
  290. }
  291. // Validate validates the fields
  292. func (f *ReactionForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  293. return validate(errs, ctx.Data, f, ctx.Locale)
  294. }
  295. // IssueLockForm form for locking an issue
  296. type IssueLockForm struct {
  297. Reason string `binding:"Required"`
  298. }
  299. // Validate validates the fields
  300. func (i *IssueLockForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  301. return validate(errs, ctx.Data, i, ctx.Locale)
  302. }
  303. // HasValidReason checks to make sure that the reason submitted in
  304. // the form matches any of the values in the config
  305. func (i IssueLockForm) HasValidReason() bool {
  306. if strings.TrimSpace(i.Reason) == "" {
  307. return true
  308. }
  309. for _, v := range setting.Repository.Issue.LockReasons {
  310. if v == i.Reason {
  311. return true
  312. }
  313. }
  314. return false
  315. }
  316. // _____ .__.__ __
  317. // / \ |__| | ____ _______/ |_ ____ ____ ____
  318. // / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \
  319. // / Y \ | |_\ ___/ \___ \ | | ( <_> ) | \ ___/
  320. // \____|__ /__|____/\___ >____ > |__| \____/|___| /\___ >
  321. // \/ \/ \/ \/ \/
  322. // CreateMilestoneForm form for creating milestone
  323. type CreateMilestoneForm struct {
  324. Title string `binding:"Required;MaxSize(50)"`
  325. Content string
  326. Deadline string
  327. }
  328. // Validate validates the fields
  329. func (f *CreateMilestoneForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  330. return validate(errs, ctx.Data, f, ctx.Locale)
  331. }
  332. // .____ ___. .__
  333. // | | _____ \_ |__ ____ | |
  334. // | | \__ \ | __ \_/ __ \| |
  335. // | |___ / __ \| \_\ \ ___/| |__
  336. // |_______ (____ /___ /\___ >____/
  337. // \/ \/ \/ \/
  338. // CreateLabelForm form for creating label
  339. type CreateLabelForm struct {
  340. ID int64
  341. Title string `binding:"Required;MaxSize(50)" locale:"repo.issues.label_title"`
  342. Description string `binding:"MaxSize(200)" locale:"repo.issues.label_description"`
  343. Color string `binding:"Required;Size(7)" locale:"repo.issues.label_color"`
  344. }
  345. // Validate validates the fields
  346. func (f *CreateLabelForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  347. return validate(errs, ctx.Data, f, ctx.Locale)
  348. }
  349. // InitializeLabelsForm form for initializing labels
  350. type InitializeLabelsForm struct {
  351. TemplateName string `binding:"Required"`
  352. }
  353. // Validate validates the fields
  354. func (f *InitializeLabelsForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  355. return validate(errs, ctx.Data, f, ctx.Locale)
  356. }
  357. // __________ .__ .__ __________ __
  358. // \______ \__ __| | | | \______ \ ____ ________ __ ____ _______/ |_
  359. // | ___/ | \ | | | | _// __ \/ ____/ | \_/ __ \ / ___/\ __\
  360. // | | | | / |_| |__ | | \ ___< <_| | | /\ ___/ \___ \ | |
  361. // |____| |____/|____/____/ |____|_ /\___ >__ |____/ \___ >____ > |__|
  362. // \/ \/ |__| \/ \/
  363. // MergePullRequestForm form for merging Pull Request
  364. // swagger:model MergePullRequestOption
  365. type MergePullRequestForm struct {
  366. // required: true
  367. // enum: merge,rebase,rebase-merge,squash
  368. Do string `binding:"Required;In(merge,rebase,rebase-merge,squash)"`
  369. MergeTitleField string
  370. MergeMessageField string
  371. }
  372. // Validate validates the fields
  373. func (f *MergePullRequestForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  374. return validate(errs, ctx.Data, f, ctx.Locale)
  375. }
  376. // CodeCommentForm form for adding code comments for PRs
  377. type CodeCommentForm struct {
  378. Content string `binding:"Required"`
  379. Side string `binding:"Required;In(previous,proposed)"`
  380. Line int64
  381. TreePath string `form:"path" binding:"Required"`
  382. IsReview bool `form:"is_review"`
  383. Reply int64 `form:"reply"`
  384. }
  385. // Validate validates the fields
  386. func (f *CodeCommentForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  387. return validate(errs, ctx.Data, f, ctx.Locale)
  388. }
  389. // SubmitReviewForm for submitting a finished code review
  390. type SubmitReviewForm struct {
  391. Content string
  392. Type string `binding:"Required;In(approve,comment,reject)"`
  393. }
  394. // Validate validates the fields
  395. func (f *SubmitReviewForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  396. return validate(errs, ctx.Data, f, ctx.Locale)
  397. }
  398. // ReviewType will return the corresponding reviewtype for type
  399. func (f SubmitReviewForm) ReviewType() models.ReviewType {
  400. switch f.Type {
  401. case "approve":
  402. return models.ReviewTypeApprove
  403. case "comment":
  404. return models.ReviewTypeComment
  405. case "reject":
  406. return models.ReviewTypeReject
  407. default:
  408. return models.ReviewTypeUnknown
  409. }
  410. }
  411. // HasEmptyContent checks if the content of the review form is empty.
  412. func (f SubmitReviewForm) HasEmptyContent() bool {
  413. reviewType := f.ReviewType()
  414. return (reviewType == models.ReviewTypeComment || reviewType == models.ReviewTypeReject) &&
  415. len(strings.TrimSpace(f.Content)) == 0
  416. }
  417. // __________ .__
  418. // \______ \ ____ | | ____ _____ ______ ____
  419. // | _// __ \| | _/ __ \\__ \ / ___// __ \
  420. // | | \ ___/| |_\ ___/ / __ \_\___ \\ ___/
  421. // |____|_ /\___ >____/\___ >____ /____ >\___ >
  422. // \/ \/ \/ \/ \/ \/
  423. // NewReleaseForm form for creating release
  424. type NewReleaseForm struct {
  425. TagName string `binding:"Required;GitRefName"`
  426. Target string `form:"tag_target" binding:"Required"`
  427. Title string `binding:"Required"`
  428. Content string
  429. Draft string
  430. Prerelease bool
  431. Files []string
  432. }
  433. // Validate validates the fields
  434. func (f *NewReleaseForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  435. return validate(errs, ctx.Data, f, ctx.Locale)
  436. }
  437. // EditReleaseForm form for changing release
  438. type EditReleaseForm struct {
  439. Title string `form:"title" binding:"Required"`
  440. Content string `form:"content"`
  441. Draft string `form:"draft"`
  442. Prerelease bool `form:"prerelease"`
  443. Files []string
  444. }
  445. // Validate validates the fields
  446. func (f *EditReleaseForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  447. return validate(errs, ctx.Data, f, ctx.Locale)
  448. }
  449. // __ __.__ __ .__
  450. // / \ / \__| | _|__|
  451. // \ \/\/ / | |/ / |
  452. // \ /| | <| |
  453. // \__/\ / |__|__|_ \__|
  454. // \/ \/
  455. // NewWikiForm form for creating wiki
  456. type NewWikiForm struct {
  457. Title string `binding:"Required"`
  458. Content string `binding:"Required"`
  459. Message string
  460. }
  461. // Validate validates the fields
  462. // FIXME: use code generation to generate this method.
  463. func (f *NewWikiForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  464. return validate(errs, ctx.Data, f, ctx.Locale)
  465. }
  466. // ___________ .___.__ __
  467. // \_ _____/ __| _/|__|/ |_
  468. // | __)_ / __ | | \ __\
  469. // | \/ /_/ | | || |
  470. // /_______ /\____ | |__||__|
  471. // \/ \/
  472. // EditRepoFileForm form for changing repository file
  473. type EditRepoFileForm struct {
  474. TreePath string `binding:"Required;MaxSize(500)"`
  475. Content string `binding:"Required"`
  476. CommitSummary string `binding:"MaxSize(100)"`
  477. CommitMessage string
  478. CommitChoice string `binding:"Required;MaxSize(50)"`
  479. NewBranchName string `binding:"GitRefName;MaxSize(100)"`
  480. LastCommit string
  481. }
  482. // Validate validates the fields
  483. func (f *EditRepoFileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  484. return validate(errs, ctx.Data, f, ctx.Locale)
  485. }
  486. // EditPreviewDiffForm form for changing preview diff
  487. type EditPreviewDiffForm struct {
  488. Content string
  489. }
  490. // Validate validates the fields
  491. func (f *EditPreviewDiffForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  492. return validate(errs, ctx.Data, f, ctx.Locale)
  493. }
  494. // ____ ___ .__ .___
  495. // | | \______ | | _________ __| _/
  496. // | | /\____ \| | / _ \__ \ / __ |
  497. // | | / | |_> > |_( <_> ) __ \_/ /_/ |
  498. // |______/ | __/|____/\____(____ /\____ |
  499. // |__| \/ \/
  500. //
  501. // UploadRepoFileForm form for uploading repository file
  502. type UploadRepoFileForm struct {
  503. TreePath string `binding:"MaxSize(500)"`
  504. CommitSummary string `binding:"MaxSize(100)"`
  505. CommitMessage string
  506. CommitChoice string `binding:"Required;MaxSize(50)"`
  507. NewBranchName string `binding:"GitRefName;MaxSize(100)"`
  508. Files []string
  509. }
  510. // Validate validates the fields
  511. func (f *UploadRepoFileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  512. return validate(errs, ctx.Data, f, ctx.Locale)
  513. }
  514. // RemoveUploadFileForm form for removing uploaded file
  515. type RemoveUploadFileForm struct {
  516. File string `binding:"Required;MaxSize(50)"`
  517. }
  518. // Validate validates the fields
  519. func (f *RemoveUploadFileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  520. return validate(errs, ctx.Data, f, ctx.Locale)
  521. }
  522. // ________ .__ __
  523. // \______ \ ____ | | _____/ |_ ____
  524. // | | \_/ __ \| | _/ __ \ __\/ __ \
  525. // | ` \ ___/| |_\ ___/| | \ ___/
  526. // /_______ /\___ >____/\___ >__| \___ >
  527. // \/ \/ \/ \/
  528. // DeleteRepoFileForm form for deleting repository file
  529. type DeleteRepoFileForm struct {
  530. CommitSummary string `binding:"MaxSize(100)"`
  531. CommitMessage string
  532. CommitChoice string `binding:"Required;MaxSize(50)"`
  533. NewBranchName string `binding:"GitRefName;MaxSize(100)"`
  534. LastCommit string
  535. }
  536. // Validate validates the fields
  537. func (f *DeleteRepoFileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  538. return validate(errs, ctx.Data, f, ctx.Locale)
  539. }
  540. // ___________.__ ___________ __
  541. // \__ ___/|__| _____ ____ \__ ___/___________ ____ | | __ ___________
  542. // | | | |/ \_/ __ \ | | \_ __ \__ \ _/ ___\| |/ // __ \_ __ \
  543. // | | | | Y Y \ ___/ | | | | \// __ \\ \___| <\ ___/| | \/
  544. // |____| |__|__|_| /\___ > |____| |__| (____ /\___ >__|_ \\___ >__|
  545. // \/ \/ \/ \/ \/ \/
  546. // AddTimeManuallyForm form that adds spent time manually.
  547. type AddTimeManuallyForm struct {
  548. Hours int `binding:"Range(0,1000)"`
  549. Minutes int `binding:"Range(0,1000)"`
  550. }
  551. // Validate validates the fields
  552. func (f *AddTimeManuallyForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  553. return validate(errs, ctx.Data, f, ctx.Locale)
  554. }
  555. // SaveTopicForm form for save topics for repository
  556. type SaveTopicForm struct {
  557. Topics []string `binding:"topics;Required;"`
  558. }
  559. // DeadlineForm hold the validation rules for deadlines
  560. type DeadlineForm struct {
  561. DateString string `form:"date" binding:"Required;Size(10)"`
  562. }
  563. // Validate validates the fields
  564. func (f *DeadlineForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  565. return validate(errs, ctx.Data, f, ctx.Locale)
  566. }