Skip to content

Commit 6779933

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Fix Ruby package parsing by removed unused email field (go-gitea#20470) [skip ci] Updated translations via Crowdin Add repository condition for issue count (go-gitea#20454) Prepend commit message to template content (go-gitea#20429) Improve pprof doc (go-gitea#20463) Improve code diff highlight, fix incorrect rendered diff result (go-gitea#19958) Add Cache-Control header to html and api responses, add no-transform (go-gitea#20432) [skip ci] Updated translations via Crowdin Allow non-semver packages in the Conan package registry (go-gitea#20412) Use body text color in repository files table links (go-gitea#20386) Correct code block in installation docs for Snap (go-gitea#20440) Downgrade golangci-lint to 1.47.0 (go-gitea#20445) Add eslint-plugin-sonarjs (go-gitea#20431) Fix: Actor is required to get user repositories (go-gitea#20443) Add "X-Gitea-Object-Type" header for GET `/raw/` & `/media/` API (go-gitea#20438) Simplify visibility checks (go-gitea#20406)
2 parents ae4cac0 + 690272d commit 6779933

File tree

39 files changed

+568
-430
lines changed

39 files changed

+568
-430
lines changed

.eslintrc.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ plugins:
1212
- eslint-plugin-unicorn
1313
- eslint-plugin-import
1414
- eslint-plugin-jquery
15+
- eslint-plugin-sonarjs
1516

1617
env:
1718
es2022: true
@@ -369,6 +370,38 @@ rules:
369370
semi-spacing: [2, {before: false, after: true}]
370371
semi-style: [2, last]
371372
semi: [2, always, {omitLastInOneLineBlock: true}]
373+
sonarjs/cognitive-complexity: [0]
374+
sonarjs/elseif-without-else: [0]
375+
sonarjs/max-switch-cases: [0]
376+
sonarjs/no-all-duplicated-branches: [2]
377+
sonarjs/no-collapsible-if: [0]
378+
sonarjs/no-collection-size-mischeck: [2]
379+
sonarjs/no-duplicate-string: [0]
380+
sonarjs/no-duplicated-branches: [0]
381+
sonarjs/no-element-overwrite: [2]
382+
sonarjs/no-empty-collection: [2]
383+
sonarjs/no-extra-arguments: [0]
384+
sonarjs/no-gratuitous-expressions: [2]
385+
sonarjs/no-identical-conditions: [2]
386+
sonarjs/no-identical-expressions: [0]
387+
sonarjs/no-identical-functions: [0]
388+
sonarjs/no-ignored-return: [2]
389+
sonarjs/no-inverted-boolean-check: [2]
390+
sonarjs/no-nested-switch: [0]
391+
sonarjs/no-nested-template-literals: [0]
392+
sonarjs/no-one-iteration-loop: [2]
393+
sonarjs/no-redundant-boolean: [2]
394+
sonarjs/no-redundant-jump: [0]
395+
sonarjs/no-same-line-conditional: [2]
396+
sonarjs/no-small-switch: [0]
397+
sonarjs/no-unused-collection: [2]
398+
sonarjs/no-use-of-empty-return-value: [2]
399+
sonarjs/no-useless-catch: [0]
400+
sonarjs/non-existent-operator: [2]
401+
sonarjs/prefer-immediate-return: [0]
402+
sonarjs/prefer-object-literal: [0]
403+
sonarjs/prefer-single-boolean-return: [0]
404+
sonarjs/prefer-while: [2]
372405
sort-imports: [0]
373406
sort-keys: [0]
374407
sort-vars: [0]

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ AIR_PACKAGE ?= github.com/cosmtrek/[email protected]
2929
EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/cmd/[email protected]
3030
ERRCHECK_PACKAGE ?= github.com/kisielk/[email protected]
3131
GOFUMPT_PACKAGE ?= mvdan.cc/[email protected]
32-
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/[email protected].1
32+
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/[email protected].0
3333
GXZ_PAGAGE ?= github.com/ulikunitz/xz/cmd/[email protected]
3434
MISSPELL_PACKAGE ?= github.com/client9/misspell/cmd/[email protected]
3535
SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/[email protected]

cmd/web.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,9 @@ func runWeb(ctx *cli.Context) error {
148148
go func() {
149149
http.DefaultServeMux.Handle("/debug/fgprof", fgprof.Handler())
150150
_, _, finished := process.GetManager().AddTypedContext(context.Background(), "Web: PProf Server", process.SystemProcessType, true)
151+
// The pprof server is for debug purpose only, it shouldn't be exposed on public network. At the moment it's not worth to introduce a configurable option for it.
151152
log.Info("Starting pprof server on localhost:6060")
152-
log.Info("%v", http.ListenAndServe("localhost:6060", nil))
153+
log.Info("Stopped pprof server: %v", http.ListenAndServe("localhost:6060", nil))
153154
finished()
154155
}()
155156
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ The following configuration set `Content-Type: application/vnd.android.package-a
300300
- `APP_DATA_PATH`: **data** (**/data/gitea** on docker): Default path for application data.
301301
- `STATIC_CACHE_TIME`: **6h**: Web browser cache time for static resources on `custom/`, `public/` and all uploaded avatars. Note that this cache is disabled when `RUN_MODE` is "dev".
302302
- `ENABLE_GZIP`: **false**: Enable gzip compression for runtime-generated content, static resources excluded.
303-
- `ENABLE_PPROF`: **false**: Application profiling (memory and cpu). For "web" command it listens on localhost:6060. For "serv" command it dumps to disk at `PPROF_DATA_PATH` as `(cpuprofile|memprofile)_<username>_<temporary id>`
303+
- `ENABLE_PPROF`: **false**: Application profiling (memory and cpu). For "web" command it listens on `localhost:6060`. For "serv" command it dumps to disk at `PPROF_DATA_PATH` as `(cpuprofile|memprofile)_<username>_<temporary id>`
304304
- `PPROF_DATA_PATH`: **data/tmp/pprof**: `PPROF_DATA_PATH`, use an absolute path when you start Gitea as service
305305
- `LANDING_PAGE`: **home**: Landing page for unauthenticated users \[home, explore, organizations, login, **custom**\]. Where custom would instead be any URL such as "/org/repo" or even `https://anotherwebsite.com`
306306
- `LFS_START_SERVER`: **false**: Enables Git LFS support.

docs/content/doc/help/seek-help.en-us.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,13 @@ menu:
4444
* This will greatly improve the chance that the root of the issue can be quickly discovered and resolved.
4545
5. If you meet slow/hanging/deadlock problems, please report the stack trace when the problem occurs:
4646
1. Enable pprof in `app.ini` and restart Gitea
47-
```
47+
```ini
4848
[server]
4949
ENABLE_PPROF = true
5050
```
51-
2. Trigger the bug, when Gitea gets stuck, use curl or browser to visit: `http://127.0.0.1:6060/debug/pprof/goroutine?debug=1` (IP is `127.0.0.1` and port is `6060`)
52-
3. Report the output (the stack trace doesn't contain sensitive data)
51+
2. Trigger the bug, when Gitea gets stuck, use curl or browser to visit: `http://127.0.0.1:6060/debug/pprof/goroutine?debug=1` (IP must be `127.0.0.1` and port must be `6060`).
52+
3. If you are using Docker, please use `docker exec -it <container-name> curl "http://127.0.0.1:6060/debug/pprof/goroutine?debug=1"`.
53+
4. Report the output (the stack trace doesn't contain sensitive data)
5354
5455
## Bugs
5556

docs/content/doc/installation/from-package.en-us.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ pacman -S gitea
4747

4848
There is a [Gitea Snap](https://snapcraft.io/gitea) package which follows the latest stable version.
4949

50-
``sh
50+
```sh
5151
snap install gitea
52-
``
52+
```
5353

5454
## SUSE and openSUSE
5555

integrations/api_repo_raw_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010

1111
"code.gitea.io/gitea/models/unittest"
1212
user_model "code.gitea.io/gitea/models/user"
13+
14+
"github.com/stretchr/testify/assert"
1315
)
1416

1517
func TestAPIReposRaw(t *testing.T) {
@@ -25,9 +27,11 @@ func TestAPIReposRaw(t *testing.T) {
2527
"65f1bf27bc3bf70f64657658635e66094edbcb4d", // Commit
2628
} {
2729
req := NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/raw/%s/README.md?token="+token, user.Name, ref)
28-
session.MakeRequest(t, req, http.StatusOK)
30+
resp := session.MakeRequest(t, req, http.StatusOK)
31+
assert.EqualValues(t, "file", resp.Header().Get("x-gitea-object-type"))
2932
}
3033
// Test default branch
3134
req := NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/raw/README.md?token="+token, user.Name)
32-
session.MakeRequest(t, req, http.StatusOK)
35+
resp := session.MakeRequest(t, req, http.StatusOK)
36+
assert.EqualValues(t, "file", resp.Header().Get("x-gitea-object-type"))
3337
}

models/repo/repo_list.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package repo
66

77
import (
88
"context"
9+
"errors"
910
"fmt"
1011
"strings"
1112

@@ -695,6 +696,9 @@ func GetUserRepositories(opts *SearchRepoOptions) (RepositoryList, int64, error)
695696
}
696697

697698
cond := builder.NewCond()
699+
if opts.Actor == nil {
700+
return nil, 0, errors.New("GetUserRepositories: Actor is needed but not given")
701+
}
698702
cond = cond.And(builder.Eq{"owner_id": opts.Actor.ID})
699703
if !opts.Private {
700704
cond = cond.And(builder.Eq{"is_private": false})

models/user/search.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,18 @@ func (opts *SearchUserOptions) toSearchQueryBase() *xorm.Session {
5959
}
6060

6161
if opts.Actor != nil {
62-
exprCond := builder.Expr("org_user.org_id = `user`.id")
63-
6462
// If Admin - they see all users!
6563
if !opts.Actor.IsAdmin {
66-
// Force visibility for privacy
67-
var accessCond builder.Cond
64+
// Users can see an organization they are a member of
65+
accessCond := builder.In("id", builder.Select("org_id").From("org_user").Where(builder.Eq{"uid": opts.Actor.ID}))
6866
if !opts.Actor.IsRestricted {
69-
accessCond = builder.Or(
70-
builder.In("id", builder.Select("org_id").From("org_user").LeftJoin("`user`", exprCond).Where(builder.And(builder.Eq{"uid": opts.Actor.ID}, builder.Eq{"visibility": structs.VisibleTypePrivate}))),
71-
builder.In("visibility", structs.VisibleTypePublic, structs.VisibleTypeLimited))
72-
} else {
73-
// restricted users only see orgs they are a member of
74-
accessCond = builder.In("id", builder.Select("org_id").From("org_user").LeftJoin("`user`", exprCond).Where(builder.And(builder.Eq{"uid": opts.Actor.ID})))
67+
// Not-Restricted users can see public and limited users/organizations
68+
accessCond = accessCond.Or(builder.In("visibility", structs.VisibleTypePublic, structs.VisibleTypeLimited))
7569
}
7670
// Don't forget about self
7771
accessCond = accessCond.Or(builder.Eq{"id": opts.Actor.ID})
7872
cond = cond.And(accessCond)
7973
}
80-
8174
} else {
8275
// Force visibility for privacy
8376
// Not logged in - only public users

modules/context/api.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
repo_model "code.gitea.io/gitea/models/repo"
1717
"code.gitea.io/gitea/modules/cache"
1818
"code.gitea.io/gitea/modules/git"
19+
"code.gitea.io/gitea/modules/httpcache"
1920
"code.gitea.io/gitea/modules/log"
2021
"code.gitea.io/gitea/modules/setting"
2122
"code.gitea.io/gitea/modules/web/middleware"
@@ -268,6 +269,7 @@ func APIContexter() func(http.Handler) http.Handler {
268269
}
269270
}
270271

272+
httpcache.AddCacheControlToHeader(ctx.Resp.Header(), 0, "no-transform")
271273
ctx.Resp.Header().Set(`X-Frame-Options`, setting.CORSConfig.XFrameOptions)
272274

273275
ctx.Data["Context"] = &ctx

0 commit comments

Comments
 (0)