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.

repository.go 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. // Copyright 2019 The Gitea 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 setting
  5. import (
  6. "path"
  7. "path/filepath"
  8. "strings"
  9. "code.gitea.io/gitea/modules/log"
  10. "github.com/unknwon/com"
  11. )
  12. // enumerates all the policy repository creating
  13. const (
  14. RepoCreatingLastUserVisibility = "last"
  15. RepoCreatingPrivate = "private"
  16. RepoCreatingPublic = "public"
  17. )
  18. // Repository settings
  19. var (
  20. Repository = struct {
  21. AnsiCharset string
  22. ForcePrivate bool
  23. DefaultPrivate string
  24. MaxCreationLimit int
  25. MirrorQueueLength int
  26. PullRequestQueueLength int
  27. PreferredLicenses []string
  28. DisableHTTPGit bool
  29. AccessControlAllowOrigin string
  30. UseCompatSSHURI bool
  31. DefaultCloseIssuesViaCommitsInAnyBranch bool
  32. EnablePushCreateUser bool
  33. EnablePushCreateOrg bool
  34. DisabledRepoUnits []string
  35. DefaultRepoUnits []string
  36. PrefixArchiveFiles bool
  37. DefaultBranch string
  38. // Repository editor settings
  39. Editor struct {
  40. LineWrapExtensions []string
  41. PreviewableFileModes []string
  42. } `ini:"-"`
  43. // Repository upload settings
  44. Upload struct {
  45. Enabled bool
  46. TempPath string
  47. AllowedTypes []string `delim:"|"`
  48. FileMaxSize int64
  49. MaxFiles int
  50. } `ini:"-"`
  51. // Repository local settings
  52. Local struct {
  53. LocalCopyPath string
  54. } `ini:"-"`
  55. // Pull request settings
  56. PullRequest struct {
  57. WorkInProgressPrefixes []string
  58. CloseKeywords []string
  59. ReopenKeywords []string
  60. DefaultMergeMessageCommitsLimit int
  61. DefaultMergeMessageSize int
  62. DefaultMergeMessageAllAuthors bool
  63. DefaultMergeMessageMaxApprovers int
  64. DefaultMergeMessageOfficialApproversOnly bool
  65. } `ini:"repository.pull-request"`
  66. // Issue Setting
  67. Issue struct {
  68. LockReasons []string
  69. } `ini:"repository.issue"`
  70. Signing struct {
  71. SigningKey string
  72. SigningName string
  73. SigningEmail string
  74. InitialCommit []string
  75. CRUDActions []string `ini:"CRUD_ACTIONS"`
  76. Merges []string
  77. Wiki []string
  78. } `ini:"repository.signing"`
  79. }{
  80. AnsiCharset: "",
  81. ForcePrivate: false,
  82. DefaultPrivate: RepoCreatingLastUserVisibility,
  83. MaxCreationLimit: -1,
  84. MirrorQueueLength: 1000,
  85. PullRequestQueueLength: 1000,
  86. PreferredLicenses: []string{"Apache License 2.0,MIT License"},
  87. DisableHTTPGit: false,
  88. AccessControlAllowOrigin: "",
  89. UseCompatSSHURI: false,
  90. DefaultCloseIssuesViaCommitsInAnyBranch: false,
  91. EnablePushCreateUser: false,
  92. EnablePushCreateOrg: false,
  93. DisabledRepoUnits: []string{},
  94. DefaultRepoUnits: []string{},
  95. PrefixArchiveFiles: true,
  96. // Repository editor settings
  97. Editor: struct {
  98. LineWrapExtensions []string
  99. PreviewableFileModes []string
  100. }{
  101. LineWrapExtensions: strings.Split(".txt,.md,.markdown,.mdown,.mkd,", ","),
  102. PreviewableFileModes: []string{"markdown"},
  103. },
  104. // Repository upload settings
  105. Upload: struct {
  106. Enabled bool
  107. TempPath string
  108. AllowedTypes []string `delim:"|"`
  109. FileMaxSize int64
  110. MaxFiles int
  111. }{
  112. Enabled: true,
  113. TempPath: "data/tmp/uploads",
  114. AllowedTypes: []string{},
  115. FileMaxSize: 3,
  116. MaxFiles: 5,
  117. },
  118. // Repository local settings
  119. Local: struct {
  120. LocalCopyPath string
  121. }{
  122. LocalCopyPath: "tmp/local-repo",
  123. },
  124. // Pull request settings
  125. PullRequest: struct {
  126. WorkInProgressPrefixes []string
  127. CloseKeywords []string
  128. ReopenKeywords []string
  129. DefaultMergeMessageCommitsLimit int
  130. DefaultMergeMessageSize int
  131. DefaultMergeMessageAllAuthors bool
  132. DefaultMergeMessageMaxApprovers int
  133. DefaultMergeMessageOfficialApproversOnly bool
  134. }{
  135. WorkInProgressPrefixes: []string{"WIP:", "[WIP]"},
  136. // Same as GitHub. See
  137. // https://help.github.com/articles/closing-issues-via-commit-messages
  138. CloseKeywords: strings.Split("close,closes,closed,fix,fixes,fixed,resolve,resolves,resolved", ","),
  139. ReopenKeywords: strings.Split("reopen,reopens,reopened", ","),
  140. DefaultMergeMessageCommitsLimit: 50,
  141. DefaultMergeMessageSize: 5 * 1024,
  142. DefaultMergeMessageAllAuthors: false,
  143. DefaultMergeMessageMaxApprovers: 10,
  144. DefaultMergeMessageOfficialApproversOnly: true,
  145. },
  146. // Issue settings
  147. Issue: struct {
  148. LockReasons []string
  149. }{
  150. LockReasons: strings.Split("Too heated,Off-topic,Spam,Resolved", ","),
  151. },
  152. // Signing settings
  153. Signing: struct {
  154. SigningKey string
  155. SigningName string
  156. SigningEmail string
  157. InitialCommit []string
  158. CRUDActions []string `ini:"CRUD_ACTIONS"`
  159. Merges []string
  160. Wiki []string
  161. }{
  162. SigningKey: "default",
  163. SigningName: "",
  164. SigningEmail: "",
  165. InitialCommit: []string{"always"},
  166. CRUDActions: []string{"pubkey", "twofa", "parentsigned"},
  167. Merges: []string{"pubkey", "twofa", "basesigned", "commitssigned"},
  168. Wiki: []string{"never"},
  169. },
  170. }
  171. RepoRootPath string
  172. ScriptType = "bash"
  173. )
  174. func newRepository() {
  175. homeDir, err := com.HomeDir()
  176. if err != nil {
  177. log.Fatal("Failed to get home directory: %v", err)
  178. }
  179. homeDir = strings.Replace(homeDir, "\\", "/", -1)
  180. // Determine and create root git repository path.
  181. sec := Cfg.Section("repository")
  182. Repository.DisableHTTPGit = sec.Key("DISABLE_HTTP_GIT").MustBool()
  183. Repository.UseCompatSSHURI = sec.Key("USE_COMPAT_SSH_URI").MustBool()
  184. Repository.MaxCreationLimit = sec.Key("MAX_CREATION_LIMIT").MustInt(-1)
  185. Repository.DefaultBranch = sec.Key("DEFAULT_BRANCH").MustString("master")
  186. RepoRootPath = sec.Key("ROOT").MustString(path.Join(homeDir, "gitea-repositories"))
  187. forcePathSeparator(RepoRootPath)
  188. if !filepath.IsAbs(RepoRootPath) {
  189. RepoRootPath = filepath.Join(AppWorkPath, RepoRootPath)
  190. } else {
  191. RepoRootPath = filepath.Clean(RepoRootPath)
  192. }
  193. ScriptType = sec.Key("SCRIPT_TYPE").MustString("bash")
  194. if err = Cfg.Section("repository").MapTo(&Repository); err != nil {
  195. log.Fatal("Failed to map Repository settings: %v", err)
  196. } else if err = Cfg.Section("repository.editor").MapTo(&Repository.Editor); err != nil {
  197. log.Fatal("Failed to map Repository.Editor settings: %v", err)
  198. } else if err = Cfg.Section("repository.upload").MapTo(&Repository.Upload); err != nil {
  199. log.Fatal("Failed to map Repository.Upload settings: %v", err)
  200. } else if err = Cfg.Section("repository.local").MapTo(&Repository.Local); err != nil {
  201. log.Fatal("Failed to map Repository.Local settings: %v", err)
  202. } else if err = Cfg.Section("repository.pull-request").MapTo(&Repository.PullRequest); err != nil {
  203. log.Fatal("Failed to map Repository.PullRequest settings: %v", err)
  204. }
  205. if !filepath.IsAbs(Repository.Upload.TempPath) {
  206. Repository.Upload.TempPath = path.Join(AppWorkPath, Repository.Upload.TempPath)
  207. }
  208. }