You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

repo_unit.go 7.0 kB

Feature: Timetracking (#2211) * Added comment's hashtag to url for mail notifications. * Added explanation to return statement + documentation. * Replacing in-line link generation with HTMLURL. (+gofmt) * Replaced action-based model with nil-based model. (+gofmt) * Replaced mailIssueActionToParticipants with mailIssueCommentToParticipants. * Updating comment for mailIssueCommentToParticipants * Added link to comment in "Dashboard" * Deleting feed entry if a comment is going to be deleted * Added migration * Added improved migration to add a CommentID column to action. * Added improved links to comments in feed entries. * Fixes #1956 by filtering for deleted comments that are referenced in actions. * Introducing "IsDeleted" column to action. * Adding design draft (not functional) * Adding database models for stopwatches and trackedtimes * See go-gitea/gitea#967 * Adding design draft (not functional) * Adding translations and improving design * Implementing stopwatch (for timetracking) * Make UI functional * Add hints in timeline for time tracking events * Implementing timetracking feature * Adding "Add time manual" option * Improved stopwatch * Created report of total spent time by user * Only showing total time spent if theire is something to show. * Adding license headers. * Improved error handling for "Add Time Manual" * Adding @sapks 's changes, refactoring * Adding API for feature tracking * Adding unit test * Adding DISABLE/ENABLE option to Repository settings page * Improving translations * Applying @sapk 's changes * Removing repo_unit and using IssuesSetting for disabling/enabling timetracker * Adding DEFAULT_ENABLE_TIMETRACKER to config, installation and admin menu * Improving documentation * Fixing vendor/ folder * Changing timtracking routes by adding subgroups /times and /times/stopwatch (Proposed by @lafriks ) * Restricting write access to timetracking based on the repo settings (Proposed by @lafriks ) * Fixed minor permissions bug. * Adding CanUseTimetracker and IsTimetrackerEnabled in ctx.Repo * Allow assignees and authors to track there time too. * Fixed some build-time-errors + logical errors. * Removing unused Get...ByID functions * Moving IsTimetrackerEnabled from context.Repository to models.Repository * Adding a seperate file for issue related repo functions * Adding license headers * Fixed GetUserByParams return 404 * Moving /users/:username/times to /repos/:username/:reponame/times/:username for security reasons * Adding /repos/:username/times to get all tracked times of the repo * Updating sdk-dependency * Updating swagger.v1.json * Adding warning if user has already a running stopwatch (auto-timetracker) * Replacing GetTrackedTimesBy... with GetTrackedTimes(options FindTrackedTimesOptions) * Changing code.gitea.io/sdk back to code.gitea.io/sdk * Correcting spelling mistake * Updating vendor.json * Changing GET stopwatch/toggle to POST stopwatch/toggle * Changing GET stopwatch/cancel to POST stopwatch/cancel * Added migration for stopwatches/timetracking * Fixed some access bugs for read-only users * Added default allow only contributors to track time value to config * Fixed migration by chaging x.Iterate to x.Find * Resorted imports * Moved Add Time Manually form to repo_form.go * Removed "Seconds" field from Add Time Manually * Resorted imports * Improved permission checking * Fixed some bugs * Added integration test * gofmt * Adding integration test by @lafriks * Added created_unix to comment fixtures * Using last event instead of a fixed event * Adding another integration test by @lafriks * Fixing bug Timetracker enabled causing error 500 at sidebar.tpl * Fixed a refactoring bug that resulted in hiding "HasUserStopwatch" warning. * Returning TrackedTime instead of AddTimeOption at AddTime. * Updating SDK from go-gitea/go-sdk#69 * Resetting Go-SDK back to default repository * Fixing test-vendor by changing ini back to original repository * Adding "tags" to swagger spec * govendor sync * Removed duplicate * Formatting templates * Adding IsTimetrackingEnabled checks to API * Improving translations / english texts * Improving documentation * Updating swagger spec * Fixing integration test caused be translation-changes * Removed encoding issues in local_en-US.ini. * "Added" copyright line * Moved unit.IssuesConfig().EnableTimetracker into a != nil check * Removed some other encoding issues in local_en-US.ini * Improved javascript by checking if data-context exists * Replaced manual comment creation with CreateComment * Removed unnecessary code * Improved error checking * Small cosmetic changes * Replaced int>string>duration parsing with int>duration parsing * Fixed encoding issues * Removed unused imports Signed-off-by: Jonas Franz <info@jonasfranz.software>
7 years ago
Feature: Timetracking (#2211) * Added comment's hashtag to url for mail notifications. * Added explanation to return statement + documentation. * Replacing in-line link generation with HTMLURL. (+gofmt) * Replaced action-based model with nil-based model. (+gofmt) * Replaced mailIssueActionToParticipants with mailIssueCommentToParticipants. * Updating comment for mailIssueCommentToParticipants * Added link to comment in "Dashboard" * Deleting feed entry if a comment is going to be deleted * Added migration * Added improved migration to add a CommentID column to action. * Added improved links to comments in feed entries. * Fixes #1956 by filtering for deleted comments that are referenced in actions. * Introducing "IsDeleted" column to action. * Adding design draft (not functional) * Adding database models for stopwatches and trackedtimes * See go-gitea/gitea#967 * Adding design draft (not functional) * Adding translations and improving design * Implementing stopwatch (for timetracking) * Make UI functional * Add hints in timeline for time tracking events * Implementing timetracking feature * Adding "Add time manual" option * Improved stopwatch * Created report of total spent time by user * Only showing total time spent if theire is something to show. * Adding license headers. * Improved error handling for "Add Time Manual" * Adding @sapks 's changes, refactoring * Adding API for feature tracking * Adding unit test * Adding DISABLE/ENABLE option to Repository settings page * Improving translations * Applying @sapk 's changes * Removing repo_unit and using IssuesSetting for disabling/enabling timetracker * Adding DEFAULT_ENABLE_TIMETRACKER to config, installation and admin menu * Improving documentation * Fixing vendor/ folder * Changing timtracking routes by adding subgroups /times and /times/stopwatch (Proposed by @lafriks ) * Restricting write access to timetracking based on the repo settings (Proposed by @lafriks ) * Fixed minor permissions bug. * Adding CanUseTimetracker and IsTimetrackerEnabled in ctx.Repo * Allow assignees and authors to track there time too. * Fixed some build-time-errors + logical errors. * Removing unused Get...ByID functions * Moving IsTimetrackerEnabled from context.Repository to models.Repository * Adding a seperate file for issue related repo functions * Adding license headers * Fixed GetUserByParams return 404 * Moving /users/:username/times to /repos/:username/:reponame/times/:username for security reasons * Adding /repos/:username/times to get all tracked times of the repo * Updating sdk-dependency * Updating swagger.v1.json * Adding warning if user has already a running stopwatch (auto-timetracker) * Replacing GetTrackedTimesBy... with GetTrackedTimes(options FindTrackedTimesOptions) * Changing code.gitea.io/sdk back to code.gitea.io/sdk * Correcting spelling mistake * Updating vendor.json * Changing GET stopwatch/toggle to POST stopwatch/toggle * Changing GET stopwatch/cancel to POST stopwatch/cancel * Added migration for stopwatches/timetracking * Fixed some access bugs for read-only users * Added default allow only contributors to track time value to config * Fixed migration by chaging x.Iterate to x.Find * Resorted imports * Moved Add Time Manually form to repo_form.go * Removed "Seconds" field from Add Time Manually * Resorted imports * Improved permission checking * Fixed some bugs * Added integration test * gofmt * Adding integration test by @lafriks * Added created_unix to comment fixtures * Using last event instead of a fixed event * Adding another integration test by @lafriks * Fixing bug Timetracker enabled causing error 500 at sidebar.tpl * Fixed a refactoring bug that resulted in hiding "HasUserStopwatch" warning. * Returning TrackedTime instead of AddTimeOption at AddTime. * Updating SDK from go-gitea/go-sdk#69 * Resetting Go-SDK back to default repository * Fixing test-vendor by changing ini back to original repository * Adding "tags" to swagger spec * govendor sync * Removed duplicate * Formatting templates * Adding IsTimetrackingEnabled checks to API * Improving translations / english texts * Improving documentation * Updating swagger spec * Fixing integration test caused be translation-changes * Removed encoding issues in local_en-US.ini. * "Added" copyright line * Moved unit.IssuesConfig().EnableTimetracker into a != nil check * Removed some other encoding issues in local_en-US.ini * Improved javascript by checking if data-context exists * Replaced manual comment creation with CreateComment * Removed unnecessary code * Improved error checking * Small cosmetic changes * Replaced int>string>duration parsing with int>duration parsing * Fixed encoding issues * Removed unused imports Signed-off-by: Jonas Franz <info@jonasfranz.software>
7 years ago
4 years ago
Feature: Timetracking (#2211) * Added comment's hashtag to url for mail notifications. * Added explanation to return statement + documentation. * Replacing in-line link generation with HTMLURL. (+gofmt) * Replaced action-based model with nil-based model. (+gofmt) * Replaced mailIssueActionToParticipants with mailIssueCommentToParticipants. * Updating comment for mailIssueCommentToParticipants * Added link to comment in "Dashboard" * Deleting feed entry if a comment is going to be deleted * Added migration * Added improved migration to add a CommentID column to action. * Added improved links to comments in feed entries. * Fixes #1956 by filtering for deleted comments that are referenced in actions. * Introducing "IsDeleted" column to action. * Adding design draft (not functional) * Adding database models for stopwatches and trackedtimes * See go-gitea/gitea#967 * Adding design draft (not functional) * Adding translations and improving design * Implementing stopwatch (for timetracking) * Make UI functional * Add hints in timeline for time tracking events * Implementing timetracking feature * Adding "Add time manual" option * Improved stopwatch * Created report of total spent time by user * Only showing total time spent if theire is something to show. * Adding license headers. * Improved error handling for "Add Time Manual" * Adding @sapks 's changes, refactoring * Adding API for feature tracking * Adding unit test * Adding DISABLE/ENABLE option to Repository settings page * Improving translations * Applying @sapk 's changes * Removing repo_unit and using IssuesSetting for disabling/enabling timetracker * Adding DEFAULT_ENABLE_TIMETRACKER to config, installation and admin menu * Improving documentation * Fixing vendor/ folder * Changing timtracking routes by adding subgroups /times and /times/stopwatch (Proposed by @lafriks ) * Restricting write access to timetracking based on the repo settings (Proposed by @lafriks ) * Fixed minor permissions bug. * Adding CanUseTimetracker and IsTimetrackerEnabled in ctx.Repo * Allow assignees and authors to track there time too. * Fixed some build-time-errors + logical errors. * Removing unused Get...ByID functions * Moving IsTimetrackerEnabled from context.Repository to models.Repository * Adding a seperate file for issue related repo functions * Adding license headers * Fixed GetUserByParams return 404 * Moving /users/:username/times to /repos/:username/:reponame/times/:username for security reasons * Adding /repos/:username/times to get all tracked times of the repo * Updating sdk-dependency * Updating swagger.v1.json * Adding warning if user has already a running stopwatch (auto-timetracker) * Replacing GetTrackedTimesBy... with GetTrackedTimes(options FindTrackedTimesOptions) * Changing code.gitea.io/sdk back to code.gitea.io/sdk * Correcting spelling mistake * Updating vendor.json * Changing GET stopwatch/toggle to POST stopwatch/toggle * Changing GET stopwatch/cancel to POST stopwatch/cancel * Added migration for stopwatches/timetracking * Fixed some access bugs for read-only users * Added default allow only contributors to track time value to config * Fixed migration by chaging x.Iterate to x.Find * Resorted imports * Moved Add Time Manually form to repo_form.go * Removed "Seconds" field from Add Time Manually * Resorted imports * Improved permission checking * Fixed some bugs * Added integration test * gofmt * Adding integration test by @lafriks * Added created_unix to comment fixtures * Using last event instead of a fixed event * Adding another integration test by @lafriks * Fixing bug Timetracker enabled causing error 500 at sidebar.tpl * Fixed a refactoring bug that resulted in hiding "HasUserStopwatch" warning. * Returning TrackedTime instead of AddTimeOption at AddTime. * Updating SDK from go-gitea/go-sdk#69 * Resetting Go-SDK back to default repository * Fixing test-vendor by changing ini back to original repository * Adding "tags" to swagger spec * govendor sync * Removed duplicate * Formatting templates * Adding IsTimetrackingEnabled checks to API * Improving translations / english texts * Improving documentation * Updating swagger spec * Fixing integration test caused be translation-changes * Removed encoding issues in local_en-US.ini. * "Added" copyright line * Moved unit.IssuesConfig().EnableTimetracker into a != nil check * Removed some other encoding issues in local_en-US.ini * Improved javascript by checking if data-context exists * Replaced manual comment creation with CreateComment * Removed unnecessary code * Improved error checking * Small cosmetic changes * Replaced int>string>duration parsing with int>duration parsing * Fixed encoding issues * Removed unused imports Signed-off-by: Jonas Franz <info@jonasfranz.software>
7 years ago
4 years ago
Feature: Timetracking (#2211) * Added comment's hashtag to url for mail notifications. * Added explanation to return statement + documentation. * Replacing in-line link generation with HTMLURL. (+gofmt) * Replaced action-based model with nil-based model. (+gofmt) * Replaced mailIssueActionToParticipants with mailIssueCommentToParticipants. * Updating comment for mailIssueCommentToParticipants * Added link to comment in "Dashboard" * Deleting feed entry if a comment is going to be deleted * Added migration * Added improved migration to add a CommentID column to action. * Added improved links to comments in feed entries. * Fixes #1956 by filtering for deleted comments that are referenced in actions. * Introducing "IsDeleted" column to action. * Adding design draft (not functional) * Adding database models for stopwatches and trackedtimes * See go-gitea/gitea#967 * Adding design draft (not functional) * Adding translations and improving design * Implementing stopwatch (for timetracking) * Make UI functional * Add hints in timeline for time tracking events * Implementing timetracking feature * Adding "Add time manual" option * Improved stopwatch * Created report of total spent time by user * Only showing total time spent if theire is something to show. * Adding license headers. * Improved error handling for "Add Time Manual" * Adding @sapks 's changes, refactoring * Adding API for feature tracking * Adding unit test * Adding DISABLE/ENABLE option to Repository settings page * Improving translations * Applying @sapk 's changes * Removing repo_unit and using IssuesSetting for disabling/enabling timetracker * Adding DEFAULT_ENABLE_TIMETRACKER to config, installation and admin menu * Improving documentation * Fixing vendor/ folder * Changing timtracking routes by adding subgroups /times and /times/stopwatch (Proposed by @lafriks ) * Restricting write access to timetracking based on the repo settings (Proposed by @lafriks ) * Fixed minor permissions bug. * Adding CanUseTimetracker and IsTimetrackerEnabled in ctx.Repo * Allow assignees and authors to track there time too. * Fixed some build-time-errors + logical errors. * Removing unused Get...ByID functions * Moving IsTimetrackerEnabled from context.Repository to models.Repository * Adding a seperate file for issue related repo functions * Adding license headers * Fixed GetUserByParams return 404 * Moving /users/:username/times to /repos/:username/:reponame/times/:username for security reasons * Adding /repos/:username/times to get all tracked times of the repo * Updating sdk-dependency * Updating swagger.v1.json * Adding warning if user has already a running stopwatch (auto-timetracker) * Replacing GetTrackedTimesBy... with GetTrackedTimes(options FindTrackedTimesOptions) * Changing code.gitea.io/sdk back to code.gitea.io/sdk * Correcting spelling mistake * Updating vendor.json * Changing GET stopwatch/toggle to POST stopwatch/toggle * Changing GET stopwatch/cancel to POST stopwatch/cancel * Added migration for stopwatches/timetracking * Fixed some access bugs for read-only users * Added default allow only contributors to track time value to config * Fixed migration by chaging x.Iterate to x.Find * Resorted imports * Moved Add Time Manually form to repo_form.go * Removed "Seconds" field from Add Time Manually * Resorted imports * Improved permission checking * Fixed some bugs * Added integration test * gofmt * Adding integration test by @lafriks * Added created_unix to comment fixtures * Using last event instead of a fixed event * Adding another integration test by @lafriks * Fixing bug Timetracker enabled causing error 500 at sidebar.tpl * Fixed a refactoring bug that resulted in hiding "HasUserStopwatch" warning. * Returning TrackedTime instead of AddTimeOption at AddTime. * Updating SDK from go-gitea/go-sdk#69 * Resetting Go-SDK back to default repository * Fixing test-vendor by changing ini back to original repository * Adding "tags" to swagger spec * govendor sync * Removed duplicate * Formatting templates * Adding IsTimetrackingEnabled checks to API * Improving translations / english texts * Improving documentation * Updating swagger spec * Fixing integration test caused be translation-changes * Removed encoding issues in local_en-US.ini. * "Added" copyright line * Moved unit.IssuesConfig().EnableTimetracker into a != nil check * Removed some other encoding issues in local_en-US.ini * Improved javascript by checking if data-context exists * Replaced manual comment creation with CreateComment * Removed unnecessary code * Improved error checking * Small cosmetic changes * Replaced int>string>duration parsing with int>duration parsing * Fixed encoding issues * Removed unused imports Signed-off-by: Jonas Franz <info@jonasfranz.software>
7 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. import (
  6. "encoding/json"
  7. "code.gitea.io/gitea/modules/timeutil"
  8. "github.com/unknwon/com"
  9. "xorm.io/xorm"
  10. "xorm.io/xorm/convert"
  11. )
  12. // RepoUnit describes all units of a repository
  13. type RepoUnit struct {
  14. ID int64
  15. RepoID int64 `xorm:"INDEX(s)"`
  16. Type UnitType `xorm:"INDEX(s)"`
  17. Config convert.Conversion `xorm:"TEXT"`
  18. CreatedUnix timeutil.TimeStamp `xorm:"INDEX CREATED"`
  19. }
  20. // UnitConfig describes common unit config
  21. type UnitConfig struct {
  22. }
  23. // FromDB fills up a UnitConfig from serialized format.
  24. func (cfg *UnitConfig) FromDB(bs []byte) error {
  25. return json.Unmarshal(bs, &cfg)
  26. }
  27. // ToDB exports a UnitConfig to a serialized format.
  28. func (cfg *UnitConfig) ToDB() ([]byte, error) {
  29. return json.Marshal(cfg)
  30. }
  31. // ExternalWikiConfig describes external wiki config
  32. type ExternalWikiConfig struct {
  33. ExternalWikiURL string
  34. }
  35. // FromDB fills up a ExternalWikiConfig from serialized format.
  36. func (cfg *ExternalWikiConfig) FromDB(bs []byte) error {
  37. return json.Unmarshal(bs, &cfg)
  38. }
  39. // ToDB exports a ExternalWikiConfig to a serialized format.
  40. func (cfg *ExternalWikiConfig) ToDB() ([]byte, error) {
  41. return json.Marshal(cfg)
  42. }
  43. // ExternalTrackerConfig describes external tracker config
  44. type ExternalTrackerConfig struct {
  45. ExternalTrackerURL string
  46. ExternalTrackerFormat string
  47. ExternalTrackerStyle string
  48. }
  49. // FromDB fills up a ExternalTrackerConfig from serialized format.
  50. func (cfg *ExternalTrackerConfig) FromDB(bs []byte) error {
  51. return json.Unmarshal(bs, &cfg)
  52. }
  53. // ToDB exports a ExternalTrackerConfig to a serialized format.
  54. func (cfg *ExternalTrackerConfig) ToDB() ([]byte, error) {
  55. return json.Marshal(cfg)
  56. }
  57. // IssuesConfig describes issues config
  58. type IssuesConfig struct {
  59. EnableTimetracker bool
  60. AllowOnlyContributorsToTrackTime bool
  61. EnableDependencies bool
  62. }
  63. // FromDB fills up a IssuesConfig from serialized format.
  64. func (cfg *IssuesConfig) FromDB(bs []byte) error {
  65. return json.Unmarshal(bs, &cfg)
  66. }
  67. // ToDB exports a IssuesConfig to a serialized format.
  68. func (cfg *IssuesConfig) ToDB() ([]byte, error) {
  69. return json.Marshal(cfg)
  70. }
  71. // PullRequestsConfig describes pull requests config
  72. type PullRequestsConfig struct {
  73. IgnoreWhitespaceConflicts bool
  74. AllowMerge bool
  75. AllowRebase bool
  76. AllowRebaseMerge bool
  77. AllowSquash bool
  78. }
  79. // FromDB fills up a PullRequestsConfig from serialized format.
  80. func (cfg *PullRequestsConfig) FromDB(bs []byte) error {
  81. return json.Unmarshal(bs, &cfg)
  82. }
  83. // ToDB exports a PullRequestsConfig to a serialized format.
  84. func (cfg *PullRequestsConfig) ToDB() ([]byte, error) {
  85. return json.Marshal(cfg)
  86. }
  87. // IsMergeStyleAllowed returns if merge style is allowed
  88. func (cfg *PullRequestsConfig) IsMergeStyleAllowed(mergeStyle MergeStyle) bool {
  89. return mergeStyle == MergeStyleMerge && cfg.AllowMerge ||
  90. mergeStyle == MergeStyleRebase && cfg.AllowRebase ||
  91. mergeStyle == MergeStyleRebaseMerge && cfg.AllowRebaseMerge ||
  92. mergeStyle == MergeStyleSquash && cfg.AllowSquash
  93. }
  94. type DatasetConfig struct {
  95. EnableDataset bool
  96. }
  97. // FromDB fills up a DatasetConfig from serialized format.
  98. func (cfg *DatasetConfig) FromDB(bs []byte) error {
  99. return json.Unmarshal(bs, &cfg)
  100. }
  101. // ToDB exports a DatasetConfig to a serialized format.
  102. func (cfg *DatasetConfig) ToDB() ([]byte, error) {
  103. return json.Marshal(cfg)
  104. }
  105. type CloudBrainConfig struct {
  106. EnableCloudBrain bool
  107. }
  108. type ModelManageConfig struct {
  109. EnableModelManage bool
  110. }
  111. // FromDB fills up a CloudBrainConfig from serialized format.
  112. func (cfg *ModelManageConfig) FromDB(bs []byte) error {
  113. return json.Unmarshal(bs, &cfg)
  114. }
  115. // ToDB exports a CloudBrainConfig to a serialized format.
  116. func (cfg *ModelManageConfig) ToDB() ([]byte, error) {
  117. return json.Marshal(cfg)
  118. }
  119. // FromDB fills up a CloudBrainConfig from serialized format.
  120. func (cfg *CloudBrainConfig) FromDB(bs []byte) error {
  121. return json.Unmarshal(bs, &cfg)
  122. }
  123. // ToDB exports a CloudBrainConfig to a serialized format.
  124. func (cfg *CloudBrainConfig) ToDB() ([]byte, error) {
  125. return json.Marshal(cfg)
  126. }
  127. type BlockChainConfig struct {
  128. EnableBlockChain bool
  129. }
  130. // FromDB fills up a CloudBrainConfig from serialized format.
  131. func (cfg *BlockChainConfig) FromDB(bs []byte) error {
  132. return json.Unmarshal(bs, &cfg)
  133. }
  134. // ToDB exports a CloudBrainConfig to a serialized format.
  135. func (cfg *BlockChainConfig) ToDB() ([]byte, error) {
  136. return json.Marshal(cfg)
  137. }
  138. // BeforeSet is invoked from XORM before setting the value of a field of this object.
  139. func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) {
  140. switch colName {
  141. case "type":
  142. switch UnitType(Cell2Int64(val)) {
  143. case UnitTypeCode, UnitTypeReleases, UnitTypeWiki:
  144. r.Config = new(UnitConfig)
  145. case UnitTypeExternalWiki:
  146. r.Config = new(ExternalWikiConfig)
  147. case UnitTypeExternalTracker:
  148. r.Config = new(ExternalTrackerConfig)
  149. case UnitTypePullRequests:
  150. r.Config = new(PullRequestsConfig)
  151. case UnitTypeIssues:
  152. r.Config = new(IssuesConfig)
  153. case UnitTypeDatasets:
  154. r.Config = new(DatasetConfig)
  155. case UnitTypeCloudBrain:
  156. r.Config = new(CloudBrainConfig)
  157. case UnitTypeBlockChain:
  158. r.Config = new(BlockChainConfig)
  159. case UnitTypeModelManage:
  160. r.Config = new(ModelManageConfig)
  161. default:
  162. panic("unrecognized repo unit type: " + com.ToStr(*val))
  163. }
  164. }
  165. }
  166. // Unit returns Unit
  167. func (r *RepoUnit) Unit() Unit {
  168. return Units[r.Type]
  169. }
  170. // CodeConfig returns config for UnitTypeCode
  171. func (r *RepoUnit) CodeConfig() *UnitConfig {
  172. return r.Config.(*UnitConfig)
  173. }
  174. // PullRequestsConfig returns config for UnitTypePullRequests
  175. func (r *RepoUnit) PullRequestsConfig() *PullRequestsConfig {
  176. return r.Config.(*PullRequestsConfig)
  177. }
  178. // ReleasesConfig returns config for UnitTypeReleases
  179. func (r *RepoUnit) ReleasesConfig() *UnitConfig {
  180. return r.Config.(*UnitConfig)
  181. }
  182. // ExternalWikiConfig returns config for UnitTypeExternalWiki
  183. func (r *RepoUnit) ExternalWikiConfig() *ExternalWikiConfig {
  184. return r.Config.(*ExternalWikiConfig)
  185. }
  186. // IssuesConfig returns config for UnitTypeIssues
  187. func (r *RepoUnit) IssuesConfig() *IssuesConfig {
  188. return r.Config.(*IssuesConfig)
  189. }
  190. // ExternalTrackerConfig returns config for UnitTypeExternalTracker
  191. func (r *RepoUnit) ExternalTrackerConfig() *ExternalTrackerConfig {
  192. return r.Config.(*ExternalTrackerConfig)
  193. }
  194. func (r *RepoUnit) DatasetConfig() *DatasetConfig {
  195. return r.Config.(*DatasetConfig)
  196. }
  197. func getUnitsByRepoID(e Engine, repoID int64) (units []*RepoUnit, err error) {
  198. var tmpUnits []*RepoUnit
  199. if err := e.Where("repo_id = ?", repoID).Find(&tmpUnits); err != nil {
  200. return nil, err
  201. }
  202. for _, u := range tmpUnits {
  203. if !u.Type.UnitGlobalDisabled() {
  204. units = append(units, u)
  205. }
  206. }
  207. return units, nil
  208. }