Skip to content

Commit fbda2fd

Browse files
committed
Merge branch 'main' into limit-org-member-view-of-restricted-users
2 parents 389d8d0 + b1f42a0 commit fbda2fd

File tree

5 files changed

+128
-1
lines changed

5 files changed

+128
-1
lines changed

custom/conf/app.example.ini

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,14 @@ LEVEL = Info
10071007
;; The set of allowed values and rules are the same as DEFAULT_REPO_UNITS.
10081008
;DEFAULT_FORK_REPO_UNITS = repo.code,repo.pulls
10091009
;;
1010+
;; Comma separated list of default mirror repo units.
1011+
;; The set of allowed values and rules are the same as DEFAULT_REPO_UNITS.
1012+
;DEFAULT_MIRROR_REPO_UNITS = repo.code,repo.releases,repo.issues,repo.wiki,repo.projects,repo.packages
1013+
;;
1014+
;; Comma separated list of default template repo units.
1015+
;; The set of allowed values and rules are the same as DEFAULT_REPO_UNITS.
1016+
;DEFAULT_TEMPLATE_REPO_UNITS = repo.code,repo.releases,repo.issues,repo.pulls,repo.wiki,repo.projects,repo.packages
1017+
;;
10101018
;; Prefix archive files by placing them in a directory named after the repository
10111019
;PREFIX_ARCHIVE_FILES = true
10121020
;;

models/unit/unit.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,27 @@ var (
8080
TypePullRequests,
8181
}
8282

