mirror of
https://github.com/go-gitea/gitea
synced 2024-12-22 16:44:26 +00:00
Add DEFAULT_MIRROR_REPO_UNITS
and DEFAULT_TEMPLATE_REPO_UNITS
options (#32416)
Resolve #30350 The action unit of mirrors and templates should be disabled by default. This PR adds `DEFAULT_MIRROR_REPO_UNITS` and `DEFAULT_TEMPLATE_REPO_UNITS` options to allow users to specify default units for mirrors and templates. Thanks to @lng2020 for the [idea](https://github.com/go-gitea/gitea/issues/30350#issuecomment-2053942243)
This commit is contained in:
parent
a910abbb45
commit
b1f42a0cdd
@ -1007,6 +1007,14 @@ LEVEL = Info
|
|||||||
;; The set of allowed values and rules are the same as DEFAULT_REPO_UNITS.
|
;; The set of allowed values and rules are the same as DEFAULT_REPO_UNITS.
|
||||||
;DEFAULT_FORK_REPO_UNITS = repo.code,repo.pulls
|
;DEFAULT_FORK_REPO_UNITS = repo.code,repo.pulls
|
||||||
;;
|
;;
|
||||||
|
;; Comma separated list of default mirror repo units.
|
||||||
|
;; The set of allowed values and rules are the same as DEFAULT_REPO_UNITS.
|
||||||
|
;DEFAULT_MIRROR_REPO_UNITS = repo.code,repo.releases,repo.issues,repo.wiki,repo.projects,repo.packages
|
||||||
|
;;
|
||||||
|
;; Comma separated list of default template repo units.
|
||||||
|
;; The set of allowed values and rules are the same as DEFAULT_REPO_UNITS.
|
||||||
|
;DEFAULT_TEMPLATE_REPO_UNITS = repo.code,repo.releases,repo.issues,repo.pulls,repo.wiki,repo.projects,repo.packages
|
||||||
|
;;
|
||||||
;; Prefix archive files by placing them in a directory named after the repository
|
;; Prefix archive files by placing them in a directory named after the repository
|
||||||
;PREFIX_ARCHIVE_FILES = true
|
;PREFIX_ARCHIVE_FILES = true
|
||||||
;;
|
;;
|
||||||
|
@ -80,6 +80,27 @@ var (
|
|||||||
TypePullRequests,
|
TypePullRequests,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DefaultMirrorRepoUnits contains the default unit types for mirrors
|
||||||
|
DefaultMirrorRepoUnits = []Type{
|
||||||
|
TypeCode,
|
||||||
|
TypeIssues,
|
||||||
|
TypeReleases,
|
||||||
|
TypeWiki,
|
||||||
|
TypeProjects,
|
||||||
|
TypePackages,
|
||||||
|
}
|
||||||
|
|
||||||
|
// DefaultTemplateRepoUnits contains the default unit types for templates
|
||||||
|
DefaultTemplateRepoUnits = []Type{
|
||||||
|
TypeCode,
|
||||||
|
TypeIssues,
|
||||||
|
TypePullRequests,
|
||||||
|
TypeReleases,
|
||||||
|
TypeWiki,
|
||||||
|
TypeProjects,
|
||||||
|
TypePackages,
|
||||||
|
}
|
||||||
|
|
||||||
// NotAllowedDefaultRepoUnits contains units that can't be default
|
// NotAllowedDefaultRepoUnits contains units that can't be default
|
||||||
NotAllowedDefaultRepoUnits = []Type{
|
NotAllowedDefaultRepoUnits = []Type{
|
||||||
TypeExternalWiki,
|
TypeExternalWiki,
|
||||||
@ -147,6 +168,7 @@ func LoadUnitConfig() error {
|
|||||||
if len(DefaultRepoUnits) == 0 {
|
if len(DefaultRepoUnits) == 0 {
|
||||||
return errors.New("no default repository units found")
|
return errors.New("no default repository units found")
|
||||||
}
|
}
|
||||||
|
// default fork repo units
|
||||||
setDefaultForkRepoUnits, invalidKeys := FindUnitTypes(setting.Repository.DefaultForkRepoUnits...)
|
setDefaultForkRepoUnits, invalidKeys := FindUnitTypes(setting.Repository.DefaultForkRepoUnits...)
|
||||||
if len(invalidKeys) > 0 {
|
if len(invalidKeys) > 0 {
|
||||||
log.Warn("Invalid keys in default fork repo units: %s", strings.Join(invalidKeys, ", "))
|
log.Warn("Invalid keys in default fork repo units: %s", strings.Join(invalidKeys, ", "))
|
||||||
@ -155,6 +177,24 @@ func LoadUnitConfig() error {
|
|||||||
if len(DefaultForkRepoUnits) == 0 {
|
if len(DefaultForkRepoUnits) == 0 {
|
||||||
return errors.New("no default fork repository units found")
|
return errors.New("no default fork repository units found")
|
||||||
}
|
}
|
||||||
|
// default mirror repo units
|
||||||
|
setDefaultMirrorRepoUnits, invalidKeys := FindUnitTypes(setting.Repository.DefaultMirrorRepoUnits...)
|
||||||
|
if len(invalidKeys) > 0 {
|
||||||
|
log.Warn("Invalid keys in default mirror repo units: %s", strings.Join(invalidKeys, ", "))
|
||||||
|
}
|
||||||
|
DefaultMirrorRepoUnits = validateDefaultRepoUnits(DefaultMirrorRepoUnits, setDefaultMirrorRepoUnits)
|
||||||
|
if len(DefaultMirrorRepoUnits) == 0 {
|
||||||
|
return errors.New("no default mirror repository units found")
|
||||||
|
}
|
||||||
|
// default template repo units
|
||||||
|
setDefaultTemplateRepoUnits, invalidKeys := FindUnitTypes(setting.Repository.DefaultTemplateRepoUnits...)
|
||||||
|
if len(invalidKeys) > 0 {
|
||||||
|
log.Warn("Invalid keys in default template repo units: %s", strings.Join(invalidKeys, ", "))
|
||||||
|
}
|
||||||
|
DefaultTemplateRepoUnits = validateDefaultRepoUnits(DefaultTemplateRepoUnits, setDefaultTemplateRepoUnits)
|
||||||
|
if len(DefaultTemplateRepoUnits) == 0 {
|
||||||
|
return errors.New("no default template repository units found")
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,6 +43,8 @@ var (
|
|||||||
DisabledRepoUnits []string
|
DisabledRepoUnits []string
|
||||||
DefaultRepoUnits []string
|
DefaultRepoUnits []string
|
||||||
DefaultForkRepoUnits []string
|
DefaultForkRepoUnits []string
|
||||||
|
DefaultMirrorRepoUnits []string
|
||||||
|
DefaultTemplateRepoUnits []string
|
||||||
PrefixArchiveFiles bool
|
PrefixArchiveFiles bool
|
||||||
DisableMigrations bool
|
DisableMigrations bool
|
||||||
DisableStars bool `ini:"DISABLE_STARS"`
|
DisableStars bool `ini:"DISABLE_STARS"`
|
||||||
@ -161,6 +163,8 @@ var (
|
|||||||
DisabledRepoUnits: []string{},
|
DisabledRepoUnits: []string{},
|
||||||
DefaultRepoUnits: []string{},
|
DefaultRepoUnits: []string{},
|
||||||
DefaultForkRepoUnits: []string{},
|
DefaultForkRepoUnits: []string{},
|
||||||
|
DefaultMirrorRepoUnits: []string{},
|
||||||
|
DefaultTemplateRepoUnits: []string{},
|
||||||
PrefixArchiveFiles: true,
|
PrefixArchiveFiles: true,
|
||||||
DisableMigrations: false,
|
DisableMigrations: false,
|
||||||
DisableStars: false,
|
DisableStars: false,
|
||||||
|
@ -381,8 +381,13 @@ func CreateRepositoryByExample(ctx context.Context, doer, u *user_model.User, re
|
|||||||
|
|
||||||
// insert units for repo
|
// insert units for repo
|
||||||
defaultUnits := unit.DefaultRepoUnits
|
defaultUnits := unit.DefaultRepoUnits
|
||||||
if isFork {
|
switch {
|
||||||
|
case isFork:
|
||||||
defaultUnits = unit.DefaultForkRepoUnits
|
defaultUnits = unit.DefaultForkRepoUnits
|
||||||
|
case repo.IsMirror:
|
||||||
|
defaultUnits = unit.DefaultMirrorRepoUnits
|
||||||
|
case repo.IsTemplate:
|
||||||
|
defaultUnits = unit.DefaultTemplateRepoUnits
|
||||||
}
|
}
|
||||||
units := make([]repo_model.RepoUnit, 0, len(defaultUnits))
|
units := make([]repo_model.RepoUnit, 0, len(defaultUnits))
|
||||||
for _, tp := range defaultUnits {
|
for _, tp := range defaultUnits {
|
||||||
|
Loading…
Reference in New Issue
Block a user