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.go 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package structs
  5. import (
  6. "strings"
  7. "time"
  8. )
  9. // Permission represents a set of permissions
  10. type Permission struct {
  11. Admin bool `json:"admin"`
  12. Push bool `json:"push"`
  13. Pull bool `json:"pull"`
  14. }
  15. // InternalTracker represents settings for internal tracker
  16. // swagger:model
  17. type InternalTracker struct {
  18. // Enable time tracking (Built-in issue tracker)
  19. EnableTimeTracker bool `json:"enable_time_tracker"`
  20. // Let only contributors track time (Built-in issue tracker)
  21. AllowOnlyContributorsToTrackTime bool `json:"allow_only_contributors_to_track_time"`
  22. // Enable dependencies for issues and pull requests (Built-in issue tracker)
  23. EnableIssueDependencies bool `json:"enable_issue_dependencies"`
  24. }
  25. // ExternalTracker represents settings for external tracker
  26. // swagger:model
  27. type ExternalTracker struct {
  28. // URL of external issue tracker.
  29. ExternalTrackerURL string `json:"external_tracker_url"`
  30. // External Issue Tracker URL Format. Use the placeholders {user}, {repo} and {index} for the username, repository name and issue index.
  31. ExternalTrackerFormat string `json:"external_tracker_format"`
  32. // External Issue Tracker Number Format, either `numeric` or `alphanumeric`
  33. ExternalTrackerStyle string `json:"external_tracker_style"`
  34. }
  35. // ExternalWiki represents setting for external wiki
  36. // swagger:model
  37. type ExternalWiki struct {
  38. // URL of external wiki.
  39. ExternalWikiURL string `json:"external_wiki_url"`
  40. }
  41. // Repository represents a repository
  42. type Repository struct {
  43. ID int64 `json:"id"`
  44. Owner *User `json:"owner"`
  45. Name string `json:"name"`
  46. FullName string `json:"full_name"`
  47. Description string `json:"description"`
  48. Empty bool `json:"empty"`
  49. Private bool `json:"private"`
  50. Fork bool `json:"fork"`
  51. Template bool `json:"template"`
  52. Parent *Repository `json:"parent"`
  53. Mirror bool `json:"mirror"`
  54. Size int `json:"size"`
  55. HTMLURL string `json:"html_url"`
  56. SSHURL string `json:"ssh_url"`
  57. CloneURL string `json:"clone_url"`
  58. OriginalURL string `json:"original_url"`
  59. Website string `json:"website"`
  60. Stars int `json:"stars_count"`
  61. Forks int `json:"forks_count"`
  62. Watchers int `json:"watchers_count"`
  63. OpenIssues int `json:"open_issues_count"`
  64. OpenPulls int `json:"open_pr_counter"`
  65. Releases int `json:"release_counter"`
  66. DefaultBranch string `json:"default_branch"`
  67. Archived bool `json:"archived"`
  68. // swagger:strfmt date-time
  69. Created time.Time `json:"created_at"`
  70. // swagger:strfmt date-time
  71. Updated time.Time `json:"updated_at"`
  72. Permissions *Permission `json:"permissions,omitempty"`
  73. HasIssues bool `json:"has_issues"`
  74. InternalTracker *InternalTracker `json:"internal_tracker,omitempty"`
  75. ExternalTracker *ExternalTracker `json:"external_tracker,omitempty"`
  76. HasWiki bool `json:"has_wiki"`
  77. ExternalWiki *ExternalWiki `json:"external_wiki,omitempty"`
  78. HasPullRequests bool `json:"has_pull_requests"`
  79. HasProjects bool `json:"has_projects"`
  80. IgnoreWhitespaceConflicts bool `json:"ignore_whitespace_conflicts"`
  81. AllowMerge bool `json:"allow_merge_commits"`
  82. AllowRebase bool `json:"allow_rebase"`
  83. AllowRebaseMerge bool `json:"allow_rebase_explicit"`
  84. AllowSquash bool `json:"allow_squash_merge"`
  85. DefaultMergeStyle string `json:"default_merge_style"`
  86. AvatarURL string `json:"avatar_url"`
  87. Internal bool `json:"internal"`
  88. MirrorInterval string `json:"mirror_interval"`
  89. }
  90. // CreateRepoOption options when creating repository
  91. // swagger:model
  92. type CreateRepoOption struct {
  93. // Name of the repository to create
  94. //
  95. // required: true
  96. // unique: true
  97. Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(100)"`
  98. // Description of the repository to create
  99. Description string `json:"description" binding:"MaxSize(255)"`
  100. // Whether the repository is private
  101. Private bool `json:"private"`
  102. // Label-Set to use
  103. IssueLabels string `json:"issue_labels"`
  104. // Whether the repository should be auto-intialized?
  105. AutoInit bool `json:"auto_init"`
  106. // Whether the repository is template
  107. Template bool `json:"template"`
  108. // Gitignores to use
  109. Gitignores string `json:"gitignores"`
  110. // License to use
  111. License string `json:"license"`
  112. // Readme of the repository to create
  113. Readme string `json:"readme"`
  114. // DefaultBranch of the repository (used when initializes and in template)
  115. DefaultBranch string `json:"default_branch" binding:"GitRefName;MaxSize(100)"`
  116. // TrustModel of the repository
  117. // enum: default,collaborator,committer,collaboratorcommitter
  118. TrustModel string `json:"trust_model"`
  119. }
  120. // EditRepoOption options when editing a repository's properties
  121. // swagger:model
  122. type EditRepoOption struct {
  123. // name of the repository
  124. // unique: true
  125. Name *string `json:"name,omitempty" binding:"OmitEmpty;AlphaDashDot;MaxSize(100);"`
  126. // a short description of the repository.
  127. Description *string `json:"description,omitempty" binding:"MaxSize(255)"`
  128. // a URL with more information about the repository.
  129. Website *string `json:"website,omitempty" binding:"MaxSize(255)"`
  130. // either `true` to make the repository private or `false` to make it public.
  131. // Note: you will get a 422 error if the organization restricts changing repository visibility to organization
  132. // owners and a non-owner tries to change the value of private.
  133. Private *bool `json:"private,omitempty"`
  134. // either `true` to make this repository a template or `false` to make it a normal repository
  135. Template *bool `json:"template,omitempty"`
  136. // either `true` to enable issues for this repository or `false` to disable them.
  137. HasIssues *bool `json:"has_issues,omitempty"`
  138. // set this structure to configure internal issue tracker (requires has_issues)
  139. InternalTracker *InternalTracker `json:"internal_tracker,omitempty"`
  140. // set this structure to use external issue tracker (requires has_issues)
  141. ExternalTracker *ExternalTracker `json:"external_tracker,omitempty"`
  142. // either `true` to enable the wiki for this repository or `false` to disable it.
  143. HasWiki *bool `json:"has_wiki,omitempty"`
  144. // set this structure to use external wiki instead of internal (requires has_wiki)
  145. ExternalWiki *ExternalWiki `json:"external_wiki,omitempty"`
  146. // sets the default branch for this repository.
  147. DefaultBranch *string `json:"default_branch,omitempty"`
  148. // either `true` to allow pull requests, or `false` to prevent pull request.
  149. HasPullRequests *bool `json:"has_pull_requests,omitempty"`
  150. // either `true` to enable project unit, or `false` to disable them.
  151. HasProjects *bool `json:"has_projects,omitempty"`
  152. // either `true` to ignore whitespace for conflicts, or `false` to not ignore whitespace. `has_pull_requests` must be `true`.
  153. IgnoreWhitespaceConflicts *bool `json:"ignore_whitespace_conflicts,omitempty"`
  154. // either `true` to allow merging pull requests with a merge commit, or `false` to prevent merging pull requests with merge commits. `has_pull_requests` must be `true`.
  155. AllowMerge *bool `json:"allow_merge_commits,omitempty"`
  156. // either `true` to allow rebase-merging pull requests, or `false` to prevent rebase-merging. `has_pull_requests` must be `true`.
  157. AllowRebase *bool `json:"allow_rebase,omitempty"`
  158. // either `true` to allow rebase with explicit merge commits (--no-ff), or `false` to prevent rebase with explicit merge commits. `has_pull_requests` must be `true`.
  159. AllowRebaseMerge *bool `json:"allow_rebase_explicit,omitempty"`
  160. // either `true` to allow squash-merging pull requests, or `false` to prevent squash-merging. `has_pull_requests` must be `true`.
  161. AllowSquash *bool `json:"allow_squash_merge,omitempty"`
  162. // either `true` to allow mark pr as merged manually, or `false` to prevent it. `has_pull_requests` must be `true`.
  163. AllowManualMerge *bool `json:"allow_manual_merge,omitempty"`
  164. // either `true` to enable AutodetectManualMerge, or `false` to prevent it. `has_pull_requests` must be `true`, Note: In some special cases, misjudgments can occur.
  165. AutodetectManualMerge *bool `json:"autodetect_manual_merge,omitempty"`
  166. // set to `true` to delete pr branch after merge by default
  167. DefaultDeleteBranchAfterMerge *bool `json:"default_delete_branch_after_merge,omitempty"`
  168. // set to a merge style to be used by this repository: "merge", "rebase", "rebase-merge", or "squash". `has_pull_requests` must be `true`.
  169. DefaultMergeStyle *string `json:"default_merge_style,omitempty"`
  170. // set to `true` to archive this repository.
  171. Archived *bool `json:"archived,omitempty"`
  172. // set to a string like `8h30m0s` to set the mirror interval time
  173. MirrorInterval *string `json:"mirror_interval,omitempty"`
  174. }
  175. // GenerateRepoOption options when creating repository using a template
  176. // swagger:model
  177. type GenerateRepoOption struct {
  178. // The organization or person who will own the new repository
  179. //
  180. // required: true
  181. Owner string `json:"owner"`
  182. // Name of the repository to create
  183. //
  184. // required: true
  185. // unique: true
  186. Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(100)"`
  187. // Description of the repository to create
  188. Description string `json:"description" binding:"MaxSize(255)"`
  189. // Whether the repository is private
  190. Private bool `json:"private"`
  191. // include git content of default branch in template repo
  192. GitContent bool `json:"git_content"`
  193. // include topics in template repo
  194. Topics bool `json:"topics"`
  195. // include git hooks in template repo
  196. GitHooks bool `json:"git_hooks"`
  197. // include webhooks in template repo
  198. Webhooks bool `json:"webhooks"`
  199. // include avatar of the template repo
  200. Avatar bool `json:"avatar"`
  201. // include labels in template repo
  202. Labels bool `json:"labels"`
  203. }
  204. // CreateBranchRepoOption options when creating a branch in a repository
  205. // swagger:model
  206. type CreateBranchRepoOption struct {
  207. // Name of the branch to create
  208. //
  209. // required: true
  210. // unique: true
  211. BranchName string `json:"new_branch_name" binding:"Required;GitRefName;MaxSize(100)"`
  212. // Name of the old branch to create from
  213. //
  214. // unique: true
  215. OldBranchName string `json:"old_branch_name" binding:"GitRefName;MaxSize(100)"`
  216. }
  217. // TransferRepoOption options when transfer a repository's ownership
  218. // swagger:model
  219. type TransferRepoOption struct {
  220. // required: true
  221. NewOwner string `json:"new_owner"`
  222. // ID of the team or teams to add to the repository. Teams can only be added to organization-owned repositories.
  223. TeamIDs *[]int64 `json:"team_ids"`
  224. }
  225. // GitServiceType represents a git service
  226. type GitServiceType int
  227. // enumerate all GitServiceType
  228. const (
  229. NotMigrated GitServiceType = iota // 0 not migrated from external sites
  230. PlainGitService // 1 plain git service
  231. GithubService // 2 github.com
  232. GiteaService // 3 gitea service
  233. GitlabService // 4 gitlab service
  234. GogsService // 5 gogs service
  235. )
  236. // Name represents the service type's name
  237. // WARNNING: the name have to be equal to that on goth's library
  238. func (gt GitServiceType) Name() string {
  239. return strings.ToLower(gt.Title())
  240. }
  241. // Title represents the service type's proper title
  242. func (gt GitServiceType) Title() string {
  243. switch gt {
  244. case GithubService:
  245. return "GitHub"
  246. case GiteaService:
  247. return "Gitea"
  248. case GitlabService:
  249. return "GitLab"
  250. case GogsService:
  251. return "Gogs"
  252. case PlainGitService:
  253. return "Git"
  254. }
  255. return ""
  256. }
  257. // MigrateRepoOptions options for migrating repository's
  258. // this is used to interact with api v1
  259. type MigrateRepoOptions struct {
  260. // required: true
  261. CloneAddr string `json:"clone_addr" binding:"Required"`
  262. // deprecated (only for backwards compatibility)
  263. RepoOwnerID int64 `json:"uid"`
  264. // Name of User or Organisation who will own Repo after migration
  265. RepoOwner string `json:"repo_owner"`
  266. // required: true
  267. RepoName string `json:"repo_name" binding:"Required;AlphaDashDot;MaxSize(100)"`
  268. // enum: git,github,gitea,gitlab
  269. Service string `json:"service"`
  270. AuthUsername string `json:"auth_username"`
  271. AuthPassword string `json:"auth_password"`
  272. AuthToken string `json:"auth_token"`
  273. Mirror bool `json:"mirror"`
  274. LFS bool `json:"lfs"`
  275. LFSEndpoint string `json:"lfs_endpoint"`
  276. Private bool `json:"private"`
  277. Description string `json:"description" binding:"MaxSize(255)"`
  278. Wiki bool `json:"wiki"`
  279. Milestones bool `json:"milestones"`
  280. Labels bool `json:"labels"`
  281. Issues bool `json:"issues"`
  282. PullRequests bool `json:"pull_requests"`
  283. Releases bool `json:"releases"`
  284. MirrorInterval string `json:"mirror_interval"`
  285. }
  286. // TokenAuth represents whether a service type supports token-based auth
  287. func (gt GitServiceType) TokenAuth() bool {
  288. switch gt {
  289. case GithubService, GiteaService, GitlabService:
  290. return true
  291. }
  292. return false
  293. }
  294. var (
  295. // SupportedFullGitService represents all git services supported to migrate issues/labels/prs and etc.
  296. // TODO: add to this list after new git service added
  297. SupportedFullGitService = []GitServiceType{
  298. GithubService,
  299. GitlabService,
  300. GiteaService,
  301. GogsService,
  302. }
  303. )