Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

repository.go 7.1KB

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