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

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