diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index 41599d411e..da657df60c 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -1025,6 +1025,10 @@ LEVEL = Info ;; The set of allowed values and rules are the same as DEFAULT_REPO_UNITS. ;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 +;; ;; Prefix archive files by placing them in a directory named after the repository ;PREFIX_ARCHIVE_FILES = true ;; diff --git a/models/unit/unit.go b/models/unit/unit.go index 6251d44c9b..a14f3ff364 100644 --- a/models/unit/unit.go +++ b/models/unit/unit.go @@ -1,4 +1,5 @@ // Copyright 2017 The Gitea Authors. All rights reserved. +// Copyright 2024 The Forgejo Authors. All rights reserved. // SPDX-License-Identifier: MIT package unit @@ -69,7 +70,7 @@ func (u Type) LogString() string { } var ( - // AllRepoUnitTypes contains all the unit types + // AllRepoUnitTypes contains all units AllRepoUnitTypes = []Type{ TypeCode, TypeIssues, @@ -83,7 +84,7 @@ var ( TypeActions, } - // DefaultRepoUnits contains the default unit types + // DefaultRepoUnits contains default units for regular repos DefaultRepoUnits = []Type{ TypeCode, TypeIssues, @@ -95,12 +96,22 @@ var ( TypeActions, } - // ForkRepoUnits contains the default unit types for forks + // ForkRepoUnits contains default units for forks DefaultForkRepoUnits = []Type{ TypeCode, TypePullRequests, } + // DefaultMirrorRepoUnits contains default units for mirrors + DefaultMirrorRepoUnits = []Type{ + TypeCode, + TypeIssues, + TypeReleases, + TypeWiki, + TypeProjects, + TypePackages, + } + // NotAllowedDefaultRepoUnits contains units that can't be default NotAllowedDefaultRepoUnits = []Type{ TypeExternalWiki, @@ -172,6 +183,8 @@ func LoadUnitConfig() error { if len(DefaultRepoUnits) == 0 { return errors.New("no default repository units found") } + + // Default fork repo units setDefaultForkRepoUnits, invalidKeys := FindUnitTypes(setting.Repository.DefaultForkRepoUnits...) if len(invalidKeys) > 0 { log.Warn("Invalid keys in default fork repo units: %s", strings.Join(invalidKeys, ", ")) @@ -181,6 +194,16 @@ func LoadUnitConfig() error { 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") + } + // Collect the allowed repo unit groups. Mutually exclusive units are // grouped together. AllowedRepoUnitGroups = [][]Type{} diff --git a/modules/repository/create.go b/modules/repository/create.go index 060b995bc5..becfed0370 100644 --- a/modules/repository/create.go +++ b/modules/repository/create.go @@ -69,8 +69,11 @@ func CreateRepositoryByExample(ctx context.Context, doer, u *user_model.User, re // insert units for repo defaultUnits := unit.DefaultRepoUnits - if isFork { + switch { + case isFork: defaultUnits = unit.DefaultForkRepoUnits + case repo.IsMirror: + defaultUnits = unit.DefaultMirrorRepoUnits } units := make([]repo_model.RepoUnit, 0, len(defaultUnits)) for _, tp := range defaultUnits { diff --git a/modules/setting/repository.go b/modules/setting/repository.go index c9e70560d0..7e774f0139 100644 --- a/modules/setting/repository.go +++ b/modules/setting/repository.go @@ -1,4 +1,5 @@ // Copyright 2019 The Gitea Authors. All rights reserved. +// Copyright 2024 The Forgejo Authors. All rights reserved. // SPDX-License-Identifier: MIT package setting @@ -52,6 +53,7 @@ var ( DisabledRepoUnits []string DefaultRepoUnits []string DefaultForkRepoUnits []string + DefaultMirrorRepoUnits []string PrefixArchiveFiles bool DisableMigrations bool DisableStars bool @@ -175,6 +177,7 @@ var ( DisabledRepoUnits: []string{}, DefaultRepoUnits: []string{}, DefaultForkRepoUnits: []string{}, + DefaultMirrorRepoUnits: []string{}, PrefixArchiveFiles: true, DisableMigrations: false, DisableStars: false,