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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  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. // NewFeishuHookForm form for creating feishu hook
  276. type NewFeishuHookForm struct {
  277. PayloadURL string `binding:"Required;ValidUrl"`
  278. WebhookForm
  279. }
  280. // Validate validates the fields
  281. func (f *NewFeishuHookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  282. return validate(errs, ctx.Data, f, ctx.Locale)
  283. }
  284. // .___
  285. // | | ______ ________ __ ____
  286. // | |/ ___// ___/ | \_/ __ \
  287. // | |\___ \ \___ \| | /\ ___/
  288. // |___/____ >____ >____/ \___ >
  289. // \/ \/ \/
  290. // CreateIssueForm form for creating issue
  291. type CreateIssueForm struct {
  292. Title string `binding:"Required;MaxSize(255)"`
  293. LabelIDs string `form:"label_ids"`
  294. AssigneeIDs string `form:"assignee_ids"`
  295. Ref string `form:"ref"`
  296. MilestoneID int64
  297. AssigneeID int64
  298. Content string
  299. Files []string
  300. }
  301. // Validate validates the fields
  302. func (f *CreateIssueForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  303. return validate(errs, ctx.Data, f, ctx.Locale)
  304. }
  305. // CreateCommentForm form for creating comment
  306. type CreateCommentForm struct {
  307. Content string
  308. Status string `binding:"OmitEmpty;In(reopen,close)"`
  309. Files []string
  310. }
  311. // Validate validates the fields
  312. func (f *CreateCommentForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  313. return validate(errs, ctx.Data, f, ctx.Locale)
  314. }
  315. // ReactionForm form for adding and removing reaction
  316. type ReactionForm struct {
  317. Content string `binding:"Required"`
  318. }
  319. // Validate validates the fields
  320. func (f *ReactionForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  321. return validate(errs, ctx.Data, f, ctx.Locale)
  322. }
  323. // IssueLockForm form for locking an issue
  324. type IssueLockForm struct {
  325. Reason string `binding:"Required"`
  326. }
  327. // Validate validates the fields
  328. func (i *IssueLockForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  329. return validate(errs, ctx.Data, i, ctx.Locale)
  330. }
  331. // HasValidReason checks to make sure that the reason submitted in
  332. // the form matches any of the values in the config
  333. func (i IssueLockForm) HasValidReason() bool {
  334. if strings.TrimSpace(i.Reason) == "" {
  335. return true
  336. }
  337. for _, v := range setting.Repository.Issue.LockReasons {
  338. if v == i.Reason {
  339. return true
  340. }
  341. }
  342. return false
  343. }
  344. // _____ .__.__ __
  345. // / \ |__| | ____ _______/ |_ ____ ____ ____
  346. // / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \
  347. // / Y \ | |_\ ___/ \___ \ | | ( <_> ) | \ ___/
  348. // \____|__ /__|____/\___ >____ > |__| \____/|___| /\___ >
  349. // \/ \/ \/ \/ \/
  350. // CreateMilestoneForm form for creating milestone
  351. type CreateMilestoneForm struct {
  352. Title string `binding:"Required;MaxSize(50)"`
  353. Content string
  354. Deadline string
  355. }
  356. // Validate validates the fields
  357. func (f *CreateMilestoneForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  358. return validate(errs, ctx.Data, f, ctx.Locale)
  359. }
  360. // .____ ___. .__
  361. // | | _____ \_ |__ ____ | |
  362. // | | \__ \ | __ \_/ __ \| |
  363. // | |___ / __ \| \_\ \ ___/| |__
  364. // |_______ (____ /___ /\___ >____/
  365. // \/ \/ \/ \/
  366. // CreateLabelForm form for creating label
  367. type CreateLabelForm struct {
  368. ID int64
  369. Title string `binding:"Required;MaxSize(50)" locale:"repo.issues.label_title"`
  370. Description string `binding:"MaxSize(200)" locale:"repo.issues.label_description"`
  371. Color string `binding:"Required;Size(7)" locale:"repo.issues.label_color"`
  372. }
  373. // Validate validates the fields
  374. func (f *CreateLabelForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  375. return validate(errs, ctx.Data, f, ctx.Locale)
  376. }
  377. // InitializeLabelsForm form for initializing labels
  378. type InitializeLabelsForm struct {
  379. TemplateName string `binding:"Required"`
  380. }
  381. // Validate validates the fields
  382. func (f *InitializeLabelsForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  383. return validate(errs, ctx.Data, f, ctx.Locale)
  384. }
  385. // __________ .__ .__ __________ __
  386. // \______ \__ __| | | | \______ \ ____ ________ __ ____ _______/ |_
  387. // | ___/ | \ | | | | _// __ \/ ____/ | \_/ __ \ / ___/\ __\
  388. // | | | | / |_| |__ | | \ ___< <_| | | /\ ___/ \___ \ | |
  389. // |____| |____/|____/____/ |____|_ /\___ >__ |____/ \___ >____ > |__|
  390. // \/ \/ |__| \/ \/
  391. // MergePullRequestForm form for merging Pull Request
  392. // swagger:model MergePullRequestOption
  393. type MergePullRequestForm struct {
  394. // required: true
  395. // enum: merge,rebase,rebase-merge,squash
  396. Do string `binding:"Required;In(merge,rebase,rebase-merge,squash)"`
  397. MergeTitleField string
  398. MergeMessageField string
  399. ForceMerge *bool `json:"force_merge,omitempty"`
  400. }
  401. // Validate validates the fields
  402. func (f *MergePullRequestForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  403. return validate(errs, ctx.Data, f, ctx.Locale)
  404. }
  405. // CodeCommentForm form for adding code comments for PRs
  406. type CodeCommentForm struct {
  407. Content string `binding:"Required"`
  408. Side string `binding:"Required;In(previous,proposed)"`
  409. Line int64
  410. TreePath string `form:"path" binding:"Required"`
  411. IsReview bool `form:"is_review"`
  412. Reply int64 `form:"reply"`
  413. LatestCommitID string
  414. }
  415. // Validate validates the fields
  416. func (f *CodeCommentForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  417. return validate(errs, ctx.Data, f, ctx.Locale)
  418. }
  419. // SubmitReviewForm for submitting a finished code review
  420. type SubmitReviewForm struct {
  421. Content string
  422. Type string `binding:"Required;In(approve,comment,reject)"`
  423. CommitID string
  424. }
  425. // Validate validates the fields
  426. func (f *SubmitReviewForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  427. return validate(errs, ctx.Data, f, ctx.Locale)
  428. }
  429. // ReviewType will return the corresponding reviewtype for type
  430. func (f SubmitReviewForm) ReviewType() models.ReviewType {
  431. switch f.Type {
  432. case "approve":
  433. return models.ReviewTypeApprove
  434. case "comment":
  435. return models.ReviewTypeComment
  436. case "reject":
  437. return models.ReviewTypeReject
  438. default:
  439. return models.ReviewTypeUnknown
  440. }
  441. }
  442. // HasEmptyContent checks if the content of the review form is empty.
  443. func (f SubmitReviewForm) HasEmptyContent() bool {
  444. reviewType := f.ReviewType()
  445. return (reviewType == models.ReviewTypeComment || reviewType == models.ReviewTypeReject) &&
  446. len(strings.TrimSpace(f.Content)) == 0
  447. }
  448. // __________ .__
  449. // \______ \ ____ | | ____ _____ ______ ____
  450. // | _// __ \| | _/ __ \\__ \ / ___// __ \
  451. // | | \ ___/| |_\ ___/ / __ \_\___ \\ ___/
  452. // |____|_ /\___ >____/\___ >____ /____ >\___ >
  453. // \/ \/ \/ \/ \/ \/
  454. // NewReleaseForm form for creating release
  455. type NewReleaseForm struct {
  456. TagName string `binding:"Required;GitRefName;MaxSize(255)"`
  457. Target string `form:"tag_target" binding:"Required;MaxSize(255)"`
  458. Title string `binding:"Required;MaxSize(255)"`
  459. Content string
  460. Draft string
  461. Prerelease bool
  462. Files []string
  463. }
  464. // Validate validates the fields
  465. func (f *NewReleaseForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  466. return validate(errs, ctx.Data, f, ctx.Locale)
  467. }
  468. // EditReleaseForm form for changing release
  469. type EditReleaseForm struct {
  470. Title string `form:"title" binding:"Required;MaxSize(255)"`
  471. Content string `form:"content"`
  472. Draft string `form:"draft"`
  473. Prerelease bool `form:"prerelease"`
  474. Files []string
  475. }
  476. // Validate validates the fields
  477. func (f *EditReleaseForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  478. return validate(errs, ctx.Data, f, ctx.Locale)
  479. }
  480. // __ __.__ __ .__
  481. // / \ / \__| | _|__|
  482. // \ \/\/ / | |/ / |
  483. // \ /| | <| |
  484. // \__/\ / |__|__|_ \__|
  485. // \/ \/
  486. // NewWikiForm form for creating wiki
  487. type NewWikiForm struct {
  488. Title string `binding:"Required"`
  489. Content string `binding:"Required"`
  490. Message string
  491. }
  492. // Validate validates the fields
  493. // FIXME: use code generation to generate this method.
  494. func (f *NewWikiForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  495. return validate(errs, ctx.Data, f, ctx.Locale)
  496. }
  497. // ___________ .___.__ __
  498. // \_ _____/ __| _/|__|/ |_
  499. // | __)_ / __ | | \ __\
  500. // | \/ /_/ | | || |
  501. // /_______ /\____ | |__||__|
  502. // \/ \/
  503. // EditRepoFileForm form for changing repository file
  504. type EditRepoFileForm struct {
  505. TreePath string `binding:"Required;MaxSize(500)"`
  506. Content string
  507. CommitSummary string `binding:"MaxSize(100)"`
  508. CommitMessage string
  509. CommitChoice string `binding:"Required;MaxSize(50)"`
  510. NewBranchName string `binding:"GitRefName;MaxSize(100)"`
  511. LastCommit string
  512. }
  513. // Validate validates the fields
  514. func (f *EditRepoFileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  515. return validate(errs, ctx.Data, f, ctx.Locale)
  516. }
  517. // EditPreviewDiffForm form for changing preview diff
  518. type EditPreviewDiffForm struct {
  519. Content string
  520. }
  521. // Validate validates the fields
  522. func (f *EditPreviewDiffForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  523. return validate(errs, ctx.Data, f, ctx.Locale)
  524. }
  525. // ____ ___ .__ .___
  526. // | | \______ | | _________ __| _/
  527. // | | /\____ \| | / _ \__ \ / __ |
  528. // | | / | |_> > |_( <_> ) __ \_/ /_/ |
  529. // |______/ | __/|____/\____(____ /\____ |
  530. // |__| \/ \/
  531. //
  532. // UploadRepoFileForm form for uploading repository file
  533. type UploadRepoFileForm struct {
  534. TreePath string `binding:"MaxSize(500)"`
  535. CommitSummary string `binding:"MaxSize(100)"`
  536. CommitMessage string
  537. CommitChoice string `binding:"Required;MaxSize(50)"`
  538. NewBranchName string `binding:"GitRefName;MaxSize(100)"`
  539. Files []string
  540. }
  541. // Validate validates the fields
  542. func (f *UploadRepoFileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  543. return validate(errs, ctx.Data, f, ctx.Locale)
  544. }
  545. // RemoveUploadFileForm form for removing uploaded file
  546. type RemoveUploadFileForm struct {
  547. File string `binding:"Required;MaxSize(50)"`
  548. }
  549. // Validate validates the fields
  550. func (f *RemoveUploadFileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  551. return validate(errs, ctx.Data, f, ctx.Locale)
  552. }
  553. // ________ .__ __
  554. // \______ \ ____ | | _____/ |_ ____
  555. // | | \_/ __ \| | _/ __ \ __\/ __ \
  556. // | ` \ ___/| |_\ ___/| | \ ___/
  557. // /_______ /\___ >____/\___ >__| \___ >
  558. // \/ \/ \/ \/
  559. // DeleteRepoFileForm form for deleting repository file
  560. type DeleteRepoFileForm struct {
  561. CommitSummary string `binding:"MaxSize(100)"`
  562. CommitMessage string
  563. CommitChoice string `binding:"Required;MaxSize(50)"`
  564. NewBranchName string `binding:"GitRefName;MaxSize(100)"`
  565. LastCommit string
  566. }
  567. // Validate validates the fields
  568. func (f *DeleteRepoFileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  569. return validate(errs, ctx.Data, f, ctx.Locale)
  570. }
  571. // ___________.__ ___________ __
  572. // \__ ___/|__| _____ ____ \__ ___/___________ ____ | | __ ___________
  573. // | | | |/ \_/ __ \ | | \_ __ \__ \ _/ ___\| |/ // __ \_ __ \
  574. // | | | | Y Y \ ___/ | | | | \// __ \\ \___| <\ ___/| | \/
  575. // |____| |__|__|_| /\___ > |____| |__| (____ /\___ >__|_ \\___ >__|
  576. // \/ \/ \/ \/ \/ \/
  577. // AddTimeManuallyForm form that adds spent time manually.
  578. type AddTimeManuallyForm struct {
  579. Hours int `binding:"Range(0,1000)"`
  580. Minutes int `binding:"Range(0,1000)"`
  581. }
  582. // Validate validates the fields
  583. func (f *AddTimeManuallyForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  584. return validate(errs, ctx.Data, f, ctx.Locale)
  585. }
  586. // SaveTopicForm form for save topics for repository
  587. type SaveTopicForm struct {
  588. Topics []string `binding:"topics;Required;"`
  589. }
  590. // DeadlineForm hold the validation rules for deadlines
  591. type DeadlineForm struct {
  592. DateString string `form:"date" binding:"Required;Size(10)"`
  593. }
  594. // Validate validates the fields
  595. func (f *DeadlineForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  596. return validate(errs, ctx.Data, f, ctx.Locale)
  597. }