Skip to content

Commit f6706f9

Browse files
committed
Merge branch 'main' into lunny/use_link_ui
2 parents 387b365 + 4d20a4a commit f6706f9

File tree

13 files changed

+80
-51
lines changed

13 files changed

+80
-51
lines changed

custom/conf/app.example.ini

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -927,14 +927,18 @@ ROUTER = console
927927
;USE_COMPAT_SSH_URI = false
928928
;;
929929
;; Close issues as long as a commit on any branch marks it as fixed
930-
;; Comma separated list of globally disabled repo units. Allowed values: repo.issues, repo.ext_issues, repo.pulls, repo.wiki, repo.ext_wiki, repo.projects
930+
;; Comma separated list of globally disabled repo units. Allowed values: repo.issues, repo.ext_issues, repo.pulls, repo.wiki, repo.ext_wiki, repo.projects, repo.packages
931931
;DISABLED_REPO_UNITS =
932932
;;
933-
;; Comma separated list of default repo units. Allowed values: repo.code, repo.releases, repo.issues, repo.pulls, repo.wiki, repo.projects.
933+
;; Comma separated list of default new repo units. Allowed values: repo.code, repo.releases, repo.issues, repo.pulls, repo.wiki, repo.projects, repo.packages.
934934
;; Note: Code and Releases can currently not be deactivated. If you specify default repo units you should still list them for future compatibility.
935935
;; External wiki and issue tracker can't be enabled by default as it requires additional settings.
936936
;; Disabled repo units will not be added to new repositories regardless if it is in the default list.
937-
;DEFAULT_REPO_UNITS = repo.code,repo.releases,repo.issues,repo.pulls,repo.wiki,repo.projects
937+
;DEFAULT_REPO_UNITS = repo.code,repo.releases,repo.issues,repo.pulls,repo.wiki,repo.projects,repo.packages
938+
;;
939+
;; Comma separated list of default forked repo units.
940+
;; The set of allowed values and rules are the same as DEFAULT_REPO_UNITS.
941+
;DEFAULT_FORK_REPO_UNITS = repo.code,repo.pulls
938942
;;
939943
;; Prefix archive files by placing them in a directory named after the repository
940944
;PREFIX_ARCHIVE_FILES = true
@@ -1218,10 +1222,6 @@ ROUTER = console
12181222
;;
12191223
;; Whether to enable a Service Worker to cache frontend assets
12201224
;USE_SERVICE_WORKER = false
1221-
;;
1222-
;; Whether to only show relevant repos on the explore page when no keyword is specified and default sorting is used.
1223-
;; A repo is considered irrelevant if it's a fork or if it has no metadata (no description, no icon, no topic).
1224-
;ONLY_SHOW_RELEVANT_REPOS = false
12251225

