gitea源码

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Copyright 2017 The Gitea Authors. All rights reserved.
  3. // SPDX-License-Identifier: MIT
  4. package forms
  5. import (
  6. "net/http"
  7. "strings"
  8. issues_model "code.gitea.io/gitea/models/issues"
  9. project_model "code.gitea.io/gitea/models/project"
  10. "code.gitea.io/gitea/modules/structs"
  11. "code.gitea.io/gitea/modules/web/middleware"
  12. "code.gitea.io/gitea/services/context"
  13. "code.gitea.io/gitea/services/webhook"
  14. "gitea.com/go-chi/binding"
  15. )
  16. // CreateRepoForm form for creating repository
  17. type CreateRepoForm struct {
  18. UID int64 `binding:"Required"`
  19. RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"`
  20. Private bool
  21. Description string `binding:"MaxSize(2048)"`
  22. DefaultBranch string `binding:"GitRefName;MaxSize(100)"`
  23. AutoInit bool
  24. Gitignores string
  25. IssueLabels string
  26. License string
  27. Readme string
  28. Template bool
  29. RepoTemplate int64
  30. GitContent bool
  31. Topics bool
  32. GitHooks bool
  33. Webhooks bool
  34. Avatar bool
  35. Labels bool
  36. ProtectedBranch bool
  37. ForkSingleBranch string
  38. ObjectFormatName string
  39. }
  40. // Validate validates the fields
  41. func (f *CreateRepoForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  42. ctx := context.GetValidateContext(req)
  43. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  44. }
  45. // MigrateRepoForm form for migrating repository
  46. // this is used to interact with web ui
  47. type MigrateRepoForm struct {
  48. // required: true
  49. CloneAddr string `json:"clone_addr" binding:"Required"`
  50. Service structs.GitServiceType `json:"service"`
  51. AuthUsername string `json:"auth_username"`
  52. AuthPassword string `json:"auth_password"`
  53. AuthToken string `json:"auth_token"`
  54. // required: true
  55. UID int64 `json:"uid" binding:"Required"`
  56. // required: true
  57. RepoName string `json:"repo_name" binding:"Required;AlphaDashDot;MaxSize(100)"`
  58. Mirror bool `json:"mirror"`
  59. LFS bool `json:"lfs"`
  60. LFSEndpoint string `json:"lfs_endpoint"`
  61. Private bool `json:"private"`
  62. Description string `json:"description" binding:"MaxSize(2048)"`
  63. Wiki bool `json:"wiki"`
  64. Milestones bool `json:"milestones"`
  65. Labels bool `json:"labels"`
  66. Issues bool `json:"issues"`
  67. PullRequests bool `json:"pull_requests"`
  68. Releases bool `json:"releases"`
  69. MirrorInterval string `json:"mirror_interval"`
  70. AWSAccessKeyID string `json:"aws_access_key_id"`
  71. AWSSecretAccessKey string `json:"aws_secret_access_key"`
  72. }
  73. // Validate validates the fields
  74. func (f *MigrateRepoForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  75. ctx := context.GetValidateContext(req)
  76. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  77. }
  78. // RepoSettingForm form for changing repository settings
  79. type RepoSettingForm struct {
  80. RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"`
  81. Description string `binding:"MaxSize(2048)"`
  82. Website string `binding:"ValidUrl;MaxSize(1024)"`
  83. Interval string
  84. MirrorAddress string
  85. MirrorUsername string
  86. MirrorPassword string
  87. LFS bool `form:"mirror_lfs"`
  88. LFSEndpoint string `form:"mirror_lfs_endpoint"`
  89. PushMirrorID int64
  90. PushMirrorAddress string
  91. PushMirrorUsername string
  92. PushMirrorPassword string
  93. PushMirrorSyncOnCommit bool
  94. PushMirrorInterval string
  95. Private bool
  96. Template bool
  97. EnablePrune bool
  98. // Advanced settings
  99. EnableCode bool
  100. EnableWiki bool
  101. EnableExternalWiki bool
  102. DefaultWikiBranch string
  103. ExternalWikiURL string
  104. EnableIssues bool
  105. EnableExternalTracker bool
  106. ExternalTrackerURL string
  107. TrackerURLFormat string
  108. TrackerIssueStyle string
  109. ExternalTrackerRegexpPattern string
  110. EnableCloseIssuesViaCommitInAnyBranch bool
  111. EnableProjects bool
  112. ProjectsMode string
  113. EnableReleases bool
  114. EnablePackages bool
  115. EnablePulls bool
  116. PullsIgnoreWhitespace bool
  117. PullsAllowMerge bool
  118. PullsAllowRebase bool
  119. PullsAllowRebaseMerge bool
  120. PullsAllowSquash bool
  121. PullsAllowFastForwardOnly bool
  122. PullsAllowManualMerge bool
  123. PullsDefaultMergeStyle string
  124. EnableAutodetectManualMerge bool
  125. PullsAllowRebaseUpdate bool
  126. DefaultDeleteBranchAfterMerge bool
  127. DefaultAllowMaintainerEdit bool
  128. EnableTimetracker bool
  129. AllowOnlyContributorsToTrackTime bool
  130. EnableIssueDependencies bool
  131. EnableActions bool
  132. IsArchived bool
  133. // Signing Settings
  134. TrustModel string
  135. // Admin settings
  136. EnableHealthCheck bool
  137. RequestReindexType string
  138. }
  139. // Validate validates the fields
  140. func (f *RepoSettingForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  141. ctx := context.GetValidateContext(req)
  142. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  143. }
  144. // ProtectBranchForm form for changing protected branch settings
  145. type ProtectBranchForm struct {
  146. RuleName string `binding:"Required"`
  147. RuleID int64
  148. EnablePush string
  149. WhitelistUsers string
  150. WhitelistTeams string
  151. WhitelistDeployKeys bool
  152. EnableForcePush string
  153. ForcePushAllowlistUsers string
  154. ForcePushAllowlistTeams string
  155. ForcePushAllowlistDeployKeys bool
  156. EnableMergeWhitelist bool
  157. MergeWhitelistUsers string
  158. MergeWhitelistTeams string
  159. EnableStatusCheck bool
  160. StatusCheckContexts string
  161. RequiredApprovals int64
  162. EnableApprovalsWhitelist bool
  163. ApprovalsWhitelistUsers string
  164. ApprovalsWhitelistTeams string
  165. BlockOnRejectedReviews bool
  166. BlockOnOfficialReviewRequests bool
  167. BlockOnOutdatedBranch bool
  168. DismissStaleApprovals bool
  169. IgnoreStaleApprovals bool
  170. RequireSignedCommits bool
  171. ProtectedFilePatterns string
  172. UnprotectedFilePatterns string
  173. BlockAdminMergeOverride bool
  174. }
  175. // Validate validates the fields
  176. func (f *ProtectBranchForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  177. ctx := context.GetValidateContext(req)
  178. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  179. }
  180. type ProtectBranchPriorityForm struct {
  181. IDs []int64
  182. }
  183. // WebhookForm form for changing web hook
  184. type WebhookForm struct {
  185. Events string
  186. Create bool
  187. Delete bool
  188. Fork bool
  189. Push bool
  190. Issues bool
  191. IssueAssign bool
  192. IssueLabel bool
  193. IssueMilestone bool
  194. IssueComment bool
  195. PullRequest bool
  196. PullRequestAssign bool
  197. PullRequestLabel bool
  198. PullRequestMilestone bool
  199. PullRequestComment bool
  200. PullRequestReview bool
  201. PullRequestSync bool
  202. PullRequestReviewRequest bool
  203. Wiki bool
  204. Repository bool
  205. Release bool
  206. Package bool
  207. Status bool
  208. WorkflowRun bool
  209. WorkflowJob bool
  210. Active bool
  211. BranchFilter string `binding:"GlobPattern"`
  212. AuthorizationHeader string
  213. Secret string
  214. }
  215. // PushOnly if the hook will be triggered when push
  216. func (f WebhookForm) PushOnly() bool {
  217. return f.Events == "push_only"
  218. }
  219. // SendEverything if the hook will be triggered any event
  220. func (f WebhookForm) SendEverything() bool {
  221. return f.Events == "send_everything"
  222. }
  223. // ChooseEvents if the hook will be triggered choose events
  224. func (f WebhookForm) ChooseEvents() bool {
  225. return f.Events == "choose_events"
  226. }
  227. // NewWebhookForm form for creating web hook
  228. type NewWebhookForm struct {
  229. PayloadURL string `binding:"Required;ValidUrl"`
  230. HTTPMethod string `binding:"Required;In(POST,GET)"`
  231. ContentType int `binding:"Required"`
  232. WebhookForm
  233. }
  234. // Validate validates the fields
  235. func (f *NewWebhookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  236. ctx := context.GetValidateContext(req)
  237. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  238. }
  239. // NewGogshookForm form for creating gogs hook
  240. type NewGogshookForm struct {
  241. PayloadURL string `binding:"Required;ValidUrl"`
  242. ContentType int `binding:"Required"`
  243. WebhookForm
  244. }
  245. // Validate validates the fields
  246. func (f *NewGogshookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  247. ctx := context.GetValidateContext(req)
  248. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  249. }
  250. // NewSlackHookForm form for creating slack hook
  251. type NewSlackHookForm struct {
  252. PayloadURL string `binding:"Required;ValidUrl"`
  253. Channel string `binding:"Required"`
  254. Username string
  255. IconURL string
  256. Color string
  257. WebhookForm
  258. }
  259. // Validate validates the fields
  260. func (f *NewSlackHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  261. ctx := context.GetValidateContext(req)
  262. if !webhook.IsValidSlackChannel(strings.TrimSpace(f.Channel)) {
  263. errs = append(errs, binding.Error{
  264. FieldNames: []string{"Channel"},
  265. Classification: "",
  266. Message: ctx.Locale.TrString("repo.settings.add_webhook.invalid_channel_name"),
  267. })
  268. }
  269. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  270. }
  271. // NewDiscordHookForm form for creating discord hook
  272. type NewDiscordHookForm struct {
  273. PayloadURL string `binding:"Required;ValidUrl"`
  274. Username string
  275. IconURL string
  276. WebhookForm
  277. }
  278. // Validate validates the fields
  279. func (f *NewDiscordHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  280. ctx := context.GetValidateContext(req)
  281. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  282. }
  283. // NewDingtalkHookForm form for creating dingtalk hook
  284. type NewDingtalkHookForm struct {
  285. PayloadURL string `binding:"Required;ValidUrl"`
  286. WebhookForm
  287. }
  288. // Validate validates the fields
  289. func (f *NewDingtalkHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  290. ctx := context.GetValidateContext(req)
  291. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  292. }
  293. // NewTelegramHookForm form for creating telegram hook
  294. type NewTelegramHookForm struct {
  295. BotToken string `binding:"Required"`
  296. ChatID string `binding:"Required"`
  297. ThreadID string
  298. WebhookForm
  299. }
  300. // Validate validates the fields
  301. func (f *NewTelegramHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  302. ctx := context.GetValidateContext(req)
  303. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  304. }
  305. // NewMatrixHookForm form for creating Matrix hook
  306. type NewMatrixHookForm struct {
  307. HomeserverURL string `binding:"Required;ValidUrl"`
  308. RoomID string `binding:"Required"`
  309. MessageType int
  310. WebhookForm
  311. }
  312. // Validate validates the fields
  313. func (f *NewMatrixHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  314. ctx := context.GetValidateContext(req)
  315. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  316. }
  317. // NewMSTeamsHookForm form for creating MS Teams hook
  318. type NewMSTeamsHookForm struct {
  319. PayloadURL string `binding:"Required;ValidUrl"`
  320. WebhookForm
  321. }
  322. // Validate validates the fields
  323. func (f *NewMSTeamsHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  324. ctx := context.GetValidateContext(req)
  325. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  326. }
  327. // NewFeishuHookForm form for creating feishu hook
  328. type NewFeishuHookForm struct {
  329. PayloadURL string `binding:"Required;ValidUrl"`
  330. WebhookForm
  331. }
  332. // Validate validates the fields
  333. func (f *NewFeishuHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  334. ctx := context.GetValidateContext(req)
  335. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  336. }
  337. // NewWechatWorkHookForm form for creating wechatwork hook
  338. type NewWechatWorkHookForm struct {
  339. PayloadURL string `binding:"Required;ValidUrl"`
  340. WebhookForm
  341. }
  342. // Validate validates the fields
  343. func (f *NewWechatWorkHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  344. ctx := context.GetValidateContext(req)
  345. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  346. }
  347. // NewPackagistHookForm form for creating packagist hook
  348. type NewPackagistHookForm struct {
  349. Username string `binding:"Required"`
  350. APIToken string `binding:"Required"`
  351. PackageURL string `binding:"Required;ValidUrl"`
  352. WebhookForm
  353. }
  354. // Validate validates the fields
  355. func (f *NewPackagistHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  356. ctx := context.GetValidateContext(req)
  357. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  358. }
  359. // .___
  360. // | | ______ ________ __ ____
  361. // | |/ ___// ___/ | \_/ __ \
  362. // | |\___ \ \___ \| | /\ ___/
  363. // |___/____ >____ >____/ \___ >
  364. // \/ \/ \/
  365. // CreateIssueForm form for creating issue
  366. type CreateIssueForm struct {
  367. Title string `binding:"Required;MaxSize(255)"`
  368. LabelIDs string `form:"label_ids"`
  369. AssigneeIDs string `form:"assignee_ids"`
  370. ReviewerIDs string `form:"reviewer_ids"`
  371. Ref string `form:"ref"`
  372. MilestoneID int64
  373. ProjectID int64
  374. Content string
  375. Files []string
  376. AllowMaintainerEdit bool
  377. }
  378. // Validate validates the fields
  379. func (f *CreateIssueForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  380. ctx := context.GetValidateContext(req)
  381. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  382. }
  383. // CreateCommentForm form for creating comment
  384. type CreateCommentForm struct {
  385. Content string
  386. Status string `binding:"OmitEmpty;In(reopen,close)"`
  387. Files []string
  388. }
  389. // Validate validates the fields
  390. func (f *CreateCommentForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  391. ctx := context.GetValidateContext(req)
  392. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  393. }
  394. // ReactionForm form for adding and removing reaction
  395. type ReactionForm struct {
  396. Content string `binding:"Required"`
  397. }
  398. // Validate validates the fields
  399. func (f *ReactionForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  400. ctx := context.GetValidateContext(req)
  401. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  402. }
  403. // IssueLockForm form for locking an issue
  404. type IssueLockForm struct {
  405. Reason string `binding:"Required"`
  406. }
  407. // Validate validates the fields
  408. func (i *IssueLockForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  409. ctx := context.GetValidateContext(req)
  410. return middleware.Validate(errs, ctx.Data, i, ctx.Locale)
  411. }
  412. // CreateProjectForm form for creating a project
  413. type CreateProjectForm struct {
  414. Title string `binding:"Required;MaxSize(100)"`
  415. Content string
  416. TemplateType project_model.TemplateType
  417. CardType project_model.CardType
  418. }
  419. // EditProjectColumnForm is a form for editing a project column
  420. type EditProjectColumnForm struct {
  421. Title string `binding:"Required;MaxSize(100)"`
  422. Sorting int8
  423. Color string `binding:"MaxSize(7)"`
  424. }
  425. // CreateMilestoneForm form for creating milestone
  426. type CreateMilestoneForm struct {
  427. Title string `binding:"Required;MaxSize(50)"`
  428. Content string
  429. Deadline string
  430. }
  431. // Validate validates the fields
  432. func (f *CreateMilestoneForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  433. ctx := context.GetValidateContext(req)
  434. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  435. }
  436. // CreateLabelForm form for creating label
  437. type CreateLabelForm struct {
  438. ID int64
  439. Title string `binding:"Required;MaxSize(50)" locale:"repo.issues.label_title"`
  440. Exclusive bool `form:"exclusive"`
  441. ExclusiveOrder int `form:"exclusive_order"`
  442. IsArchived bool `form:"is_archived"`
  443. Description string `binding:"MaxSize(200)" locale:"repo.issues.label_description"`
  444. Color string `binding:"Required;MaxSize(7)" locale:"repo.issues.label_color"`
  445. }
  446. // Validate validates the fields
  447. func (f *CreateLabelForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  448. ctx := context.GetValidateContext(req)
  449. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  450. }
  451. // InitializeLabelsForm form for initializing labels
  452. type InitializeLabelsForm struct {
  453. TemplateName string `binding:"Required"`
  454. }
  455. // Validate validates the fields
  456. func (f *InitializeLabelsForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  457. ctx := context.GetValidateContext(req)
  458. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  459. }
  460. // MergePullRequestForm form for merging Pull Request
  461. // swagger:model MergePullRequestOption
  462. type MergePullRequestForm struct {
  463. // required: true
  464. // enum: merge,rebase,rebase-merge,squash,fast-forward-only,manually-merged
  465. Do string `binding:"Required;In(merge,rebase,rebase-merge,squash,fast-forward-only,manually-merged)"`
  466. MergeTitleField string
  467. MergeMessageField string
  468. MergeCommitID string // only used for manually-merged
  469. HeadCommitID string `json:"head_commit_id,omitempty"`
  470. ForceMerge bool `json:"force_merge,omitempty"`
  471. MergeWhenChecksSucceed bool `json:"merge_when_checks_succeed,omitempty"`
  472. DeleteBranchAfterMerge bool `json:"delete_branch_after_merge,omitempty"`
  473. }
  474. // Validate validates the fields
  475. func (f *MergePullRequestForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  476. ctx := context.GetValidateContext(req)
  477. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  478. }
  479. // CodeCommentForm form for adding code comments for PRs
  480. type CodeCommentForm struct {
  481. Origin string `binding:"Required;In(timeline,diff)"`
  482. Content string `binding:"Required"`
  483. Side string `binding:"Required;In(previous,proposed)"`
  484. Line int64
  485. TreePath string `form:"path" binding:"Required"`
  486. SingleReview bool `form:"single_review"`
  487. Reply int64 `form:"reply"`
  488. LatestCommitID string
  489. Files []string
  490. }
  491. // Validate validates the fields
  492. func (f *CodeCommentForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  493. ctx := context.GetValidateContext(req)
  494. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  495. }
  496. // SubmitReviewForm for submitting a finished code review
  497. type SubmitReviewForm struct {
  498. Content string
  499. Type string
  500. CommitID string
  501. Files []string
  502. }
  503. // Validate validates the fields
  504. func (f *SubmitReviewForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  505. ctx := context.GetValidateContext(req)
  506. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  507. }
  508. // ReviewType will return the corresponding ReviewType for type
  509. func (f SubmitReviewForm) ReviewType() issues_model.ReviewType {
  510. switch f.Type {
  511. case "approve":
  512. return issues_model.ReviewTypeApprove
  513. case "comment":
  514. return issues_model.ReviewTypeComment
  515. case "reject":
  516. return issues_model.ReviewTypeReject
  517. case "":
  518. return issues_model.ReviewTypeComment // default to comment when doing quick-submit (Ctrl+Enter) on the review form
  519. default:
  520. return issues_model.ReviewTypeUnknown
  521. }
  522. }
  523. // HasEmptyContent checks if the content of the review form is empty.
  524. func (f SubmitReviewForm) HasEmptyContent() bool {
  525. reviewType := f.ReviewType()
  526. return (reviewType == issues_model.ReviewTypeComment || reviewType == issues_model.ReviewTypeReject) &&
  527. len(strings.TrimSpace(f.Content)) == 0
  528. }
  529. // DismissReviewForm for dismissing stale review by repo admin
  530. type DismissReviewForm struct {
  531. ReviewID int64 `binding:"Required"`
  532. Message string
  533. }
  534. // UpdateAllowEditsForm form for changing if PR allows edits from maintainers
  535. type UpdateAllowEditsForm struct {
  536. AllowMaintainerEdit bool
  537. }
  538. // __________ .__
  539. // \______ \ ____ | | ____ _____ ______ ____
  540. // | _// __ \| | _/ __ \\__ \ / ___// __ \
  541. // | | \ ___/| |_\ ___/ / __ \_\___ \\ ___/
  542. // |____|_ /\___ >____/\___ >____ /____ >\___ >
  543. // \/ \/ \/ \/ \/ \/
  544. // NewReleaseForm form for creating release
  545. type NewReleaseForm struct {
  546. TagName string `binding:"Required;GitRefName;MaxSize(255)"`
  547. Target string `form:"tag_target" binding:"Required;MaxSize(255)"`
  548. Title string `binding:"MaxSize(255)"`
  549. Content string
  550. Draft bool
  551. TagOnly bool
  552. Prerelease bool
  553. AddTagMsg bool
  554. Files []string
  555. }
  556. // Validate validates the fields
  557. func (f *NewReleaseForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  558. ctx := context.GetValidateContext(req)
  559. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  560. }
  561. // EditReleaseForm form for changing release
  562. type EditReleaseForm struct {
  563. Title string `form:"title" binding:"Required;MaxSize(255)"`
  564. Content string `form:"content"`
  565. Draft string `form:"draft"`
  566. Prerelease bool `form:"prerelease"`
  567. Files []string
  568. }
  569. // Validate validates the fields
  570. func (f *EditReleaseForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  571. ctx := context.GetValidateContext(req)
  572. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  573. }
  574. // __ __.__ __ .__
  575. // / \ / \__| | _|__|
  576. // \ \/\/ / | |/ / |
  577. // \ /| | <| |
  578. // \__/\ / |__|__|_ \__|
  579. // \/ \/
  580. // NewWikiForm form for creating wiki
  581. type NewWikiForm struct {
  582. Title string `binding:"Required"`
  583. Content string `binding:"Required"`
  584. Message string
  585. }
  586. // Validate validates the fields
  587. // FIXME: use code generation to generate this method.
  588. func (f *NewWikiForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  589. ctx := context.GetValidateContext(req)
  590. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  591. }
  592. // ___________.__ ___________ __
  593. // \__ ___/|__| _____ ____ \__ ___/___________ ____ | | __ ___________
  594. // | | | |/ \_/ __ \ | | \_ __ \__ \ _/ ___\| |/ // __ \_ __ \
  595. // | | | | Y Y \ ___/ | | | | \// __ \\ \___| <\ ___/| | \/
  596. // |____| |__|__|_| /\___ > |____| |__| (____ /\___ >__|_ \\___ >__|
  597. // \/ \/ \/ \/ \/ \/
  598. // AddTimeManuallyForm form that adds spent time manually.
  599. type AddTimeManuallyForm struct {
  600. Hours int `binding:"Range(0,1000)"`
  601. Minutes int `binding:"Range(0,1000)"`
  602. }
  603. // Validate validates the fields
  604. func (f *AddTimeManuallyForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  605. ctx := context.GetValidateContext(req)
  606. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  607. }
  608. // SaveTopicForm form for save topics for repository
  609. type SaveTopicForm struct {
  610. Topics []string `binding:"topics;Required;"`
  611. }
  612. // DeadlineForm hold the validation rules for deadlines
  613. type DeadlineForm struct {
  614. DateString string `form:"date" binding:"Required;Size(10)"`
  615. }
  616. // Validate validates the fields
  617. func (f *DeadlineForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  618. ctx := context.GetValidateContext(req)
  619. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  620. }