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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. // Repository editor settings
  33. Editor struct {
  34. LineWrapExtensions []string
  35. PreviewableFileModes []string
  36. } `ini:"-"`
  37. // Repository upload settings
  38. Upload struct {
  39. Enabled bool
  40. TempPath string
  41. AllowedTypes []string `delim:"|"`
  42. FileMaxSize int64
  43. MaxFiles int
  44. } `ini:"-"`
  45. // Repository local settings
  46. Local struct {
  47. LocalCopyPath string
  48. } `ini:"-"`
  49. // Pull request settings
  50. PullRequest struct {
  51. WorkInProgressPrefixes []string
  52. } `ini:"repository.pull-request"`
  53. // Issue Setting
  54. Issue struct {
  55. LockReasons []string
  56. } `ini:"repository.issue"`
  57. Signing struct {
  58. SigningKey string
  59. SigningName string
  60. SigningEmail string
  61. InitialCommit []string
  62. CRUDActions []string `ini:"CRUD_ACTIONS"`
  63. Merges []string
  64. Wiki []string
  65. } `ini:"repository.signing"`
  66. }{
  67. AnsiCharset: "",
  68. ForcePrivate: false,
  69. DefaultPrivate: RepoCreatingLastUserVisibility,
  70. MaxCreationLimit: -1,
  71. MirrorQueueLength: 1000,
  72. PullRequestQueueLength: 1000,
  73. PreferredLicenses: []string{"Apache License 2.0,MIT License"},
  74. DisableHTTPGit: false,
  75. AccessControlAllowOrigin: "",
  76. UseCompatSSHURI: false,
  77. DefaultCloseIssuesViaCommitsInAnyBranch: false,
  78. // Repository editor settings
  79. Editor: struct {
  80. LineWrapExtensions []string
  81. PreviewableFileModes []string
  82. }{
  83. LineWrapExtensions: strings.Split(".txt,.md,.markdown,.mdown,.mkd,", ","),
  84. PreviewableFileModes: []string{"markdown"},
  85. },
  86. // Repository upload settings
  87. Upload: struct {
  88. Enabled bool
  89. TempPath string
  90. AllowedTypes []string `delim:"|"`
  91. FileMaxSize int64
  92. MaxFiles int
  93. }{
  94. Enabled: true,
  95. TempPath: "data/tmp/uploads",
  96. AllowedTypes: []string{},
  97. FileMaxSize: 3,
  98. MaxFiles: 5,
  99. },
  100. // Repository local settings
  101. Local: struct {
  102. LocalCopyPath string
  103. }{
  104. LocalCopyPath: "tmp/local-repo",
  105. },
  106. // Pull request settings
  107. PullRequest: struct {
  108. WorkInProgressPrefixes []string
  109. }{
  110. WorkInProgressPrefixes: []string{"WIP:", "[WIP]"},
  111. },
  112. // Issue settings
  113. Issue: struct {
  114. LockReasons []string
  115. }{
  116. LockReasons: strings.Split("Too heated,Off-topic,Spam,Resolved", ","),
  117. },
  118. // Signing settings
  119. Signing: struct {
  120. SigningKey string
  121. SigningName string
  122. SigningEmail string
  123. InitialCommit []string
  124. CRUDActions []string `ini:"CRUD_ACTIONS"`
  125. Merges []string
  126. Wiki []string
  127. }{
  128. SigningKey: "default",
  129. SigningName: "",
  130. SigningEmail: "",
  131. InitialCommit: []string{"always"},
  132. CRUDActions: []string{"pubkey", "twofa", "parentsigned"},
  133. Merges: []string{"pubkey", "twofa", "basesigned", "commitssigned"},
  134. Wiki: []string{"never"},
  135. },
  136. }
  137. RepoRootPath string
  138. ScriptType = "bash"
  139. )
  140. func newRepository() {
  141. homeDir, err := com.HomeDir()
  142. if err != nil {
  143. log.Fatal("Failed to get home directory: %v", err)
  144. }
  145. homeDir = strings.Replace(homeDir, "\\", "/", -1)
  146. // Determine and create root git repository path.
  147. sec := Cfg.Section("repository")
  148. Repository.DisableHTTPGit = sec.Key("DISABLE_HTTP_GIT").MustBool()
  149. Repository.UseCompatSSHURI = sec.Key("USE_COMPAT_SSH_URI").MustBool()
  150. Repository.MaxCreationLimit = sec.Key("MAX_CREATION_LIMIT").MustInt(-1)
  151. RepoRootPath = sec.Key("ROOT").MustString(path.Join(homeDir, "gitea-repositories"))
  152. forcePathSeparator(RepoRootPath)
  153. if !filepath.IsAbs(RepoRootPath) {
  154. RepoRootPath = filepath.Join(AppWorkPath, RepoRootPath)
  155. } else {
  156. RepoRootPath = filepath.Clean(RepoRootPath)
  157. }
  158. ScriptType = sec.Key("SCRIPT_TYPE").MustString("bash")
  159. if err = Cfg.Section("repository").MapTo(&Repository); err != nil {
  160. log.Fatal("Failed to map Repository settings: %v", err)
  161. } else if err = Cfg.Section("repository.editor").MapTo(&Repository.Editor); err != nil {
  162. log.Fatal("Failed to map Repository.Editor settings: %v", err)
  163. } else if err = Cfg.Section("repository.upload").MapTo(&Repository.Upload); err != nil {
  164. log.Fatal("Failed to map Repository.Upload settings: %v", err)
  165. } else if err = Cfg.Section("repository.local").MapTo(&Repository.Local); err != nil {
  166. log.Fatal("Failed to map Repository.Local settings: %v", err)
  167. } else if err = Cfg.Section("repository.pull-request").MapTo(&Repository.PullRequest); err != nil {
  168. log.Fatal("Failed to map Repository.PullRequest settings: %v", err)
  169. }
  170. if !filepath.IsAbs(Repository.Upload.TempPath) {
  171. Repository.Upload.TempPath = path.Join(AppWorkPath, Repository.Upload.TempPath)
  172. }
  173. }