gitea源码

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package structs
  4. import (
  5. "strings"
  6. "time"
  7. )
  8. // Permission represents a set of permissions
  9. type Permission struct {
  10. Admin bool `json:"admin"` // Admin indicates if the user is an administrator of the repository.
  11. Push bool `json:"push"` // Push indicates if the user can push code to the repository.
  12. Pull bool `json:"pull"` // Pull indicates if the user can pull code from the repository.
  13. }
  14. // InternalTracker represents settings for internal tracker
  15. // swagger:model
  16. type InternalTracker struct {
  17. // Enable time tracking (Built-in issue tracker)
  18. EnableTimeTracker bool `json:"enable_time_tracker"`
  19. // Let only contributors track time (Built-in issue tracker)
  20. AllowOnlyContributorsToTrackTime bool `json:"allow_only_contributors_to_track_time"`
  21. // Enable dependencies for issues and pull requests (Built-in issue tracker)
  22. EnableIssueDependencies bool `json:"enable_issue_dependencies"`
  23. }
  24. // ExternalTracker represents settings for external tracker
  25. // swagger:model
  26. type ExternalTracker struct {
  27. // URL of external issue tracker.
  28. ExternalTrackerURL string `json:"external_tracker_url"`
  29. // External Issue Tracker URL Format. Use the placeholders {user}, {repo} and {index} for the username, repository name and issue index.
  30. ExternalTrackerFormat string `json:"external_tracker_format"`
  31. // External Issue Tracker Number Format, either `numeric`, `alphanumeric`, or `regexp`
  32. ExternalTrackerStyle string `json:"external_tracker_style"`
  33. // External Issue Tracker issue regular expression
  34. ExternalTrackerRegexpPattern string `json:"external_tracker_regexp_pattern"`
  35. }
  36. // ExternalWiki represents setting for external wiki
  37. // swagger:model
  38. type ExternalWiki struct {
  39. // URL of external wiki.
  40. ExternalWikiURL string `json:"external_wiki_url"`
  41. }
  42. // Repository represents a repository
  43. type Repository struct {
  44. ID int64 `json:"id"`
  45. Owner *User `json:"owner"`
  46. Name string `json:"name"`
  47. FullName string `json:"full_name"`
  48. Description string `json:"description"`
  49. Empty bool `json:"empty"`
  50. Private bool `json:"private"`
  51. Fork bool `json:"fork"`
  52. Template bool `json:"template"`
  53. // the original repository if this repository is a fork, otherwise null
  54. Parent *Repository `json:"parent,omitempty"`
  55. Mirror bool `json:"mirror"`
  56. Size int `json:"size"`
  57. Language string `json:"language"`
  58. LanguagesURL string `json:"languages_url"`
  59. HTMLURL string `json:"html_url"`
  60. URL string `json:"url"`
  61. Link string `json:"link"`
  62. SSHURL string `json:"ssh_url"`
  63. CloneURL string `json:"clone_url"`
  64. OriginalURL string `json:"original_url"`
  65. Website string `json:"website"`
  66. Stars int `json:"stars_count"`
  67. Forks int `json:"forks_count"`
  68. Watchers int `json:"watchers_count"`
  69. OpenIssues int `json:"open_issues_count"`
  70. OpenPulls int `json:"open_pr_counter"`
  71. Releases int `json:"release_counter"`
  72. DefaultBranch string `json:"default_branch"`
  73. Archived bool `json:"archived"`
  74. // swagger:strfmt date-time
  75. Created time.Time `json:"created_at"`
  76. // swagger:strfmt date-time
  77. Updated time.Time `json:"updated_at"`
  78. ArchivedAt time.Time `json:"archived_at"`
  79. Permissions *Permission `json:"permissions,omitempty"`
  80. HasCode bool `json:"has_code"`
  81. HasIssues bool `json:"has_issues"`
  82. InternalTracker *InternalTracker `json:"internal_tracker,omitempty"`
  83. ExternalTracker *ExternalTracker `json:"external_tracker,omitempty"`
  84. HasWiki bool `json:"has_wiki"`
  85. ExternalWiki *ExternalWiki `json:"external_wiki,omitempty"`
  86. HasPullRequests bool `json:"has_pull_requests"`
  87. HasProjects bool `json:"has_projects"`
  88. ProjectsMode string `json:"projects_mode"`
  89. HasReleases bool `json:"has_releases"`
  90. HasPackages bool `json:"has_packages"`
  91. HasActions bool `json:"has_actions"`
  92. IgnoreWhitespaceConflicts bool `json:"ignore_whitespace_conflicts"`
  93. AllowMerge bool `json:"allow_merge_commits"`
  94. AllowRebase bool `json:"allow_rebase"`
  95. AllowRebaseMerge bool `json:"allow_rebase_explicit"`
  96. AllowSquash bool `json:"allow_squash_merge"`
  97. AllowFastForwardOnly bool `json:"allow_fast_forward_only_merge"`
  98. AllowRebaseUpdate bool `json:"allow_rebase_update"`
  99. AllowManualMerge bool `json:"allow_manual_merge"`
  100. AutodetectManualMerge bool `json:"autodetect_manual_merge"`
  101. DefaultDeleteBranchAfterMerge bool `json:"default_delete_branch_after_merge"`
  102. DefaultMergeStyle string `json:"default_merge_style"`
  103. DefaultAllowMaintainerEdit bool `json:"default_allow_maintainer_edit"`
  104. AvatarURL string `json:"avatar_url"`
  105. Internal bool `json:"internal"`
  106. MirrorInterval string `json:"mirror_interval"`
  107. // ObjectFormatName of the underlying git repository
  108. // enum: sha1,sha256
  109. ObjectFormatName string `json:"object_format_name"`
  110. // swagger:strfmt date-time
  111. MirrorUpdated time.Time `json:"mirror_updated"`
  112. RepoTransfer *RepoTransfer `json:"repo_transfer,omitempty"`
  113. Topics []string `json:"topics"`
  114. Licenses []string `json:"licenses"`
  115. }
  116. // CreateRepoOption options when creating repository
  117. // swagger:model
  118. type CreateRepoOption struct {
  119. // Name of the repository to create
  120. //
  121. // required: true
  122. // unique: true
  123. Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(100)"`
  124. // Description of the repository to create
  125. Description string `json:"description" binding:"MaxSize(2048)"`
  126. // Whether the repository is private
  127. Private bool `json:"private"`
  128. // Label-Set to use
  129. IssueLabels string `json:"issue_labels"`
  130. // Whether the repository should be auto-initialized?
  131. AutoInit bool `json:"auto_init"`
  132. // Whether the repository is template
  133. Template bool `json:"template"`
  134. // Gitignores to use
  135. Gitignores string `json:"gitignores"`
  136. // License to use
  137. License string `json:"license"`
  138. // Readme of the repository to create
  139. Readme string `json:"readme"`
  140. // DefaultBranch of the repository (used when initializes and in template)
  141. DefaultBranch string `json:"default_branch" binding:"GitRefName;MaxSize(100)"`
  142. // TrustModel of the repository
  143. // enum: default,collaborator,committer,collaboratorcommitter
  144. TrustModel string `json:"trust_model"`
  145. // ObjectFormatName of the underlying git repository
  146. // enum: sha1,sha256
  147. ObjectFormatName string `json:"object_format_name" binding:"MaxSize(6)"`
  148. }
  149. // EditRepoOption options when editing a repository's properties
  150. // swagger:model
  151. type EditRepoOption struct {
  152. // name of the repository
  153. // unique: true
  154. Name *string `json:"name,omitempty" binding:"OmitEmpty;AlphaDashDot;MaxSize(100);"`
  155. // a short description of the repository.
  156. Description *string `json:"description,omitempty" binding:"MaxSize(2048)"`
  157. // a URL with more information about the repository.
  158. Website *string `json:"website,omitempty" binding:"MaxSize(1024)"`
  159. // either `true` to make the repository private or `false` to make it public.
  160. // Note: you will get a 422 error if the organization restricts changing repository visibility to organization
  161. // owners and a non-owner tries to change the value of private.
  162. Private *bool `json:"private,omitempty"`
  163. // either `true` to make this repository a template or `false` to make it a normal repository
  164. Template *bool `json:"template,omitempty"`
  165. // either `true` to enable code for this repository or `false` to disable it.
  166. HasCode *bool `json:"has_code,omitempty"`
  167. // either `true` to enable issues for this repository or `false` to disable them.
  168. HasIssues *bool `json:"has_issues,omitempty"`
  169. // set this structure to configure internal issue tracker
  170. InternalTracker *InternalTracker `json:"internal_tracker,omitempty"`
  171. // set this structure to use external issue tracker
  172. ExternalTracker *ExternalTracker `json:"external_tracker,omitempty"`
  173. // either `true` to enable the wiki for this repository or `false` to disable it.
  174. HasWiki *bool `json:"has_wiki,omitempty"`
  175. // set this structure to use external wiki instead of internal
  176. ExternalWiki *ExternalWiki `json:"external_wiki,omitempty"`
  177. // sets the default branch for this repository.
  178. DefaultBranch *string `json:"default_branch,omitempty"`
  179. // either `true` to allow pull requests, or `false` to prevent pull request.
  180. HasPullRequests *bool `json:"has_pull_requests,omitempty"`
  181. // either `true` to enable project unit, or `false` to disable them.
  182. HasProjects *bool `json:"has_projects,omitempty"`
  183. // `repo` to only allow repo-level projects, `owner` to only allow owner projects, `all` to allow both.
  184. ProjectsMode *string `json:"projects_mode,omitempty" binding:"In(repo,owner,all)"`
  185. // either `true` to enable releases unit, or `false` to disable them.
  186. HasReleases *bool `json:"has_releases,omitempty"`
  187. // either `true` to enable packages unit, or `false` to disable them.
  188. HasPackages *bool `json:"has_packages,omitempty"`
  189. // either `true` to enable actions unit, or `false` to disable them.
  190. HasActions *bool `json:"has_actions,omitempty"`
  191. // either `true` to ignore whitespace for conflicts, or `false` to not ignore whitespace.
  192. IgnoreWhitespaceConflicts *bool `json:"ignore_whitespace_conflicts,omitempty"`
  193. // either `true` to allow merging pull requests with a merge commit, or `false` to prevent merging pull requests with merge commits.
  194. AllowMerge *bool `json:"allow_merge_commits,omitempty"`
  195. // either `true` to allow rebase-merging pull requests, or `false` to prevent rebase-merging.
  196. AllowRebase *bool `json:"allow_rebase,omitempty"`
  197. // either `true` to allow rebase with explicit merge commits (--no-ff), or `false` to prevent rebase with explicit merge commits.
  198. AllowRebaseMerge *bool `json:"allow_rebase_explicit,omitempty"`
  199. // either `true` to allow squash-merging pull requests, or `false` to prevent squash-merging.
  200. AllowSquash *bool `json:"allow_squash_merge,omitempty"`
  201. // either `true` to allow fast-forward-only merging pull requests, or `false` to prevent fast-forward-only merging.
  202. AllowFastForwardOnly *bool `json:"allow_fast_forward_only_merge,omitempty"`
  203. // either `true` to allow mark pr as merged manually, or `false` to prevent it.
  204. AllowManualMerge *bool `json:"allow_manual_merge,omitempty"`
  205. // either `true` to enable AutodetectManualMerge, or `false` to prevent it. Note: In some special cases, misjudgments can occur.
  206. AutodetectManualMerge *bool `json:"autodetect_manual_merge,omitempty"`
  207. // either `true` to allow updating pull request branch by rebase, or `false` to prevent it.
  208. AllowRebaseUpdate *bool `json:"allow_rebase_update,omitempty"`
  209. // set to `true` to delete pr branch after merge by default
  210. DefaultDeleteBranchAfterMerge *bool `json:"default_delete_branch_after_merge,omitempty"`
  211. // set to a merge style to be used by this repository: "merge", "rebase", "rebase-merge", "squash", or "fast-forward-only".
  212. DefaultMergeStyle *string `json:"default_merge_style,omitempty"`
  213. // set to `true` to allow edits from maintainers by default
  214. DefaultAllowMaintainerEdit *bool `json:"default_allow_maintainer_edit,omitempty"`
  215. // set to `true` to archive this repository.
  216. Archived *bool `json:"archived,omitempty"`
  217. // set to a string like `8h30m0s` to set the mirror interval time
  218. MirrorInterval *string `json:"mirror_interval,omitempty"`
  219. // enable prune - remove obsolete remote-tracking references when mirroring
  220. EnablePrune *bool `json:"enable_prune,omitempty"`
  221. }
  222. // GenerateRepoOption options when creating a repository using a template
  223. // swagger:model
  224. type GenerateRepoOption struct {
  225. // the organization's name or individual user's name who will own the new repository
  226. //
  227. // required: true
  228. Owner string `json:"owner"`
  229. // required: true
  230. // unique: true
  231. Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(100)"`
  232. // Default branch of the new repository
  233. DefaultBranch string `json:"default_branch"`
  234. // Description of the repository to create
  235. Description string `json:"description" binding:"MaxSize(2048)"`
  236. // Whether the repository is private
  237. Private bool `json:"private"`
  238. // include git content of default branch in template repo
  239. GitContent bool `json:"git_content"`
  240. // include topics in template repo
  241. Topics bool `json:"topics"`
  242. // include git hooks in template repo
  243. GitHooks bool `json:"git_hooks"`
  244. // include webhooks in template repo
  245. Webhooks bool `json:"webhooks"`
  246. // include avatar of the template repo
  247. Avatar bool `json:"avatar"`
  248. // include labels in template repo
  249. Labels bool `json:"labels"`
  250. // include protected branches in template repo
  251. ProtectedBranch bool `json:"protected_branch"`
  252. }
  253. // CreateBranchRepoOption options when creating a branch in a repository
  254. // swagger:model
  255. type CreateBranchRepoOption struct {
  256. // Name of the branch to create
  257. //
  258. // required: true
  259. // unique: true
  260. BranchName string `json:"new_branch_name" binding:"Required;GitRefName;MaxSize(100)"`
  261. // Deprecated: true
  262. // Name of the old branch to create from
  263. //
  264. // unique: true
  265. OldBranchName string `json:"old_branch_name" binding:"GitRefName;MaxSize(100)"`
  266. // Name of the old branch/tag/commit to create from
  267. //
  268. // unique: true
  269. OldRefName string `json:"old_ref_name" binding:"GitRefName;MaxSize(100)"`
  270. }
  271. // RenameBranchRepoOption options when renaming a branch in a repository
  272. // swagger:model
  273. type RenameBranchRepoOption struct {
  274. // New branch name
  275. //
  276. // required: true
  277. // unique: true
  278. Name string `json:"name" binding:"Required;GitRefName;MaxSize(100)"`
  279. }
  280. // TransferRepoOption options when transfer a repository's ownership
  281. // swagger:model
  282. type TransferRepoOption struct {
  283. // required: true
  284. NewOwner string `json:"new_owner"`
  285. // ID of the team or teams to add to the repository. Teams can only be added to organization-owned repositories.
  286. TeamIDs *[]int64 `json:"team_ids"`
  287. }
  288. // GitServiceType represents a git service
  289. type GitServiceType int
  290. // enumerate all GitServiceType
  291. const (
  292. NotMigrated GitServiceType = iota // 0 not migrated from external sites
  293. PlainGitService // 1 plain git service
  294. GithubService // 2 github.com
  295. GiteaService // 3 gitea service
  296. GitlabService // 4 gitlab service
  297. GogsService // 5 gogs service
  298. OneDevService // 6 onedev service
  299. GitBucketService // 7 gitbucket service
  300. CodebaseService // 8 codebase service
  301. CodeCommitService // 9 codecommit service
  302. )
  303. // Name represents the service type's name
  304. // WARNING: the name has to be equal to that on goth's library
  305. func (gt GitServiceType) Name() string {
  306. return strings.ToLower(gt.Title())
  307. }
  308. // Title represents the service type's proper title
  309. func (gt GitServiceType) Title() string {
  310. switch gt {
  311. case GithubService:
  312. return "GitHub"
  313. case GiteaService:
  314. return "Gitea"
  315. case GitlabService:
  316. return "GitLab"
  317. case GogsService:
  318. return "Gogs"
  319. case OneDevService:
  320. return "OneDev"
  321. case GitBucketService:
  322. return "GitBucket"
  323. case CodebaseService:
  324. return "Codebase"
  325. case CodeCommitService:
  326. return "CodeCommit"
  327. case PlainGitService:
  328. return "Git"
  329. }
  330. return ""
  331. }
  332. // MigrateRepoOptions options for migrating repository's
  333. // this is used to interact with api v1
  334. type MigrateRepoOptions struct {
  335. // required: true
  336. CloneAddr string `json:"clone_addr" binding:"Required"`
  337. // deprecated (only for backwards compatibility, use repo_owner instead)
  338. RepoOwnerID int64 `json:"uid"`
  339. // the organization's name or individual user's name who will own the migrated repository
  340. RepoOwner string `json:"repo_owner"`
  341. // required: true
  342. RepoName string `json:"repo_name" binding:"Required;AlphaDashDot;MaxSize(100)"`
  343. // enum: git,github,gitea,gitlab,gogs,onedev,gitbucket,codebase,codecommit
  344. Service string `json:"service"`
  345. AuthUsername string `json:"auth_username"`
  346. AuthPassword string `json:"auth_password"`
  347. AuthToken string `json:"auth_token"`
  348. Mirror bool `json:"mirror"`
  349. LFS bool `json:"lfs"`
  350. LFSEndpoint string `json:"lfs_endpoint"`
  351. Private bool `json:"private"`
  352. Description string `json:"description" binding:"MaxSize(2048)"`
  353. Wiki bool `json:"wiki"`
  354. Milestones bool `json:"milestones"`
  355. Labels bool `json:"labels"`
  356. Issues bool `json:"issues"`
  357. PullRequests bool `json:"pull_requests"`
  358. Releases bool `json:"releases"`
  359. MirrorInterval string `json:"mirror_interval"`
  360. AWSAccessKeyID string `json:"aws_access_key_id"`
  361. AWSSecretAccessKey string `json:"aws_secret_access_key"`
  362. }
  363. // TokenAuth represents whether a service type supports token-based auth
  364. func (gt GitServiceType) TokenAuth() bool {
  365. switch gt {
  366. case GithubService, GiteaService, GitlabService:
  367. return true
  368. }
  369. return false
  370. }
  371. // SupportedFullGitService represents all git services supported to migrate issues/labels/prs and etc.
  372. // TODO: add to this list after new git service added
  373. var SupportedFullGitService = []GitServiceType{
  374. GithubService,
  375. GitlabService,
  376. GiteaService,
  377. GogsService,
  378. OneDevService,
  379. GitBucketService,
  380. CodebaseService,
  381. CodeCommitService,
  382. }
  383. // RepoTransfer represents a pending repo transfer
  384. type RepoTransfer struct {
  385. Doer *User `json:"doer"`
  386. Recipient *User `json:"recipient"`
  387. Teams []*Team `json:"teams"`
  388. }
  389. // NewIssuePinsAllowed represents an API response that says if new Issue Pins are allowed
  390. type NewIssuePinsAllowed struct {
  391. Issues bool `json:"issues"`
  392. PullRequests bool `json:"pull_requests"`
  393. }
  394. // UpdateRepoAvatarUserOption options when updating the repo avatar
  395. type UpdateRepoAvatarOption struct {
  396. // image must be base64 encoded
  397. Image string `json:"image" binding:"Required"`
  398. }