83+
// DefaultMirrorRepoUnits contains the default unit types for mirrors
84+
DefaultMirrorRepoUnits = []Type{
85+
TypeCode,
86+
TypeIssues,
87+
TypeReleases,
88+
TypeWiki,
89+
TypeProjects,
90+
TypePackages,
91+
}
92+
93+
// DefaultTemplateRepoUnits contains the default unit types for templates
94+
DefaultTemplateRepoUnits = []Type{
95+
TypeCode,
96+
TypeIssues,
97+
TypePullRequests,
98+
TypeReleases,
99+
TypeWiki,
100+
TypeProjects,
101+
TypePackages,
102+
}
103+
83104
// NotAllowedDefaultRepoUnits contains units that can't be default
84105
NotAllowedDefaultRepoUnits = []Type{
85106
TypeExternalWiki,
@@ -147,6 +168,7 @@ func LoadUnitConfig() error {
147168
if len(DefaultRepoUnits) == 0 {
148169
return errors.New("no default repository units found")
149170
}
171+
// default fork repo units
150172
setDefaultForkRepoUnits, invalidKeys := FindUnitTypes(setting.Repository.DefaultForkRepoUnits...)
151173
if len(invalidKeys) > 0 {
152174
log.Warn("Invalid keys in default fork repo units: %s", strings.Join(invalidKeys, ", "))
@@ -155,6 +177,24 @@ func LoadUnitConfig() error {
155177
if len(DefaultForkRepoUnits) == 0 {
156178
return errors.New("no default fork repository units found")
157179
}
180+
// default mirror repo units
181+
setDefaultMirrorRepoUnits, invalidKeys := FindUnitTypes(setting.Repository.DefaultMirrorRepoUnits...)
182+
if len(invalidKeys) > 0 {
183+
log.Warn("Invalid keys in default mirror repo units: %s", strings.Join(invalidKeys, ", "))
184+
}
185+
DefaultMirrorRepoUnits = validateDefaultRepoUnits(DefaultMirrorRepoUnits, setDefaultMirrorRepoUnits)
186+
if len(DefaultMirrorRepoUnits) == 0 {
187+
return errors.New("no default mirror repository units found")
188+
}
189+
// default template repo units
190+
setDefaultTemplateRepoUnits, invalidKeys := FindUnitTypes(setting.Repository.DefaultTemplateRepoUnits...)
191+
if len(invalidKeys) > 0 {
192+
log.Warn("Invalid keys in default template repo units: %s", strings.Join(invalidKeys, ", "))
193+
}
194+
DefaultTemplateRepoUnits = validateDefaultRepoUnits(DefaultTemplateRepoUnits, setDefaultTemplateRepoUnits)
195+
if len(DefaultTemplateRepoUnits) == 0 {
196+
return errors.New("no default template repository units found")
197+
}
158198
return nil
159199
}
160200

modules/setting/repository.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ var (
4343
DisabledRepoUnits []string
4444
DefaultRepoUnits []string
4545
DefaultForkRepoUnits []string
46+
DefaultMirrorRepoUnits []string
47+
DefaultTemplateRepoUnits []string
4648
PrefixArchiveFiles bool
4749
DisableMigrations bool
4850
DisableStars bool `ini:"DISABLE_STARS"`
@@ -161,6 +163,8 @@ var (
161163
DisabledRepoUnits: []string{},
162164
DefaultRepoUnits: []string{},
163165
DefaultForkRepoUnits: []string{},
166+
DefaultMirrorRepoUnits: []string{},
167+
DefaultTemplateRepoUnits: []string{},
164168
PrefixArchiveFiles: true,
165169
DisableMigrations: false,
166170
DisableStars: false,

services/doctor/actions.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright 2024 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package doctor
5+
6+
import (
7+
"context"
8+
"fmt"
9+
10+
"code.gitea.io/gitea/models/db"
11+
repo_model "code.gitea.io/gitea/models/repo"
12+
unit_model "code.gitea.io/gitea/models/unit"
13+
"code.gitea.io/gitea/modules/log"
14+
"code.gitea.io/gitea/modules/optional"
15+
repo_service "code.gitea.io/gitea/services/repository"
16+
)
17+
18+
func disableMirrorActionsUnit(ctx context.Context, logger log.Logger, autofix bool) error {
19+
var reposToFix []*repo_model.Repository
20+
21+
for page := 1; ; page++ {
22+
repos, _, err := repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{
23+
ListOptions: db.ListOptions{
24+
PageSize: repo_model.RepositoryListDefaultPageSize,
25+
Page: page,
26+
},
27+
Mirror: optional.Some(true),
28+
})
29+
if err != nil {
30+
return fmt.Errorf("SearchRepository: %w", err)
31+
}
32+
if len(repos) == 0 {
33+
break
34+
}
35+
36+
for _, repo := range repos {
37+
if repo.UnitEnabled(ctx, unit_model.TypeActions) {
38+
reposToFix = append(reposToFix, repo)
39+
}
40+
}
41+
}
42+
43+
if len(reposToFix) == 0 {
44+
logger.Info("Found no mirror with actions unit enabled")
45+
} else {
46+
logger.Warn("Found %d mirrors with actions unit enabled", len(reposToFix))
47+
}
48+
if !autofix || len(reposToFix) == 0 {
49+
return nil
50+
}
51+
52+
for _, repo := range reposToFix {
53+
if err := repo_service.UpdateRepositoryUnits(ctx, repo, nil, []unit_model.Type{unit_model.TypeActions}); err != nil {
54+
return err
55+
}
56+
}
57+
logger.Info("Fixed %d mirrors with actions unit enabled", len(reposToFix))
58+
59+
return nil
60+
}
61+
62+
func init() {
63+
Register(&Check{
64+
Title: "Disable the actions unit for all mirrors",
65+
Name: "disable-mirror-actions-unit",
66+
IsDefault: false,
67+
Run: disableMirrorActionsUnit,
68+
Priority: 9,
69+
})
70+
}

services/repository/create.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,13 @@ func CreateRepositoryByExample(ctx context.Context, doer, u *user_model.User, re
381381

382382
// insert units for repo
383383
defaultUnits := unit.DefaultRepoUnits
384-
if isFork {
384+
switch {
385+
case isFork:
385386
defaultUnits = unit.DefaultForkRepoUnits
387+
case repo.IsMirror:
388+
defaultUnits = unit.DefaultMirrorRepoUnits
389+
case repo.IsTemplate:
390+
defaultUnits = unit.DefaultTemplateRepoUnits
386391
}
387392
units := make([]repo_model.RepoUnit, 0, len(defaultUnits))
388393
for _, tp := range defaultUnits {

0 commit comments

Comments
 (0)