選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

repo.go 16KB

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