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

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