Skip to content

Commit 3107305

Browse files
committed
Merge remote-tracking branch 'upstream/main'
* upstream/main: [skip ci] Updated translations via Crowdin Typo in config-cheat-sheet (go-gitea#21261) Use native inputs in whitespace dropdown (go-gitea#20980) [skip ci] Updated licenses and gitignores Use en-US as fallback when using other default language (go-gitea#21200) Make NuGet service index publicly accessible (go-gitea#21242) Save files in local storage as umask (go-gitea#21198) NPM Package Registry search API endpoint (go-gitea#20280) [skip ci] Updated translations via Crowdin Added search input field to issue filter (go-gitea#20623)
2 parents 7636631 + 2649e7f commit 3107305

File tree

24 files changed

+407
-77
lines changed

24 files changed

+407
-77
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ Default templates for project boards:
852852
- `SCHEDULE` accept formats
853853
- Full crontab specs, e.g. `* * * * * ?`
854854
- Descriptors, e.g. `@midnight`, `@every 1h30m` ...
855-
- See more: [cron decument](https://pkg.go.dev/github.com/gogs/[email protected])
855+
- See more: [cron documentation](https://pkg.go.dev/github.com/gogs/[email protected])
856856

857857
### Basic cron tasks - enabled by default
858858

docs/content/doc/packages/npm.en-us.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ npm dist-tag add [email protected] release
127127

128128
The tag name must not be a valid version. All tag names which are parsable as a version are rejected.
129129

130+
## Search packages
131+
132+
The registry supports [searching](https://docs.npmjs.com/cli/v7/commands/npm-search/) but does not support special search qualifiers like `author:gitea`.
133+
130134
## Supported commands
131135

132136
```
@@ -136,4 +140,5 @@ npm publish
136140
npm unpublish
137141
npm dist-tag
138142
npm view
143+
npm search
139144
```

modules/packages/npm/creator.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,34 @@ type PackageDistribution struct {
9696
NpmSignature string `json:"npm-signature,omitempty"`
9797
}
9898

99+
type PackageSearch struct {
100+
Objects []*PackageSearchObject `json:"objects"`
101+
Total int64 `json:"total"`
102+
}
103+
104+
type PackageSearchObject struct {
105+
Package *PackageSearchPackage `json:"package"`
106+
}
107+
108+
type PackageSearchPackage struct {
109+
Scope string `json:"scope"`
110+
Name string `json:"name"`
111+
Version string `json:"version"`
112+
Date time.Time `json:"date"`
113+
Description string `json:"description"`
114+
Author User `json:"author"`
115+
Publisher User `json:"publisher"`
116+
Maintainers []User `json:"maintainers"`
117+
Keywords []string `json:"keywords,omitempty"`
118+
Links *PackageSearchPackageLinks `json:"links"`
119+
}
120+
121+
type PackageSearchPackageLinks struct {
122+
Registry string `json:"npm"`
123+
Homepage string `json:"homepage,omitempty"`
124+
Repository string `json:"repository,omitempty"`
125+
}
126+
99127
// User https://github.com/npm/registry/blob/master/docs/REGISTRY-API.md#package
100128
type User struct {
101129
Username string `json:"username,omitempty"`

modules/storage/local.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ func (l *LocalStorage) Save(path string, r io.Reader, size int64) (int64, error)
102102
if err := util.Rename(tmp.Name(), p); err != nil {
103103
return 0, err
104104
}
105+
// Golang's tmp file (os.CreateTemp) always have 0o600 mode, so we need to change the file to follow the umask (as what Create/MkDir does)
106+
if err := util.ApplyUmask(p, os.ModePerm); err != nil {
107+
return 0, err
108+
}
105109

106110
tmpRemoved = true
107111

modules/translation/i18n/i18n.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type LocaleStore interface {
3434
// HasLang returns whether a given language is present in the store
3535
HasLang(langName string) bool
3636
// AddLocaleByIni adds a new language to the store
37-
AddLocaleByIni(langName, langDesc string, source interface{}) error
37+
AddLocaleByIni(langName, langDesc string, source, moreSource []byte) error
3838
}
3939

4040
// ResetDefaultLocales resets the current default locales

modules/translation/i18n/i18n_test.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/stretchr/testify/assert"
1111
)
1212

13-
func Test_Tr(t *testing.T) {
13+
func TestLocaleStore(t *testing.T) {
1414
testData1 := []byte(`
1515
.dot.name = Dot Name
1616
fmt = %[1]s %[2]s
@@ -28,8 +28,8 @@ sub = Changed Sub String
2828
`)
2929

3030
ls := NewLocaleStore()
31-
assert.NoError(t, ls.AddLocaleByIni("lang1", "Lang1", testData1))
32-
assert.NoError(t, ls.AddLocaleByIni("lang2", "Lang2", testData2))
31+
assert.NoError(t, ls.AddLocaleByIni("lang1", "Lang1", testData1, nil))
32+
assert.NoError(t, ls.AddLocaleByIni("lang2", "Lang2", testData2, nil))
3333
ls.SetDefaultLang("lang1")
3434

3535
result := ls.Tr("lang1", "fmt", "a", "b")
@@ -58,3 +58,21 @@ sub = Changed Sub String
5858
assert.False(t, found)
5959
assert.NoError(t, ls.Close())
6060
}
61+
62+
func TestLocaleStoreMoreSource(t *testing.T) {
63+
testData1 := []byte(`
64+
a=11
65+
b=12
66+
`)
67+
68+
testData2 := []byte(`
69+
b=21
70+
c=22
71+
`)
72+
73+
ls := NewLocaleStore()
74+
assert.NoError(t, ls.AddLocaleByIni("lang1", "Lang1", testData1, testData2))
75+
assert.Equal(t, "11", ls.Tr("lang1", "a"))
76+
assert.Equal(t, "21", ls.Tr("lang1", "b"))
77+
assert.Equal(t, "22", ls.Tr("lang1", "c"))
78+
}

modules/translation/i18n/localestore.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ func NewLocaleStore() LocaleStore {
3737
}
3838

3939
// AddLocaleByIni adds locale by ini into the store
40-
// if source is a string, then the file is loaded
41-
// if source is a []byte, then the content is used
42-
func (store *localeStore) AddLocaleByIni(langName, langDesc string, source interface{}) error {
40+
func (store *localeStore) AddLocaleByIni(langName, langDesc string, source, moreSource []byte) error {
4341
if _, ok := store.localeMap[langName]; ok {
4442
return ErrLocaleAlreadyExist
4543
}
@@ -53,7 +51,7 @@ func (store *localeStore) AddLocaleByIni(langName, langDesc string, source inter
5351
iniFile, err := ini.LoadSources(ini.LoadOptions{
5452
IgnoreInlineComment: true,
5553
UnescapeValueCommentSymbols: true,
56-
}, source)
54+
}, source, moreSource)
5755
if err != nil {
5856
return fmt.Errorf("unable to load ini: %w", err)
5957
}

modules/translation/translation.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ func InitLocales(ctx context.Context) {
6060
log.Fatal("Failed to list locale files: %v", err)
6161
}
6262

63-
localFiles := make(map[string]interface{}, len(localeNames))
63+
localeData := make(map[string][]byte, len(localeNames))
6464
for _, name := range localeNames {
65-
localFiles[name], err = options.Locale(name)
65+
localeData[name], err = options.Locale(name)
6666
if err != nil {
6767
log.Fatal("Failed to load %s locale file. %v", name, err)
6868
}
@@ -75,9 +75,17 @@ func InitLocales(ctx context.Context) {
7575

7676
matcher = language.NewMatcher(supportedTags)
7777
for i := range setting.Names {
78-
key := "locale_" + setting.Langs[i] + ".ini"
78+
var localeDataBase []byte
79+
if i == 0 && setting.Langs[0] != "en-US" {
80+
// Only en-US has complete translations. When use other language as default, the en-US should still be used as fallback.
81+
localeDataBase = localeData["locale_en-US.ini"]
82+
if localeDataBase == nil {
83+
log.Fatal("Failed to load locale_en-US.ini file.")
84+
}
85+
}
7986

80-
if err = i18n.DefaultLocales.AddLocaleByIni(setting.Langs[i], setting.Names[i], localFiles[key]); err != nil {
87+
key := "locale_" + setting.Langs[i] + ".ini"
88+
if err = i18n.DefaultLocales.AddLocaleByIni(setting.Langs[i], setting.Names[i], localeDataBase, localeData[key]); err != nil {
8189
log.Error("Failed to set messages to %s: %v", setting.Langs[i], err)
8290
}
8391
}

modules/util/file_unix.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2022 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
//go:build !windows
6+
7+
package util
8+
9+
import (
10+
"os"
11+
12+
"golang.org/x/sys/unix"
13+
)
14+
15+
var defaultUmask int
16+
17+
func init() {
18+
// at the moment, the umask could only be gotten by calling unix.Umask(newUmask)
19+
// use 0o077 as temp new umask to reduce the risks if this umask is used anywhere else before the correct umask is recovered
20+
tempUmask := 0o077
21+
defaultUmask = unix.Umask(tempUmask)
22+
unix.Umask(defaultUmask)
23+
}
24+
25+
func ApplyUmask(f string, newMode os.FileMode) error {
26+
mod := newMode & ^os.FileMode(defaultUmask)
27+
return os.Chmod(f, mod)
28+
}

modules/util/file_unix_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2022 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
//go:build !windows
6+
7+
package util
8+
9+
import (
10+
"os"
11+
"testing"
12+
13+
"github.com/stretchr/testify/assert"
14+
)
15+
16+
func TestApplyUmask(t *testing.T) {
17+
f, err := os.CreateTemp(t.TempDir(), "test-filemode-")
18+
assert.NoError(t, err)
19+
20+
err = os.Chmod(f.Name(), 0o777)
21+
assert.NoError(t, err)
22+
st, err := os.Stat(f.Name())
23+
assert.NoError(t, err)
24+
assert.EqualValues(t, 0o777, st.Mode().Perm()&0o777)
25+
26+
oldDefaultUmask := defaultUmask
27+
defaultUmask = 0o037
28+
defer func() {
29+
defaultUmask = oldDefaultUmask
30+
}()
31+
err = ApplyUmask(f.Name(), os.ModePerm)
32+
assert.NoError(t, err)
33+
st, err = os.Stat(f.Name())
34+
assert.NoError(t, err)
35+
assert.EqualValues(t, 0o740, st.Mode().Perm()&0o777)
36+
}

modules/util/file_windows.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2022 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
//go:build windows
6+
7+
package util
8+
9+
import (
10+
"os"
11+
)
12+
13+
func ApplyUmask(f string, newMode os.FileMode) error {
14+
// do nothing for Windows, because Windows doesn't use umask
15+
return nil
16+
}

options/license/checkmk

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2006, 2010 Micah Cowan
2+
#
3+
# Redistribution of this program in any form, with or without
4+
# modifications, is permitted, provided that the above copyright is
5+
# retained in distributions of this program in source form.
6+
#
7+
# (This is a free, non-copyleft license compatible with pretty much any
8+
# other free or proprietary license, including the GPL. It's essentially
9+
# a scaled-down version of the "modified" BSD license.)

options/locale/locale_ja-JP.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3092,6 +3092,7 @@ container.details.platform=プラットフォーム
30923092
container.details.repository_site=リポジトリサイト
30933093
container.details.documentation_site=ドキュメントサイト
30943094
container.pull=コマンドラインでイメージを取得します:
3095+
container.digest=ダイジェスト:
30953096
container.documentation=Container レジストリの詳細については、 <a target="_blank" rel="noopener noreferrer" href="https://docs.gitea.io/en-us/packages/container/">ドキュメント</a> を参照してください。
30963097
container.multi_arch=OS / アーキテクチャ
30973098
container.layers=イメージレイヤー

0 commit comments

Comments
 (0)