Skip to content

Commit a154902

Browse files
committed
Merge remote-tracking branch 'upstream/main'
* upstream/main: Add whitespace removal inside template curly brackes (go-gitea#20853) Only show relevant repositories on explore page (go-gitea#19361) Replace `ServeStream` with `ServeContent` (go-gitea#20903) Update JS dependencies (go-gitea#20950) chore: remove broken gitea-format-imports (go-gitea#20952)
2 parents 64da426 + 6c4688e commit a154902

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1797
-4136
lines changed

Makefile

+10-2
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,10 @@ clean:
242242

243243
.PHONY: fmt
244244
fmt:
245-
@echo "Running gitea-fmt (with gofumpt)..."
246245
@MISSPELL_PACKAGE=$(MISSPELL_PACKAGE) GOFUMPT_PACKAGE=$(GOFUMPT_PACKAGE) $(GO) run build/code-batch-process.go gitea-fmt -w '{file-list}'
246+
$(eval TEMPLATES := $(wildcard templates/**/*.tmpl))
247+
@# strip whitespace after '{{' and before `}}` unless there is only whitespace before it
248+
@$(SED_INPLACE) -e 's/{{[ ]\{1,\}/{{/g' -e '/^[ ]\{1,\}}}/! s/[ ]\{1,\}}}/}}/g' $(TEMPLATES)
247249

248250
.PHONY: vet
249251
vet:
@@ -288,13 +290,19 @@ errcheck:
288290

289291
.PHONY: fmt-check
290292
fmt-check:
291-
# get all go files and run gitea-fmt (with gofmt) on them
293+
@# get all go files and run gitea-fmt (with gofmt) on them
292294
@diff=$$(MISSPELL_PACKAGE=$(MISSPELL_PACKAGE) GOFUMPT_PACKAGE=$(GOFUMPT_PACKAGE) $(GO) run build/code-batch-process.go gitea-fmt -l '{file-list}'); \
293295
if [ -n "$$diff" ]; then \
294296
echo "Please run 'make fmt' and commit the result:"; \
295297
echo "$${diff}"; \
296298
exit 1; \
297299
fi
300+
@diff2=$$(git diff templates); \
301+
if [ -n "$$diff2" ]; then \
302+
echo "Please run 'make fmt' and commit the result:"; \
303+
echo "$${diff2}"; \
304+
exit 1; \
305+
fi
298306

299307
.PHONY: checks
300308
checks: checks-frontend checks-backend

build/gitea-format-imports.go

-26
This file was deleted.

custom/conf/app.example.ini

+4
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,10 @@ ROUTER = console
11641164
;;
11651165
;; Whether to enable a Service Worker to cache frontend assets
11661166
;USE_SERVICE_WORKER = false
1167+
;;
1168+
;; Whether to only show relevant repos on the explore page when no keyword is specified and default sorting is used.
1169+
;; A repo is considered irrelevant if it's a fork or if it has no metadata (no description, no icon, no topic).
1170+
;ONLY_SHOW_RELEVANT_REPOS = false
11671171

11681172
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11691173
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

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

+2
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ The following configuration set `Content-Type: application/vnd.android.package-a
194194
- `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.
195195
- `SEARCH_REPO_DESCRIPTION`: **true**: Whether to search within description at repository search on explore page.
196196
- `USE_SERVICE_WORKER`: **false**: Whether to enable a Service Worker to cache frontend assets.
197+
- `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.
198+
A repo is considered irrelevant if it's a fork or if it has no metadata (no description, no icon, no topic).
197199

198200
### UI - Admin (`ui.admin`)
199201

models/repo/repo_list.go

+29-2
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ type SearchRepoOptions struct {
163163
HasMilestones util.OptionalBool
164164
// LowerNames represents valid lower names to restrict to
165165
LowerNames []string
166+
// When specified true, apply some filters over the conditions:
167+
// - Don't show forks, when opts.Fork is OptionalBoolNone.
168+
// - Do not display repositories that don't have a description, an icon and topics.
169+
OnlyShowRelevant bool
166170
}
167171

168172
// SearchOrderBy is used to sort the result
@@ -463,8 +467,12 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond {
463467
Where(builder.Eq{"language": opts.Language}).And(builder.Eq{"is_primary": true})))
464468
}
465469

466-
if opts.Fork != util.OptionalBoolNone {
467-
cond = cond.And(builder.Eq{"is_fork": opts.Fork == util.OptionalBoolTrue})
470+
if opts.Fork != util.OptionalBoolNone || opts.OnlyShowRelevant {
471+
if opts.OnlyShowRelevant && opts.Fork == util.OptionalBoolNone {
472+
cond = cond.And(builder.Eq{"is_fork": false})
473+
} else {
474+
cond = cond.And(builder.Eq{"is_fork": opts.Fork == util.OptionalBoolTrue})
475+
}
468476
}
469477

470478
if opts.Mirror != util.OptionalBoolNone {
@@ -486,6 +494,25 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond {
486494
cond = cond.And(builder.Eq{"num_milestones": 0}.Or(builder.IsNull{"num_milestones"}))
487495
}
488496

497+
if opts.OnlyShowRelevant {
498+
// Only show a repo that either has a topic or description.
499+
subQueryCond := builder.NewCond()
500+
501+
// Topic checking. Topics is non-null.
502+
subQueryCond = subQueryCond.Or(builder.And(builder.Neq{"topics": "null"}, builder.Neq{"topics": "[]"}))
503+
504+
// Description checking. Description not empty.
505+
subQueryCond = subQueryCond.Or(builder.Neq{"description": ""})
506+
507+
// Repo has a avatar.
508+
subQueryCond = subQueryCond.Or(builder.Neq{"avatar": ""})
509+
510+
// Always hide repo's that are empty.
511+
subQueryCond = subQueryCond.And(builder.Eq{"is_empty": false})
512+
513+
cond = cond.And(subQueryCond)
514+
}
515+
489516
return cond
490517
}
491518

modules/context/context.go

+1-17
Original file line numberDiff line numberDiff line change
@@ -358,14 +358,7 @@ func (ctx *Context) SetServeHeaders(filename string) {
358358
}
359359

360360
// ServeContent serves content to http request
361-
func (ctx *Context) ServeContent(name string, r io.ReadSeeker, params ...interface{}) {
362-
modTime := time.Now()
363-
for _, p := range params {
364-
switch v := p.(type) {
365-
case time.Time:
366-
modTime = v
367-
}
368-
}
361+
func (ctx *Context) ServeContent(name string, r io.ReadSeeker, modTime time.Time) {
369362
ctx.SetServeHeaders(name)
370363
http.ServeContent(ctx.Resp, ctx.Req, name, modTime, r)
371364
}
@@ -382,15 +375,6 @@ func (ctx *Context) ServeFile(file string, names ...string) {
382375
http.ServeFile(ctx.Resp, ctx.Req, file)
383376
}
384377

385-
// ServeStream serves file via io stream
386-
func (ctx *Context) ServeStream(rd io.Reader, name string) {
387-
ctx.SetServeHeaders(name)
388-
_, err := io.Copy(ctx.Resp, rd)
389-
if err != nil {
390-
ctx.ServerError("Download file failed", err)
391-
}
392-
}
393-
394378
// UploadStream returns the request body or the first form file
395379
// Only form files need to get closed.
396380
func (ctx *Context) UploadStream() (rd io.ReadCloser, needToClose bool, err error) {

modules/setting/setting.go

+2
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ var (
240240
CustomEmojisMap map[string]string `ini:"-"`
241241
SearchRepoDescription bool
242242
UseServiceWorker bool
243+
OnlyShowRelevantRepos bool
243244

244245
Notification struct {
245246
MinTimeout time.Duration
@@ -1087,6 +1088,7 @@ func loadFromConf(allowEmpty bool, extraConfig string) {
10871088
UI.DefaultShowFullName = Cfg.Section("ui").Key("DEFAULT_SHOW_FULL_NAME").MustBool(false)
10881089
UI.SearchRepoDescription = Cfg.Section("ui").Key("SEARCH_REPO_DESCRIPTION").MustBool(true)
10891090
UI.UseServiceWorker = Cfg.Section("ui").Key("USE_SERVICE_WORKER").MustBool(false)
1091+
UI.OnlyShowRelevantRepos = Cfg.Section("ui").Key("ONLY_SHOW_RELEVANT_REPOS").MustBool(false)
10901092

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

modules/timeutil/timestamp.go

+5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ func (ts TimeStamp) AsTime() (tm time.Time) {
5454
return ts.AsTimeInLocation(setting.DefaultUILocation)
5555
}
5656

57+
// AsLocalTime convert timestamp as time.Time in local location
58+
func (ts TimeStamp) AsLocalTime() time.Time {
59+
return time.Unix(int64(ts), 0)
60+
}
61+
5762
// AsTimeInLocation convert timestamp as time.Time in Local locale
5863
func (ts TimeStamp) AsTimeInLocation(loc *time.Location) (tm time.Time) {
5964
tm = time.Unix(int64(ts), 0).In(loc)

options/locale/locale_en-US.ini

+3
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ org_no_results = No matching organizations found.
277277
code_no_results = No source code matching your search term found.
278278
code_search_results = Search results for '%s'
279279
code_last_indexed_at = Last indexed %s
280+
relevant_repositories_tooltip = Repositories that are forks or that have no topic, no icon, and no description are hidden.
281+
relevant_repositories = Only relevant repositories are being shown, <a href="%s">show unfiltered results</a>.
282+
280283

281284
[auth]
282285
create_new_account = Register Account

0 commit comments

Comments
 (0)