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

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