Fork to maintain patches against the official gitea for https://code.ceondo.com https://github.com/go-gitea/gitea

unit.go 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // Copyright 2017 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 models
  5. // UnitType is Unit's Type
  6. type UnitType int
  7. // Enumerate all the unit types
  8. const (
  9. UnitTypeCode UnitType = iota + 1 // 1 code
  10. UnitTypeIssues // 2 issues
  11. UnitTypePullRequests // 3 PRs
  12. UnitTypeReleases // 4 Releases
  13. UnitTypeWiki // 5 Wiki
  14. UnitTypeExternalWiki // 6 ExternalWiki
  15. UnitTypeExternalTracker // 7 ExternalTracker
  16. )
  17. var (
  18. // allRepUnitTypes contains all the unit types
  19. allRepUnitTypes = []UnitType{
  20. UnitTypeCode,
  21. UnitTypeIssues,
  22. UnitTypePullRequests,
  23. UnitTypeReleases,
  24. UnitTypeWiki,
  25. UnitTypeExternalWiki,
  26. UnitTypeExternalTracker,
  27. }
  28. // defaultRepoUnits contains the default unit types
  29. defaultRepoUnits = []UnitType{
  30. UnitTypeCode,
  31. UnitTypeIssues,
  32. UnitTypePullRequests,
  33. UnitTypeReleases,
  34. UnitTypeWiki,
  35. }
  36. // MustRepoUnits contains the units could not be disabled currently
  37. MustRepoUnits = []UnitType{
  38. UnitTypeCode,
  39. UnitTypeReleases,
  40. }
  41. )
  42. // Unit is a section of one repository
  43. type Unit struct {
  44. Type UnitType
  45. NameKey string
  46. URI string
  47. DescKey string
  48. Idx int
  49. }
  50. // CanDisable returns if this unit could be disabled.
  51. func (u *Unit) CanDisable() bool {
  52. return true
  53. }
  54. // IsLessThan compares order of two units
  55. func (u Unit) IsLessThan(unit Unit) bool {
  56. if (u.Type == UnitTypeExternalTracker || u.Type == UnitTypeExternalWiki) && unit.Type != UnitTypeExternalTracker && unit.Type != UnitTypeExternalWiki {
  57. return false
  58. }
  59. return u.Idx < unit.Idx
  60. }
  61. // Enumerate all the units
  62. var (
  63. UnitCode = Unit{
  64. UnitTypeCode,
  65. "repo.code",
  66. "/",
  67. "repo.code.desc",
  68. 0,
  69. }
  70. UnitIssues = Unit{
  71. UnitTypeIssues,
  72. "repo.issues",
  73. "/issues",
  74. "repo.issues.desc",
  75. 1,
  76. }
  77. UnitExternalTracker = Unit{
  78. UnitTypeExternalTracker,
  79. "repo.ext_issues",
  80. "/issues",
  81. "repo.ext_issues.desc",
  82. 1,
  83. }
  84. UnitPullRequests = Unit{
  85. UnitTypePullRequests,
  86. "repo.pulls",
  87. "/pulls",
  88. "repo.pulls.desc",
  89. 2,
  90. }
  91. UnitReleases = Unit{
  92. UnitTypeReleases,
  93. "repo.releases",
  94. "/releases",
  95. "repo.releases.desc",
  96. 3,
  97. }
  98. UnitWiki = Unit{
  99. UnitTypeWiki,
  100. "repo.wiki",
  101. "/wiki",
  102. "repo.wiki.desc",
  103. 4,
  104. }
  105. UnitExternalWiki = Unit{
  106. UnitTypeExternalWiki,
  107. "repo.ext_wiki",
  108. "/wiki",
  109. "repo.ext_wiki.desc",
  110. 4,
  111. }
  112. // Units contains all the units
  113. Units = map[UnitType]Unit{
  114. UnitTypeCode: UnitCode,
  115. UnitTypeIssues: UnitIssues,
  116. UnitTypeExternalTracker: UnitExternalTracker,
  117. UnitTypePullRequests: UnitPullRequests,
  118. UnitTypeReleases: UnitReleases,
  119. UnitTypeWiki: UnitWiki,
  120. UnitTypeExternalWiki: UnitExternalWiki,
  121. }
  122. )