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 22KB

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