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

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