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

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