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

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