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

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

modules/context/context.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"code.gitea.io/gitea/modules/base"
2929
mc "code.gitea.io/gitea/modules/cache"
3030
"code.gitea.io/gitea/modules/git"
31+
"code.gitea.io/gitea/modules/httpcache"
3132
"code.gitea.io/gitea/modules/json"
3233
"code.gitea.io/gitea/modules/log"
3334
"code.gitea.io/gitea/modules/setting"
@@ -767,6 +768,7 @@ func Contexter() func(next http.Handler) http.Handler {
767768
}
768769
}
769770

771+
httpcache.AddCacheControlToHeader(ctx.Resp.Header(), 0, "no-transform")
770772
ctx.Resp.Header().Set(`X-Frame-Options`, setting.CORSConfig.XFrameOptions)
771773

772774
ctx.Data["CsrfToken"] = ctx.csrf.GetToken()

modules/highlight/highlight.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ var (
4040
// NewContext loads custom highlight map from local config
4141
func NewContext() {
4242
once.Do(func() {
43-
keys := setting.Cfg.Section("highlight.mapping").Keys()
44-
for i := range keys {
45-
highlightMapping[keys[i].Name()] = keys[i].Value()
43+
if setting.Cfg != nil {
44+
keys := setting.Cfg.Section("highlight.mapping").Keys()
45+
for i := range keys {
46+
highlightMapping[keys[i].Name()] = keys[i].Value()
47+
}
4648
}
4749

4850
// The size 512 is simply a conservative rule of thumb

modules/httpcache/httpcache.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,23 @@ import (
1717
)
1818

1919
// AddCacheControlToHeader adds suitable cache-control headers to response
20-
func AddCacheControlToHeader(h http.Header, d time.Duration) {
20+
func AddCacheControlToHeader(h http.Header, maxAge time.Duration, additionalDirectives ...string) {
21+
directives := make([]string, 0, 2+len(additionalDirectives))
22+
2123
if setting.IsProd {
22-
h.Set("Cache-Control", "private, max-age="+strconv.Itoa(int(d.Seconds())))
24+
if maxAge == 0 {
25+
directives = append(directives, "no-store")
26+
} else {
27+
directives = append(directives, "private", "max-age="+strconv.Itoa(int(maxAge.Seconds())))
28+
}
2329
} else {
24-
h.Set("Cache-Control", "no-store")
30+
directives = append(directives, "no-store")
31+
2532
// to remind users they are using non-prod setting.
26-
// some users may be confused by "Cache-Control: no-store" in their setup if they did wrong to `RUN_MODE` in `app.ini`.
2733
h.Add("X-Gitea-Debug", "RUN_MODE="+setting.RunMode)
28-
h.Add("X-Gitea-Debug", "CacheControl=no-store")
2934
}
35+
36+
h.Set("Cache-Control", strings.Join(append(directives, additionalDirectives...), ", "))
3037
}
3138

3239
// generateETag generates an ETag based on size, filename and file modification time

modules/markup/html.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ func genDefaultLinkProcessor(defaultLink string) processor {
11761176
node.DataAtom = atom.A
11771177
node.Attr = []html.Attribute{
11781178
{Key: "href", Val: defaultLink},
1179-
{Key: "class", Val: "default-link"},
1179+
{Key: "class", Val: "default-link muted"},
11801180
}
11811181
node.FirstChild, node.LastChild = ch, ch
11821182
}

modules/packages/conan/reference.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ import (
88
"errors"
99
"fmt"
1010
"regexp"
11+
"strings"
1112

1213
"code.gitea.io/gitea/modules/log"
13-
14-
goversion "github.com/hashicorp/go-version"
1514
)
1615

1716
const (
@@ -56,7 +55,9 @@ func NewRecipeReference(name, version, user, channel, revision string) (*RecipeR
5655
if !namePattern.MatchString(name) {
5756
return nil, ErrValidation
5857
}
59-
if _, err := goversion.NewSemver(version); err != nil {
58+
59+
v := strings.TrimSpace(version)
60+
if v == "" {
6061
return nil, ErrValidation
6162
}
6263
if user != "" && !namePattern.MatchString(user) {
@@ -69,7 +70,7 @@ func NewRecipeReference(name, version, user, channel, revision string) (*RecipeR
6970
return nil, ErrValidation
7071
}
7172

72-
return &RecipeReference{name, version, user, channel, revision}, nil
73+
return &RecipeReference{name, v, user, channel, revision}, nil
7374
}
7475

7576
func (r *RecipeReference) RevisionOrDefault() string {

modules/packages/conan/reference_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func TestNewRecipeReference(t *testing.T) {
3434
{"name", "1.0", "_", "_", "", true},
3535
{"name", "1.0", "_", "_", "0", true},
3636
{"name", "1.0", "", "", "0", true},
37+
{"name", "1.0.0q", "", "", "0", true},
3738
{"name", "1.0", "", "", "000000000000000000000000000000000000000000000000000000000000", false},
3839
}
3940

modules/packages/rubygems/metadata.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ type gemspec struct {
8080
VersionRequirements requirement `yaml:"version_requirements"`
8181
} `yaml:"dependencies"`
8282
Description string `yaml:"description"`
83-
Email string `yaml:"email"`
8483
Executables []string `yaml:"executables"`
8584
Extensions []interface{} `yaml:"extensions"`
8685
ExtraRdocFiles []string `yaml:"extra_rdoc_files"`

options/locale/locale_el-GR.ini

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,7 @@ projects.type.basic_kanban=Βασικό Kanban
11771177
projects.type.bug_triage=Διαλογή Σφαλμάτων
11781178
projects.template.desc=Πρότυπο έργου
11791179
projects.template.desc_helper=Επιλέξτε ένα πρότυπο έργου για να ξεκινήσετε
1180-
projects.type.uncategorized=Αταξινόμητο
1180+
projects.type.uncategorized=Χωρίς Κατηγορία
11811181
projects.board.edit=Επεξεργασία πίνακα
11821182
projects.board.edit_title=Νέο Όνομα Πίνακα
11831183
projects.board.new_title=Νέο Όνομα Πίνακα
@@ -1186,7 +1186,7 @@ projects.board.new=Νέος Πίνακας
11861186
projects.board.set_default=Ορισμός Προεπιλογής
11871187
projects.board.set_default_desc=Ορίστε αυτόν τον πίνακα ως προεπιλογή για μη κατηγοριοποιημένα ζητήματα και pull requests
11881188
projects.board.delete=Διαγραφή Πίνακα
1189-
projects.board.deletion_desc=Η διαγραφή ενός πίνακα έργου μετακινεί όλα τα σχετιζόμενα ζητήματα σε 'Αταξινόμητα'. Συνέχεια;
1189+
projects.board.deletion_desc=Η διαγραφή ενός πίνακα έργου μετακινεί όλα τα σχετιζόμενα ζητήματα σε 'Χωρίς Κατηγορία'. Συνέχεια;
11901190
projects.board.color=Χρώμα
11911191
projects.open=Άνοιγμα
11921192
projects.close=Κλείσιμο
@@ -1420,6 +1420,7 @@ issues.due_date_form_remove=Διαγραφή
14201420
issues.due_date_not_writer=Χρειάζεστε πρόσβαση εγγραφής στο αποθετήριο για να ενημερώσετε την ημερομηνία λήξης ενός ζητήματος.
14211421
issues.due_date_not_set=Δεν ορίστηκε ημερομηνία παράδοσης.
14221422
issues.due_date_added=πρόσθεσε την ημερομηνία παράδοσης %s %s
1423+
issues.due_date_modified=τροποποίησε την ημερομηνία παράδοσης από %[2]s σε %[1]s %[3]s
14231424
issues.due_date_remove=αφαίρεσε την ημερομηνία παράδοσης %s %s
14241425
issues.due_date_overdue=Εκπρόθεσμο
14251426
issues.due_date_invalid=Η ημερομηνία παράδοσης δεν είναι έγκυρη ή εκτός εύρους. Παρακαλούμε χρησιμοποιήστε τη μορφή 'εεεε-μμ-ηη'.

options/locale/locale_ja-JP.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,7 @@ issues.due_date_form_remove=削除
14201420
issues.due_date_not_writer=イシューの期日を変更するには、リポジトリへの書き込み権限が必要です。
14211421
issues.due_date_not_set=期日は未設定です。
14221422
issues.due_date_added=が期日 %s を追加 %s
1423+
issues.due_date_modified=が期日を %[2]s から %[1]s に変更 %[3]s
14231424
issues.due_date_remove=が期日 %s を削除 %s
14241425
issues.due_date_overdue=期日は過ぎています
14251426
issues.due_date_invalid=期日が正しくないか範囲を超えています。 'yyyy-mm-dd' の形式で入力してください。

package-lock.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"eslint": "8.20.0",
5151
"eslint-plugin-import": "2.26.0",
5252
"eslint-plugin-jquery": "1.5.1",
53+
"eslint-plugin-sonarjs": "0.13.0",
5354
"eslint-plugin-unicorn": "43.0.2",
5455
"eslint-plugin-vue": "9.2.0",
5556
"jest": "28.1.3",

0 commit comments

Comments
 (0)