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.4KB

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