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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  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 forms
  6. import (
  7. "net/http"
  8. "net/url"
  9. "strings"
  10. "code.gitea.io/gitea/models"
  11. "code.gitea.io/gitea/modules/context"
  12. "code.gitea.io/gitea/modules/setting"
  13. "code.gitea.io/gitea/modules/structs"
  14. "code.gitea.io/gitea/modules/web/middleware"
  15. "code.gitea.io/gitea/routers/utils"
  16. "gitea.com/go-chi/binding"
  17. )
  18. // _______________________________________ _________.______________________ _______________.___.
  19. // \______ \_ _____/\______ \_____ \ / _____/| \__ ___/\_____ \\______ \__ | |
  20. // | _/| __)_ | ___// | \ \_____ \ | | | | / | \| _// | |
  21. // | | \| \ | | / | \/ \| | | | / | \ | \\____ |
  22. // |____|_ /_______ / |____| \_______ /_______ /|___| |____| \_______ /____|_ // ______|
  23. // \/ \/ \/ \/ \/ \/ \/
  24. // CreateRepoForm form for creating repository
  25. type CreateRepoForm struct {
  26. UID int64 `binding:"Required"`
  27. RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"`
  28. Private bool
  29. Description string `binding:"MaxSize(255)"`
  30. DefaultBranch string `binding:"GitRefName;MaxSize(100)"`
  31. AutoInit bool
  32. Gitignores string
  33. IssueLabels string
  34. License string
  35. Readme string
  36. Template bool
  37. RepoTemplate int64
  38. GitContent bool
  39. Topics bool
  40. GitHooks bool
  41. Webhooks bool
  42. Avatar bool
  43. Labels bool
  44. TrustModel string
  45. }
  46. // Validate validates the fields
  47. func (f *CreateRepoForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  48. ctx := context.GetContext(req)
  49. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  50. }
  51. // MigrateRepoForm form for migrating repository
  52. // this is used to interact with web ui
  53. type MigrateRepoForm struct {
  54. // required: true
  55. CloneAddr string `json:"clone_addr" binding:"Required"`
  56. Service structs.GitServiceType `json:"service"`
  57. AuthUsername string `json:"auth_username"`
  58. AuthPassword string `json:"auth_password"`
  59. AuthToken string `json:"auth_token"`
  60. // required: true
  61. UID int64 `json:"uid" binding:"Required"`
  62. // required: true
  63. RepoName string `json:"repo_name" binding:"Required;AlphaDashDot;MaxSize(100)"`
  64. Mirror bool `json:"mirror"`
  65. LFS bool `json:"lfs"`
  66. LFSEndpoint string `json:"lfs_endpoint"`
  67. Private bool `json:"private"`
  68. Description string `json:"description" binding:"MaxSize(255)"`
  69. Wiki bool `json:"wiki"`
  70. Milestones bool `json:"milestones"`
  71. Labels bool `json:"labels"`
  72. Issues bool `json:"issues"`
  73. PullRequests bool `json:"pull_requests"`
  74. Releases bool `json:"releases"`
  75. MirrorInterval string `json:"mirror_interval"`
  76. }
  77. // Validate validates the fields
  78. func (f *MigrateRepoForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  79. ctx := context.GetContext(req)
  80. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  81. }
  82. // ParseRemoteAddr checks if given remote address is valid,
  83. // and returns composed URL with needed username and password.
  84. func ParseRemoteAddr(remoteAddr, authUsername, authPassword string) (string, error) {
  85. remoteAddr = strings.TrimSpace(remoteAddr)
  86. // Remote address can be HTTP/HTTPS/Git URL or local path.
  87. if strings.HasPrefix(remoteAddr, "http://") ||
  88. strings.HasPrefix(remoteAddr, "https://") ||
  89. strings.HasPrefix(remoteAddr, "git://") {
  90. u, err := url.Parse(remoteAddr)
  91. if err != nil {
  92. return "", &models.ErrInvalidCloneAddr{IsURLError: true}
  93. }
  94. if len(authUsername)+len(authPassword) > 0 {
  95. u.User = url.UserPassword(authUsername, authPassword)
  96. }
  97. remoteAddr = u.String()
  98. }
  99. return remoteAddr, nil
  100. }
  101. // RepoSettingForm form for changing repository settings
  102. type RepoSettingForm struct {
  103. RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"`
  104. Description string `binding:"MaxSize(255)"`
  105. Website string `binding:"ValidUrl;MaxSize(255)"`
  106. Interval string
  107. MirrorAddress string
  108. MirrorUsername string
  109. MirrorPassword string
  110. LFS bool `form:"mirror_lfs"`
  111. LFSEndpoint string `form:"mirror_lfs_endpoint"`
  112. PushMirrorID string
  113. PushMirrorAddress string
  114. PushMirrorUsername string
  115. PushMirrorPassword string
  116. PushMirrorInterval string
  117. Private bool
  118. Template bool
  119. EnablePrune bool
  120. // Advanced settings
  121. EnableWiki bool
  122. EnableExternalWiki bool
  123. ExternalWikiURL string
  124. EnableIssues bool
  125. EnableExternalTracker bool
  126. ExternalTrackerURL string
  127. TrackerURLFormat string
  128. TrackerIssueStyle string
  129. EnableCloseIssuesViaCommitInAnyBranch bool
  130. EnableProjects bool
  131. EnablePulls bool
  132. PullsIgnoreWhitespace bool
  133. PullsAllowMerge bool
  134. PullsAllowRebase bool
  135. PullsAllowRebaseMerge bool
  136. PullsAllowSquash bool
  137. PullsAllowManualMerge bool
  138. PullsDefaultMergeStyle string
  139. EnableAutodetectManualMerge bool
  140. DefaultDeleteBranchAfterMerge bool
  141. EnableTimetracker bool
  142. AllowOnlyContributorsToTrackTime bool
  143. EnableIssueDependencies bool
  144. IsArchived bool
  145. // Signing Settings
  146. TrustModel string
  147. // Admin settings
  148. EnableHealthCheck bool
  149. }
  150. // Validate validates the fields
  151. func (f *RepoSettingForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  152. ctx := context.GetContext(req)
  153. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  154. }
  155. // __________ .__
  156. // \______ \____________ ____ ____ | |__
  157. // | | _/\_ __ \__ \ / \_/ ___\| | \
  158. // | | \ | | \// __ \| | \ \___| Y \
  159. // |______ / |__| (____ /___| /\___ >___| /
  160. // \/ \/ \/ \/ \/
  161. // ProtectBranchForm form for changing protected branch settings
  162. type ProtectBranchForm struct {
  163. Protected bool
  164. EnablePush string
  165. WhitelistUsers string
  166. WhitelistTeams string
  167. WhitelistDeployKeys bool
  168. EnableMergeWhitelist bool
  169. MergeWhitelistUsers string
  170. MergeWhitelistTeams string
  171. EnableStatusCheck bool
  172. StatusCheckContexts []string
  173. RequiredApprovals int64
  174. EnableApprovalsWhitelist bool
  175. ApprovalsWhitelistUsers string
  176. ApprovalsWhitelistTeams string
  177. BlockOnRejectedReviews bool
  178. BlockOnOfficialReviewRequests bool
  179. BlockOnOutdatedBranch bool
  180. DismissStaleApprovals bool
  181. RequireSignedCommits bool
  182. ProtectedFilePatterns string
  183. UnprotectedFilePatterns string
  184. }
  185. // Validate validates the fields
  186. func (f *ProtectBranchForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  187. ctx := context.GetContext(req)
  188. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  189. }
  190. // __ __ ___. .__ .__ __
  191. // / \ / \ ____\_ |__ | |__ | |__ ____ | | __
  192. // \ \/\/ // __ \| __ \| | \| | \ / _ \| |/ /
  193. // \ /\ ___/| \_\ \ Y \ Y ( <_> ) <
  194. // \__/\ / \___ >___ /___| /___| /\____/|__|_ \
  195. // \/ \/ \/ \/ \/ \/
  196. // WebhookForm form for changing web hook
  197. type WebhookForm struct {
  198. Events string
  199. Create bool
  200. Delete bool
  201. Fork bool
  202. Issues bool
  203. IssueAssign bool
  204. IssueLabel bool
  205. IssueMilestone bool
  206. IssueComment bool
  207. Release bool
  208. Push bool
  209. PullRequest bool
  210. PullRequestAssign bool
  211. PullRequestLabel bool
  212. PullRequestMilestone bool
  213. PullRequestComment bool
  214. PullRequestReview bool
  215. PullRequestSync bool
  216. Repository bool
  217. Active bool
  218. BranchFilter string `binding:"GlobPattern"`
  219. }
  220. // PushOnly if the hook will be triggered when push
  221. func (f WebhookForm) PushOnly() bool {
  222. return f.Events == "push_only"
  223. }
  224. // SendEverything if the hook will be triggered any event
  225. func (f WebhookForm) SendEverything() bool {
  226. return f.Events == "send_everything"
  227. }
  228. // ChooseEvents if the hook will be triggered choose events
  229. func (f WebhookForm) ChooseEvents() bool {
  230. return f.Events == "choose_events"
  231. }
  232. // NewWebhookForm form for creating web hook
  233. type NewWebhookForm struct {
  234. PayloadURL string `binding:"Required;ValidUrl"`
  235. HTTPMethod string `binding:"Required;In(POST,GET)"`
  236. ContentType int `binding:"Required"`
  237. Secret string
  238. WebhookForm
  239. }
  240. // Validate validates the fields
  241. func (f *NewWebhookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  242. ctx := context.GetContext(req)
  243. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  244. }
  245. // NewGogshookForm form for creating gogs hook
  246. type NewGogshookForm struct {
  247. PayloadURL string `binding:"Required;ValidUrl"`
  248. ContentType int `binding:"Required"`
  249. Secret string
  250. WebhookForm
  251. }
  252. // Validate validates the fields
  253. func (f *NewGogshookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  254. ctx := context.GetContext(req)
  255. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  256. }
  257. // NewSlackHookForm form for creating slack hook
  258. type NewSlackHookForm struct {
  259. PayloadURL string `binding:"Required;ValidUrl"`
  260. Channel string `binding:"Required"`
  261. Username string
  262. IconURL string
  263. Color string
  264. WebhookForm
  265. }
  266. // Validate validates the fields
  267. func (f *NewSlackHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  268. ctx := context.GetContext(req)
  269. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  270. }
  271. // HasInvalidChannel validates the channel name is in the right format
  272. func (f NewSlackHookForm) HasInvalidChannel() bool {
  273. return !utils.IsValidSlackChannel(f.Channel)
  274. }
  275. // NewDiscordHookForm form for creating discord hook
  276. type NewDiscordHookForm struct {
  277. PayloadURL string `binding:"Required;ValidUrl"`
  278. Username string
  279. IconURL string
  280. WebhookForm
  281. }
  282. // Validate validates the fields
  283. func (f *NewDiscordHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  284. ctx := context.GetContext(req)
  285. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  286. }
  287. // NewDingtalkHookForm form for creating dingtalk hook
  288. type NewDingtalkHookForm struct {
  289. PayloadURL string `binding:"Required;ValidUrl"`
  290. WebhookForm
  291. }
  292. // Validate validates the fields
  293. func (f *NewDingtalkHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  294. ctx := context.GetContext(req)
  295. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  296. }
  297. // NewTelegramHookForm form for creating telegram hook
  298. type NewTelegramHookForm struct {
  299. BotToken string `binding:"Required"`
  300. ChatID string `binding:"Required"`
  301. WebhookForm
  302. }
  303. // Validate validates the fields
  304. func (f *NewTelegramHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  305. ctx := context.GetContext(req)
  306. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  307. }
  308. // NewMatrixHookForm form for creating Matrix hook
  309. type NewMatrixHookForm struct {
  310. HomeserverURL string `binding:"Required;ValidUrl"`
  311. RoomID string `binding:"Required"`
  312. AccessToken string `binding:"Required"`
  313. MessageType int
  314. WebhookForm
  315. }
  316. // Validate validates the fields
  317. func (f *NewMatrixHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  318. ctx := context.GetContext(req)
  319. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  320. }
  321. // NewMSTeamsHookForm form for creating MS Teams hook
  322. type NewMSTeamsHookForm struct {
  323. PayloadURL string `binding:"Required;ValidUrl"`
  324. WebhookForm
  325. }
  326. // Validate validates the fields
  327. func (f *NewMSTeamsHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  328. ctx := context.GetContext(req)
  329. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  330. }
  331. // NewFeishuHookForm form for creating feishu hook
  332. type NewFeishuHookForm struct {
  333. PayloadURL string `binding:"Required;ValidUrl"`
  334. WebhookForm
  335. }
  336. // Validate validates the fields
  337. func (f *NewFeishuHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  338. ctx := context.GetContext(req)
  339. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  340. }
  341. // NewWechatWorkHookForm form for creating wechatwork hook
  342. type NewWechatWorkHookForm struct {
  343. PayloadURL string `binding:"Required;ValidUrl"`
  344. WebhookForm
  345. }
  346. // Validate validates the fields
  347. func (f *NewWechatWorkHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  348. ctx := context.GetContext(req)
  349. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  350. }
  351. // .___
  352. // | | ______ ________ __ ____
  353. // | |/ ___// ___/ | \_/ __ \
  354. // | |\___ \ \___ \| | /\ ___/
  355. // |___/____ >____ >____/ \___ >
  356. // \/ \/ \/
  357. // CreateIssueForm form for creating issue
  358. type CreateIssueForm struct {
  359. Title string `binding:"Required;MaxSize(255)"`
  360. LabelIDs string `form:"label_ids"`
  361. AssigneeIDs string `form:"assignee_ids"`
  362. Ref string `form:"ref"`
  363. MilestoneID int64
  364. ProjectID int64
  365. AssigneeID int64
  366. Content string
  367. Files []string
  368. }
  369. // Validate validates the fields
  370. func (f *CreateIssueForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  371. ctx := context.GetContext(req)
  372. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  373. }
  374. // CreateCommentForm form for creating comment
  375. type CreateCommentForm struct {
  376. Content string
  377. Status string `binding:"OmitEmpty;In(reopen,close)"`
  378. Files []string
  379. }
  380. // Validate validates the fields
  381. func (f *CreateCommentForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  382. ctx := context.GetContext(req)
  383. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  384. }
  385. // ReactionForm form for adding and removing reaction
  386. type ReactionForm struct {
  387. Content string `binding:"Required"`
  388. }
  389. // Validate validates the fields
  390. func (f *ReactionForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  391. ctx := context.GetContext(req)
  392. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  393. }
  394. // IssueLockForm form for locking an issue
  395. type IssueLockForm struct {
  396. Reason string `binding:"Required"`
  397. }
  398. // Validate validates the fields
  399. func (i *IssueLockForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  400. ctx := context.GetContext(req)
  401. return middleware.Validate(errs, ctx.Data, i, ctx.Locale)
  402. }
  403. // HasValidReason checks to make sure that the reason submitted in
  404. // the form matches any of the values in the config
  405. func (i IssueLockForm) HasValidReason() bool {
  406. if strings.TrimSpace(i.Reason) == "" {
  407. return true
  408. }
  409. for _, v := range setting.Repository.Issue.LockReasons {
  410. if v == i.Reason {
  411. return true
  412. }
  413. }
  414. return false
  415. }
  416. // __________ __ __
  417. // \______ \_______ ____ |__| ____ _____/ |_ ______
  418. // | ___/\_ __ \/ _ \ | |/ __ \_/ ___\ __\/ ___/
  419. // | | | | \( <_> ) | \ ___/\ \___| | \___ \
  420. // |____| |__| \____/\__| |\___ >\___ >__| /____ >
  421. // \______| \/ \/ \/
  422. // CreateProjectForm form for creating a project
  423. type CreateProjectForm struct {
  424. Title string `binding:"Required;MaxSize(100)"`
  425. Content string
  426. BoardType models.ProjectBoardType
  427. }
  428. // UserCreateProjectForm is a from for creating an individual or organization
  429. // form.
  430. type UserCreateProjectForm struct {
  431. Title string `binding:"Required;MaxSize(100)"`
  432. Content string
  433. BoardType models.ProjectBoardType
  434. UID int64 `binding:"Required"`
  435. }
  436. // EditProjectBoardForm is a form for editing a project board
  437. type EditProjectBoardForm struct {
  438. Title string `binding:"Required;MaxSize(100)"`
  439. Sorting int8
  440. }
  441. // _____ .__.__ __
  442. // / \ |__| | ____ _______/ |_ ____ ____ ____
  443. // / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \
  444. // / Y \ | |_\ ___/ \___ \ | | ( <_> ) | \ ___/
  445. // \____|__ /__|____/\___ >____ > |__| \____/|___| /\___ >
  446. // \/ \/ \/ \/ \/
  447. // CreateMilestoneForm form for creating milestone
  448. type CreateMilestoneForm struct {
  449. Title string `binding:"Required;MaxSize(50)"`
  450. Content string
  451. Deadline string
  452. }
  453. // Validate validates the fields
  454. func (f *CreateMilestoneForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  455. ctx := context.GetContext(req)
  456. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  457. }
  458. // .____ ___. .__
  459. // | | _____ \_ |__ ____ | |
  460. // | | \__ \ | __ \_/ __ \| |
  461. // | |___ / __ \| \_\ \ ___/| |__
  462. // |_______ (____ /___ /\___ >____/
  463. // \/ \/ \/ \/
  464. // CreateLabelForm form for creating label
  465. type CreateLabelForm struct {
  466. ID int64
  467. Title string `binding:"Required;MaxSize(50)" locale:"repo.issues.label_title"`
  468. Description string `binding:"MaxSize(200)" locale:"repo.issues.label_description"`
  469. Color string `binding:"Required;Size(7)" locale:"repo.issues.label_color"`
  470. }
  471. // Validate validates the fields
  472. func (f *CreateLabelForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  473. ctx := context.GetContext(req)
  474. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  475. }
  476. // InitializeLabelsForm form for initializing labels
  477. type InitializeLabelsForm struct {
  478. TemplateName string `binding:"Required"`
  479. }
  480. // Validate validates the fields
  481. func (f *InitializeLabelsForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  482. ctx := context.GetContext(req)
  483. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  484. }
  485. // __________ .__ .__ __________ __
  486. // \______ \__ __| | | | \______ \ ____ ________ __ ____ _______/ |_
  487. // | ___/ | \ | | | | _// __ \/ ____/ | \_/ __ \ / ___/\ __\
  488. // | | | | / |_| |__ | | \ ___< <_| | | /\ ___/ \___ \ | |
  489. // |____| |____/|____/____/ |____|_ /\___ >__ |____/ \___ >____ > |__|
  490. // \/ \/ |__| \/ \/
  491. // MergePullRequestForm form for merging Pull Request
  492. // swagger:model MergePullRequestOption
  493. type MergePullRequestForm struct {
  494. // required: true
  495. // enum: merge,rebase,rebase-merge,squash,manually-merged
  496. Do string `binding:"Required;In(merge,rebase,rebase-merge,squash,manually-merged)"`
  497. MergeTitleField string
  498. MergeMessageField string
  499. MergeCommitID string // only used for manually-merged
  500. ForceMerge *bool `json:"force_merge,omitempty"`
  501. DeleteBranchAfterMerge bool `json:"delete_branch_after_merge,omitempty"`
  502. }
  503. // Validate validates the fields
  504. func (f *MergePullRequestForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  505. ctx := context.GetContext(req)
  506. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  507. }
  508. // CodeCommentForm form for adding code comments for PRs
  509. type CodeCommentForm struct {
  510. Origin string `binding:"Required;In(timeline,diff)"`
  511. Content string `binding:"Required"`
  512. Side string `binding:"Required;In(previous,proposed)"`
  513. Line int64
  514. TreePath string `form:"path" binding:"Required"`
  515. IsReview bool `form:"is_review"`
  516. Reply int64 `form:"reply"`
  517. LatestCommitID string
  518. }
  519. // Validate validates the fields
  520. func (f *CodeCommentForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  521. ctx := context.GetContext(req)
  522. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  523. }
  524. // SubmitReviewForm for submitting a finished code review
  525. type SubmitReviewForm struct {
  526. Content string
  527. Type string `binding:"Required;In(approve,comment,reject)"`
  528. CommitID string
  529. Files []string
  530. }
  531. // Validate validates the fields
  532. func (f *SubmitReviewForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  533. ctx := context.GetContext(req)
  534. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  535. }
  536. // ReviewType will return the corresponding reviewtype for type
  537. func (f SubmitReviewForm) ReviewType() models.ReviewType {
  538. switch f.Type {
  539. case "approve":
  540. return models.ReviewTypeApprove
  541. case "comment":
  542. return models.ReviewTypeComment
  543. case "reject":
  544. return models.ReviewTypeReject
  545. default:
  546. return models.ReviewTypeUnknown
  547. }
  548. }
  549. // HasEmptyContent checks if the content of the review form is empty.
  550. func (f SubmitReviewForm) HasEmptyContent() bool {
  551. reviewType := f.ReviewType()
  552. return (reviewType == models.ReviewTypeComment || reviewType == models.ReviewTypeReject) &&
  553. len(strings.TrimSpace(f.Content)) == 0
  554. }
  555. // DismissReviewForm for dismissing stale review by repo admin
  556. type DismissReviewForm struct {
  557. ReviewID int64 `binding:"Required"`
  558. Message string
  559. }
  560. // __________ .__
  561. // \______ \ ____ | | ____ _____ ______ ____
  562. // | _// __ \| | _/ __ \\__ \ / ___// __ \
  563. // | | \ ___/| |_\ ___/ / __ \_\___ \\ ___/
  564. // |____|_ /\___ >____/\___ >____ /____ >\___ >
  565. // \/ \/ \/ \/ \/ \/
  566. // NewReleaseForm form for creating release
  567. type NewReleaseForm struct {
  568. TagName string `binding:"Required;GitRefName;MaxSize(255)"`
  569. Target string `form:"tag_target" binding:"Required;MaxSize(255)"`
  570. Title string `binding:"Required;MaxSize(255)"`
  571. Content string
  572. Draft string
  573. TagOnly string
  574. Prerelease bool
  575. AddTagMsg bool
  576. Files []string
  577. }
  578. // Validate validates the fields
  579. func (f *NewReleaseForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  580. ctx := context.GetContext(req)
  581. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  582. }
  583. // EditReleaseForm form for changing release
  584. type EditReleaseForm struct {
  585. Title string `form:"title" binding:"Required;MaxSize(255)"`
  586. Content string `form:"content"`
  587. Draft string `form:"draft"`
  588. Prerelease bool `form:"prerelease"`
  589. Files []string
  590. }
  591. // Validate validates the fields
  592. func (f *EditReleaseForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  593. ctx := context.GetContext(req)
  594. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  595. }
  596. // __ __.__ __ .__
  597. // / \ / \__| | _|__|
  598. // \ \/\/ / | |/ / |
  599. // \ /| | <| |
  600. // \__/\ / |__|__|_ \__|
  601. // \/ \/
  602. // NewWikiForm form for creating wiki
  603. type NewWikiForm struct {
  604. Title string `binding:"Required"`
  605. Content string `binding:"Required"`
  606. Message string
  607. }
  608. // Validate validates the fields
  609. // FIXME: use code generation to generate this method.
  610. func (f *NewWikiForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  611. ctx := context.GetContext(req)
  612. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  613. }
  614. // ___________ .___.__ __
  615. // \_ _____/ __| _/|__|/ |_
  616. // | __)_ / __ | | \ __\
  617. // | \/ /_/ | | || |
  618. // /_______ /\____ | |__||__|
  619. // \/ \/
  620. // EditRepoFileForm form for changing repository file
  621. type EditRepoFileForm struct {
  622. TreePath string `binding:"Required;MaxSize(500)"`
  623. Content string
  624. CommitSummary string `binding:"MaxSize(100)"`
  625. CommitMessage string
  626. CommitChoice string `binding:"Required;MaxSize(50)"`
  627. NewBranchName string `binding:"GitRefName;MaxSize(100)"`
  628. LastCommit string
  629. Signoff bool
  630. }
  631. // Validate validates the fields
  632. func (f *EditRepoFileForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  633. ctx := context.GetContext(req)
  634. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  635. }
  636. // EditPreviewDiffForm form for changing preview diff
  637. type EditPreviewDiffForm struct {
  638. Content string
  639. }
  640. // Validate validates the fields
  641. func (f *EditPreviewDiffForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  642. ctx := context.GetContext(req)
  643. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  644. }
  645. // ____ ___ .__ .___
  646. // | | \______ | | _________ __| _/
  647. // | | /\____ \| | / _ \__ \ / __ |
  648. // | | / | |_> > |_( <_> ) __ \_/ /_/ |
  649. // |______/ | __/|____/\____(____ /\____ |
  650. // |__| \/ \/
  651. //
  652. // UploadRepoFileForm form for uploading repository file
  653. type UploadRepoFileForm struct {
  654. TreePath string `binding:"MaxSize(500)"`
  655. CommitSummary string `binding:"MaxSize(100)"`
  656. CommitMessage string
  657. CommitChoice string `binding:"Required;MaxSize(50)"`
  658. NewBranchName string `binding:"GitRefName;MaxSize(100)"`
  659. Files []string
  660. Signoff bool
  661. }
  662. // Validate validates the fields
  663. func (f *UploadRepoFileForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  664. ctx := context.GetContext(req)
  665. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  666. }
  667. // RemoveUploadFileForm form for removing uploaded file
  668. type RemoveUploadFileForm struct {
  669. File string `binding:"Required;MaxSize(50)"`
  670. }
  671. // Validate validates the fields
  672. func (f *RemoveUploadFileForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  673. ctx := context.GetContext(req)
  674. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  675. }
  676. // ________ .__ __
  677. // \______ \ ____ | | _____/ |_ ____
  678. // | | \_/ __ \| | _/ __ \ __\/ __ \
  679. // | ` \ ___/| |_\ ___/| | \ ___/
  680. // /_______ /\___ >____/\___ >__| \___ >
  681. // \/ \/ \/ \/
  682. // DeleteRepoFileForm form for deleting repository file
  683. type DeleteRepoFileForm struct {
  684. CommitSummary string `binding:"MaxSize(100)"`
  685. CommitMessage string
  686. CommitChoice string `binding:"Required;MaxSize(50)"`
  687. NewBranchName string `binding:"GitRefName;MaxSize(100)"`
  688. LastCommit string
  689. Signoff bool
  690. }
  691. // Validate validates the fields
  692. func (f *DeleteRepoFileForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  693. ctx := context.GetContext(req)
  694. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  695. }
  696. // ___________.__ ___________ __
  697. // \__ ___/|__| _____ ____ \__ ___/___________ ____ | | __ ___________
  698. // | | | |/ \_/ __ \ | | \_ __ \__ \ _/ ___\| |/ // __ \_ __ \
  699. // | | | | Y Y \ ___/ | | | | \// __ \\ \___| <\ ___/| | \/
  700. // |____| |__|__|_| /\___ > |____| |__| (____ /\___ >__|_ \\___ >__|
  701. // \/ \/ \/ \/ \/ \/
  702. // AddTimeManuallyForm form that adds spent time manually.
  703. type AddTimeManuallyForm struct {
  704. Hours int `binding:"Range(0,1000)"`
  705. Minutes int `binding:"Range(0,1000)"`
  706. }
  707. // Validate validates the fields
  708. func (f *AddTimeManuallyForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  709. ctx := context.GetContext(req)
  710. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  711. }
  712. // SaveTopicForm form for save topics for repository
  713. type SaveTopicForm struct {
  714. Topics []string `binding:"topics;Required;"`
  715. }
  716. // DeadlineForm hold the validation rules for deadlines
  717. type DeadlineForm struct {
  718. DateString string `form:"date" binding:"Required;Size(10)"`
  719. }
  720. // Validate validates the fields
  721. func (f *DeadlineForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  722. ctx := context.GetContext(req)
  723. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  724. }