12261226
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12271227
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ In addition there is _`StaticRootPath`_ which can be set as a built-in at build
104104
- `ENABLE_PUSH_CREATE_USER`: **false**: Allow users to push local repositories to Gitea and have them automatically created for a user.
105105
- `ENABLE_PUSH_CREATE_ORG`: **false**: Allow users to push local repositories to Gitea and have them automatically created for an org.
106106
- `DISABLED_REPO_UNITS`: **_empty_**: Comma separated list of globally disabled repo units. Allowed values: \[repo.issues, repo.ext_issues, repo.pulls, repo.wiki, repo.ext_wiki, repo.projects\]
107-
- `DEFAULT_REPO_UNITS`: **repo.code,repo.releases,repo.issues,repo.pulls,repo.wiki,repo.projects**: Comma separated list of default repo units. Allowed values: \[repo.code, repo.releases, repo.issues, repo.pulls, repo.wiki, repo.projects\]. Note: Code and Releases can currently not be deactivated. If you specify default repo units you should still list them for future compatibility. External wiki and issue tracker can't be enabled by default as it requires additional settings. Disabled repo units will not be added to new repositories regardless if it is in the default list.
107+
- `DEFAULT_REPO_UNITS`: **repo.code,repo.releases,repo.issues,repo.pulls,repo.wiki,repo.projects,repo.packages**: Comma separated list of default new repo units. Allowed values: \[repo.code, repo.releases, repo.issues, repo.pulls, repo.wiki, repo.projects\]. Note: Code and Releases can currently not be deactivated. If you specify default repo units you should still list them for future compatibility. External wiki and issue tracker can't be enabled by default as it requires additional settings. Disabled repo units will not be added to new repositories regardless if it is in the default list.
108+
- `DEFAULT_FORK_REPO_UNITS`: **repo.code,repo.pulls**: Comma separated list of default forked repo units. The set of allowed values and rules is the same as `DEFAULT_REPO_UNITS`.
108109
- `PREFIX_ARCHIVE_FILES`: **true**: Prefix archive files by placing them in a directory named after the repository.
109110
- `DISABLE_MIGRATIONS`: **false**: Disable migrating feature.
110111
- `DISABLE_STARS`: **false**: Disable stars feature.
@@ -230,8 +231,6 @@ The following configuration set `Content-Type: application/vnd.android.package-a
230231
- `DEFAULT_SHOW_FULL_NAME`: **false**: Whether the full name of the users should be shown where possible. If the full name isn't set, the username will be used.
231232
- `SEARCH_REPO_DESCRIPTION`: **true**: Whether to search within description at repository search on explore page.
232233
- `USE_SERVICE_WORKER`: **false**: Whether to enable a Service Worker to cache frontend assets.
233-
- `ONLY_SHOW_RELEVANT_REPOS`: **false** Whether to only show relevant repos on the explore page when no keyword is specified and default sorting is used.
234-
A repo is considered irrelevant if it's a fork or if it has no metadata (no description, no icon, no topic).
235234

236235
### UI - Admin (`ui.admin`)
237236

models/repo/repo_list.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond {
494494
}
495495

496496
if opts.OnlyShowRelevant {
497-
// Only show a repo that either has a topic or description.
497+
// Only show a repo that has at least a topic, an icon, or a description
498498
subQueryCond := builder.NewCond()
499499

500500
// Topic checking. Topics are present.
@@ -504,13 +504,13 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond {
504504
subQueryCond = subQueryCond.Or(builder.And(builder.Neq{"topics": "null"}, builder.Neq{"topics": "[]"}))
505505
}
506506

507-
// Description checking. Description not empty.
507+
// Description checking. Description not empty
508508
subQueryCond = subQueryCond.Or(builder.Neq{"description": ""})
509509

510-
// Repo has a avatar.
510+
// Repo has a avatar
511511
subQueryCond = subQueryCond.Or(builder.Neq{"avatar": ""})
512512

513-
// Always hide repo's that are empty.
513+
// Always hide repo's that are empty
514514
subQueryCond = subQueryCond.And(builder.Eq{"is_empty": false})
515515

516516
cond = cond.And(subQueryCond)

models/unit/unit.go

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ var (
9494
TypePackages,
9595
}
9696

97+
// ForkRepoUnits contains the default unit types for forks
98+
DefaultForkRepoUnits = []Type{
99+
TypeCode,
100+
TypePullRequests,
101+
}
102+
97103
// NotAllowedDefaultRepoUnits contains units that can't be default
98104
NotAllowedDefaultRepoUnits = []Type{
99105
TypeExternalUncyclo,
@@ -110,26 +116,41 @@ var (
110116
DisabledRepoUnits = []Type{}
111117
)
112118

113-
// LoadUnitConfig load units from settings
114-
func LoadUnitConfig() {
115-
setDefaultRepoUnits := FindUnitTypes(setting.Repository.DefaultRepoUnits...)
116-
// Default repo units set if setting is not empty
117-
if len(setDefaultRepoUnits) > 0 {
119+
// Get valid set of default repository units from settings
120+
func validateDefaultRepoUnits(defaultUnits, settingDefaultUnits []Type) []Type {
121+
units := defaultUnits
122+
123+
// Use setting if not empty
124+
if len(settingDefaultUnits) > 0 {
118125
// MustRepoUnits required as default
119-
DefaultRepoUnits = make([]Type, len(MustRepoUnits))
120-
copy(DefaultRepoUnits, MustRepoUnits)
121-
for _, defaultU := range setDefaultRepoUnits {
122-
if !defaultU.CanBeDefault() {
123-
log.Warn("Not allowed as default unit: %s", defaultU.String())
126+
units = make([]Type, len(MustRepoUnits))
127+
copy(units, MustRepoUnits)
128+
for _, settingUnit := range settingDefaultUnits {
129+
if !settingUnit.CanBeDefault() {
130+
log.Warn("Not allowed as default unit: %s", settingUnit.String())
124131
continue
125132
}
126133
// MustRepoUnits already added
127-
if defaultU.CanDisable() {
128-
DefaultRepoUnits = append(DefaultRepoUnits, defaultU)
134+
if settingUnit.CanDisable() {
135+
units = append(units, settingUnit)
129136
}
130137
}
131138
}
132139

140+
// Remove disabled units
141+
for _, disabledUnit := range DisabledRepoUnits {
142+
for i, unit := range units {
143+
if unit == disabledUnit {
144+
units = append(units[:i], units[i+1:]...)
145+
}
146+
}
147+
}
148+
149+
return units
150+
}
151+
152+
// LoadUnitConfig load units from settings
153+
func LoadUnitConfig() {
133154
DisabledRepoUnits = FindUnitTypes(setting.Repository.DisabledRepoUnits...)
134155
// Check that must units are not disabled
135156
for i, disabledU := range DisabledRepoUnits {
@@ -138,14 +159,11 @@ func LoadUnitConfig() {
138159
DisabledRepoUnits = append(DisabledRepoUnits[:i], DisabledRepoUnits[i+1:]...)
139160
}
140161
}
141-
// Remove disabled units from default units
142-
for _, disabledU := range DisabledRepoUnits {
143-
for i, defaultU := range DefaultRepoUnits {
144-
if defaultU == disabledU {
145-
DefaultRepoUnits = append(DefaultRepoUnits[:i], DefaultRepoUnits[i+1:]...)
146-
}
147-
}
148-
}
162+
163+
setDefaultRepoUnits := FindUnitTypes(setting.Repository.DefaultRepoUnits...)
164+
DefaultRepoUnits = validateDefaultRepoUnits(DefaultRepoUnits, setDefaultRepoUnits)
165+
setDefaultForkRepoUnits := FindUnitTypes(setting.Repository.DefaultForkRepoUnits...)
166+
DefaultForkRepoUnits = validateDefaultRepoUnits(DefaultForkRepoUnits, setDefaultForkRepoUnits)
149167
}
150168

151169
// UnitGlobalDisabled checks if unit type is global disabled

modules/repository/create.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
)
3131

3232
// CreateRepositoryByExample creates a repository for the user/organization.
33-
func CreateRepositoryByExample(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository, overwriteOrAdopt bool) (err error) {
33+
func CreateRepositoryByExample(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository, overwriteOrAdopt, isFork bool) (err error) {
3434
if err = repo_model.IsUsableRepoName(repo.Name); err != nil {
3535
return err
3636
}
@@ -67,8 +67,12 @@ func CreateRepositoryByExample(ctx context.Context, doer, u *user_model.User, re
6767
}
6868

6969
// insert units for repo
70-
units := make([]repo_model.RepoUnit, 0, len(unit.DefaultRepoUnits))
71-
for _, tp := range unit.DefaultRepoUnits {
70+
defaultUnits := unit.DefaultRepoUnits
71+
if isFork {
72+
defaultUnits = unit.DefaultForkRepoUnits
73+
}
74+
units := make([]repo_model.RepoUnit, 0, len(defaultUnits))
75+
for _, tp := range defaultUnits {
7276
if tp == unit.TypeIssues {
7377
units = append(units, repo_model.RepoUnit{
7478
RepoID: repo.ID,
@@ -212,7 +216,7 @@ func CreateRepository(doer, u *user_model.User, opts CreateRepoOptions) (*repo_m
212216
var rollbackRepo *repo_model.Repository
213217

214218
if err := db.WithTx(db.DefaultContext, func(ctx context.Context) error {
215-
if err := CreateRepositoryByExample(ctx, doer, u, repo, false); err != nil {
219+
if err := CreateRepositoryByExample(ctx, doer, u, repo, false, false); err != nil {
216220
return err
217221
}
218222

modules/repository/generate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ func GenerateRepository(ctx context.Context, doer, owner *user_model.User, templ
319319
TrustModel: templateRepo.TrustModel,
320320
}
321321

322-
if err = CreateRepositoryByExample(ctx, doer, owner, generateRepo, false); err != nil {
322+
if err = CreateRepositoryByExample(ctx, doer, owner, generateRepo, false, false); err != nil {
323323
return nil, err
324324
}
325325

modules/setting/repository.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ var (
4141
EnablePushCreateOrg bool
4242
DisabledRepoUnits []string
4343
DefaultRepoUnits []string
44+
DefaultForkRepoUnits []string
4445
PrefixArchiveFiles bool
4546
DisableMigrations bool
4647
DisableStars bool `ini:"DISABLE_STARS"`
@@ -157,6 +158,7 @@ var (
157158
EnablePushCreateOrg: false,
158159
DisabledRepoUnits: []string{},
159160
DefaultRepoUnits: []string{},
161+
DefaultForkRepoUnits: []string{},
160162
PrefixArchiveFiles: true,
161163
DisableMigrations: false,
162164
DisableStars: false,

modules/setting/setting.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ var (
241241
CustomEmojisMap map[string]string `ini:"-"`
242242
SearchRepoDescription bool
243243
UseServiceWorker bool
244-
OnlyShowRelevantRepos bool
245244

246245
Notification struct {
247246
MinTimeout time.Duration
@@ -1123,7 +1122,6 @@ func loadFromConf(allowEmpty bool, extraConfig string) {
11231122
UI.DefaultShowFullName = Cfg.Section("ui").Key("DEFAULT_SHOW_FULL_NAME").MustBool(false)
11241123
UI.SearchRepoDescription = Cfg.Section("ui").Key("SEARCH_REPO_DESCRIPTION").MustBool(true)
11251124
UI.UseServiceWorker = Cfg.Section("ui").Key("USE_SERVICE_WORKER").MustBool(false)
1126-
UI.OnlyShowRelevantRepos = Cfg.Section("ui").Key("ONLY_SHOW_RELEVANT_REPOS").MustBool(false)
11271125

11281126
HasRobotsTxt, err = util.IsFile(path.Join(CustomPath, "robots.txt"))
11291127
if err != nil {

routers/web/explore/repo.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import (
1717

1818
const (
1919
// tplExploreRepos explore repositories page template
20-
tplExploreRepos base.TplName = "explore/repos"
20+
tplExploreRepos base.TplName = "explore/repos"
21+
relevantReposOnlyParam string = "no_filter"
2122
)
2223

2324
// RepoSearchOptions when calling search repositories
@@ -81,13 +82,11 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
8182
default:
8283
ctx.Data["SortType"] = "recentupdate"
8384
orderBy = db.SearchOrderByRecentUpdated
84-
onlyShowRelevant = setting.UI.OnlyShowRelevantRepos && !ctx.FormBool("no_filter")
8585
}
8686

87+
onlyShowRelevant = !ctx.FormBool(relevantReposOnlyParam)
88+
8789
keyword := ctx.FormTrim("q")
88-
if keyword != "" {
89-
onlyShowRelevant = false
90-
}
9190

9291
ctx.Data["OnlyShowRelevant"] = onlyShowRelevant
9392

@@ -139,7 +138,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
139138
pager.SetDefaultParams(ctx)
140139
pager.AddParam(ctx, "topic", "TopicOnly")
141140
pager.AddParam(ctx, "language", "Language")
142-
pager.AddParamString("no_filter", ctx.FormString("no_filter"))
141+
pager.AddParamString(relevantReposOnlyParam, ctx.FormString(relevantReposOnlyParam))
143142
ctx.Data["Page"] = pager
144143

145144
ctx.HTML(http.StatusOK, opts.TplName)

services/repository/adopt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func AdoptRepository(doer, u *user_model.User, opts repo_module.CreateRepoOption
6767
}
6868
}
6969

70-
if err := repo_module.CreateRepositoryByExample(ctx, doer, u, repo, true); err != nil {
70+
if err := repo_module.CreateRepositoryByExample(ctx, doer, u, repo, true, false); err != nil {
7171
return err
7272
}
7373
if err := adoptRepository(ctx, repoPath, doer, repo, opts); err != nil {

services/repository/fork.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts Fork
119119
}()
120120

121121
err = db.WithTx(ctx, func(txCtx context.Context) error {
122-
if err = repo_module.CreateRepositoryByExample(txCtx, doer, owner, repo, false); err != nil {
122+
if err = repo_module.CreateRepositoryByExample(txCtx, doer, owner, repo, false, true); err != nil {
123123
return err
124124
}
125125

web_src/js/features/repo-findfile.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ export function filterRepoFilesWeighted(files, filter) {
7272
return filterResult;
7373
}
7474

75+
export function escapePath(s) {
76+
return s.split('/').map(encodeURIComponent).join('/');
77+
}
78+
7579
function filterRepoFiles(filter) {
7680
const treeLink = $repoFindFileInput.attr('data-url-tree-link');
7781
$repoFindFileTableBody.empty();
@@ -83,7 +87,7 @@ function filterRepoFiles(filter) {
8387
for (const r of filterResult) {
8488
const $row = $(tmplRow);
8589
const $a = $row.find('a');
86-
$a.attr('href', `${treeLink}/${r.matchResult.join('')}`);
90+
$a.attr('href', `${treeLink}/${escapePath(r.matchResult.join(''))}`);
8791
const $octiconFile = $(svg('octicon-file')).addClass('mr-3');
8892
$a.append($octiconFile);
8993
// if the target file path is "abc/xyz", to search "bx", then the matchResult is ['a', 'b', 'c/', 'x', 'yz']

web_src/js/features/repo-findfile.test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {describe, expect, test} from 'vitest';
2-
import {strSubMatch, calcMatchedWeight, filterRepoFilesWeighted} from './repo-findfile.js';
2+
import {strSubMatch, calcMatchedWeight, filterRepoFilesWeighted, escapePath} from './repo-findfile.js';
33

44
describe('Repo Find Files', () => {
55
test('strSubMatch', () => {
@@ -32,4 +32,9 @@ describe('Repo Find Files', () => {
3232
expect(res).toHaveLength(2);
3333
expect(res[0].matchResult).toEqual(['', 'word', '.txt']);
3434
});
35+
36+
test('escapePath', () => {
37+
expect(escapePath('a/b/c')).toEqual('a/b/c');
38+
expect(escapePath('a/b/ c')).toEqual('a/b/%20c');
39+
});
3540
});

0 commit comments

Comments
 (0)