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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. }{
  58. AnsiCharset: "",
  59. ForcePrivate: false,
  60. DefaultPrivate: RepoCreatingLastUserVisibility,
  61. MaxCreationLimit: -1,
  62. MirrorQueueLength: 1000,
  63. PullRequestQueueLength: 1000,
  64. PreferredLicenses: []string{"Apache License 2.0,MIT License"},
  65. DisableHTTPGit: false,
  66. AccessControlAllowOrigin: "",
  67. UseCompatSSHURI: false,
  68. DefaultCloseIssuesViaCommitsInAnyBranch: false,
  69. // Repository editor settings
  70. Editor: struct {
  71. LineWrapExtensions []string
  72. PreviewableFileModes []string
  73. }{
  74. LineWrapExtensions: strings.Split(".txt,.md,.markdown,.mdown,.mkd,", ","),
  75. PreviewableFileModes: []string{"markdown"},
  76. },
  77. // Repository upload settings
  78. Upload: struct {
  79. Enabled bool
  80. TempPath string
  81. AllowedTypes []string `delim:"|"`
  82. FileMaxSize int64
  83. MaxFiles int
  84. }{
  85. Enabled: true,
  86. TempPath: "data/tmp/uploads",
  87. AllowedTypes: []string{},
  88. FileMaxSize: 3,
  89. MaxFiles: 5,
  90. },
  91. // Repository local settings
  92. Local: struct {
  93. LocalCopyPath string
  94. }{
  95. LocalCopyPath: "tmp/local-repo",
  96. },
  97. // Pull request settings
  98. PullRequest: struct {
  99. WorkInProgressPrefixes []string
  100. }{
  101. WorkInProgressPrefixes: []string{"WIP:", "[WIP]"},
  102. },
  103. // Issue settings
  104. Issue: struct {
  105. LockReasons []string
  106. }{
  107. LockReasons: strings.Split("Too heated,Off-topic,Spam,Resolved", ","),
  108. },
  109. }
  110. RepoRootPath string
  111. ScriptType = "bash"
  112. )
  113. func newRepository() {
  114. homeDir, err := com.HomeDir()
  115. if err != nil {
  116. log.Fatal("Failed to get home directory: %v", err)
  117. }
  118. homeDir = strings.Replace(homeDir, "\\", "/", -1)
  119. // Determine and create root git repository path.
  120. sec := Cfg.Section("repository")
  121. Repository.DisableHTTPGit = sec.Key("DISABLE_HTTP_GIT").MustBool()
  122. Repository.UseCompatSSHURI = sec.Key("USE_COMPAT_SSH_URI").MustBool()
  123. Repository.MaxCreationLimit = sec.Key("MAX_CREATION_LIMIT").MustInt(-1)
  124. RepoRootPath = sec.Key("ROOT").MustString(path.Join(homeDir, "gitea-repositories"))
  125. forcePathSeparator(RepoRootPath)
  126. if !filepath.IsAbs(RepoRootPath) {
  127. RepoRootPath = filepath.Join(AppWorkPath, RepoRootPath)
  128. } else {
  129. RepoRootPath = filepath.Clean(RepoRootPath)
  130. }
  131. ScriptType = sec.Key("SCRIPT_TYPE").MustString("bash")
  132. if err = Cfg.Section("repository").MapTo(&Repository); err != nil {
  133. log.Fatal("Failed to map Repository settings: %v", err)
  134. } else if err = Cfg.Section("repository.editor").MapTo(&Repository.Editor); err != nil {
  135. log.Fatal("Failed to map Repository.Editor settings: %v", err)
  136. } else if err = Cfg.Section("repository.upload").MapTo(&Repository.Upload); err != nil {
  137. log.Fatal("Failed to map Repository.Upload settings: %v", err)
  138. } else if err = Cfg.Section("repository.local").MapTo(&Repository.Local); err != nil {
  139. log.Fatal("Failed to map Repository.Local settings: %v", err)
  140. } else if err = Cfg.Section("repository.pull-request").MapTo(&Repository.PullRequest); err != nil {
  141. log.Fatal("Failed to map Repository.PullRequest settings: %v", err)
  142. }
  143. if !filepath.IsAbs(Repository.Upload.TempPath) {
  144. Repository.Upload.TempPath = path.Join(AppWorkPath, Repository.Upload.TempPath)
  145. }
  146. }