Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
zjjhot committed Sep 26, 2022
2 parents 7636631 + 2649e7f commit 3107305
Show file tree
Hide file tree
Showing 24 changed files with 407 additions and 77 deletions.
2 changes: 1 addition & 1 deletion docs/content/doc/advanced/config-cheat-sheet.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ Default templates for project boards:
- `SCHEDULE` accept formats
- Full crontab specs, e.g. `* * * * * ?`
- Descriptors, e.g. `@midnight`, `@every 1h30m` ...
- See more: [cron decument](https://pkg.go.dev/github.com/gogs/cron@v0.0.0-20171120032916-9f6c956d3e14)
- See more: [cron documentation](https://pkg.go.dev/github.com/gogs/cron@v0.0.0-20171120032916-9f6c956d3e14)

### Basic cron tasks - enabled by default

Expand Down
5 changes: 5 additions & 0 deletions docs/content/doc/packages/npm.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ npm dist-tag add test_package@1.0.2 release

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

## Search packages

The registry supports [searching](https://docs.npmjs.com/cli/v7/commands/npm-search/) but does not support special search qualifiers like `author:gitea`.

## Supported commands

```
Expand All @@ -136,4 +140,5 @@ npm publish
npm unpublish
npm dist-tag
npm view
npm search
```
28 changes: 28 additions & 0 deletions modules/packages/npm/creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,34 @@ type PackageDistribution struct {
NpmSignature string `json:"npm-signature,omitempty"`
}

type PackageSearch struct {
Objects []*PackageSearchObject `json:"objects"`
Total int64 `json:"total"`
}

type PackageSearchObject struct {
Package *PackageSearchPackage `json:"package"`
}

type PackageSearchPackage struct {
Scope string `json:"scope"`
Name string `json:"name"`
Version string `json:"version"`
Date time.Time `json:"date"`
Description string `json:"description"`
Author User `json:"author"`
Publisher User `json:"publisher"`
Maintainers []User `json:"maintainers"`
Keywords []string `json:"keywords,omitempty"`
Links *PackageSearchPackageLinks `json:"links"`
}

type PackageSearchPackageLinks struct {
Registry string `json:"npm"`
Homepage string `json:"homepage,omitempty"`
Repository string `json:"repository,omitempty"`
}

// User https://github.com/npm/registry/blob/master/docs/REGISTRY-API.md#package
type User struct {
Username string `json:"username,omitempty"`
Expand Down
4 changes: 4 additions & 0 deletions modules/storage/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ func (l *LocalStorage) Save(path string, r io.Reader, size int64) (int64, error)
if err := util.Rename(tmp.Name(), p); err != nil {
return 0, err
}
// 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)
if err := util.ApplyUmask(p, os.ModePerm); err != nil {
return 0, err
}

tmpRemoved = true

Expand Down
2 changes: 1 addition & 1 deletion modules/translation/i18n/i18n.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type LocaleStore interface {
// HasLang returns whether a given language is present in the store
HasLang(langName string) bool
// AddLocaleByIni adds a new language to the store
AddLocaleByIni(langName, langDesc string, source interface{}) error
AddLocaleByIni(langName, langDesc string, source, moreSource []byte) error
}

// ResetDefaultLocales resets the current default locales
Expand Down
24 changes: 21 additions & 3 deletions modules/translation/i18n/i18n_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/assert"
)

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

ls := NewLocaleStore()
assert.NoError(t, ls.AddLocaleByIni("lang1", "Lang1", testData1))
assert.NoError(t, ls.AddLocaleByIni("lang2", "Lang2", testData2))
assert.NoError(t, ls.AddLocaleByIni("lang1", "Lang1", testData1, nil))
assert.NoError(t, ls.AddLocaleByIni("lang2", "Lang2", testData2, nil))
ls.SetDefaultLang("lang1")

result := ls.Tr("lang1", "fmt", "a", "b")
Expand Down Expand Up @@ -58,3 +58,21 @@ sub = Changed Sub String
assert.False(t, found)
assert.NoError(t, ls.Close())
}

func TestLocaleStoreMoreSource(t *testing.T) {
testData1 := []byte(`
a=11
b=12
`)

testData2 := []byte(`
b=21
c=22
`)

ls := NewLocaleStore()
assert.NoError(t, ls.AddLocaleByIni("lang1", "Lang1", testData1, testData2))
assert.Equal(t, "11", ls.Tr("lang1", "a"))
assert.Equal(t, "21", ls.Tr("lang1", "b"))
assert.Equal(t, "22", ls.Tr("lang1", "c"))
}
6 changes: 2 additions & 4 deletions modules/translation/i18n/localestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ func NewLocaleStore() LocaleStore {
}

// AddLocaleByIni adds locale by ini into the store
// if source is a string, then the file is loaded
// if source is a []byte, then the content is used
func (store *localeStore) AddLocaleByIni(langName, langDesc string, source interface{}) error {
func (store *localeStore) AddLocaleByIni(langName, langDesc string, source, moreSource []byte) error {
if _, ok := store.localeMap[langName]; ok {
return ErrLocaleAlreadyExist
}
Expand All @@ -53,7 +51,7 @@ func (store *localeStore) AddLocaleByIni(langName, langDesc string, source inter
iniFile, err := ini.LoadSources(ini.LoadOptions{
IgnoreInlineComment: true,
UnescapeValueCommentSymbols: true,
}, source)
}, source, moreSource)
if err != nil {
return fmt.Errorf("unable to load ini: %w", err)
}
Expand Down
16 changes: 12 additions & 4 deletions modules/translation/translation.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ func InitLocales(ctx context.Context) {
log.Fatal("Failed to list locale files: %v", err)
}

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

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

if err = i18n.DefaultLocales.AddLocaleByIni(setting.Langs[i], setting.Names[i], localFiles[key]); err != nil {
key := "locale_" + setting.Langs[i] + ".ini"
if err = i18n.DefaultLocales.AddLocaleByIni(setting.Langs[i], setting.Names[i], localeDataBase, localeData[key]); err != nil {
log.Error("Failed to set messages to %s: %v", setting.Langs[i], err)
}
}
Expand Down
28 changes: 28 additions & 0 deletions modules/util/file_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build !windows

package util

import (
"os"

"golang.org/x/sys/unix"
)

var defaultUmask int

func init() {
// at the moment, the umask could only be gotten by calling unix.Umask(newUmask)
// use 0o077 as temp new umask to reduce the risks if this umask is used anywhere else before the correct umask is recovered
tempUmask := 0o077
defaultUmask = unix.Umask(tempUmask)
unix.Umask(defaultUmask)
}

func ApplyUmask(f string, newMode os.FileMode) error {
mod := newMode & ^os.FileMode(defaultUmask)
return os.Chmod(f, mod)
}
36 changes: 36 additions & 0 deletions modules/util/file_unix_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build !windows

package util

import (
"os"
"testing"

"github.com/stretchr/testify/assert"
)

func TestApplyUmask(t *testing.T) {
f, err := os.CreateTemp(t.TempDir(), "test-filemode-")
assert.NoError(t, err)

err = os.Chmod(f.Name(), 0o777)
assert.NoError(t, err)
st, err := os.Stat(f.Name())
assert.NoError(t, err)
assert.EqualValues(t, 0o777, st.Mode().Perm()&0o777)

oldDefaultUmask := defaultUmask
defaultUmask = 0o037
defer func() {
defaultUmask = oldDefaultUmask
}()
err = ApplyUmask(f.Name(), os.ModePerm)
assert.NoError(t, err)
st, err = os.Stat(f.Name())
assert.NoError(t, err)
assert.EqualValues(t, 0o740, st.Mode().Perm()&0o777)
}
16 changes: 16 additions & 0 deletions modules/util/file_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//go:build windows

package util

import (
"os"
)

func ApplyUmask(f string, newMode os.FileMode) error {
// do nothing for Windows, because Windows doesn't use umask
return nil
}
9 changes: 9 additions & 0 deletions options/license/checkmk
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2006, 2010 Micah Cowan
#
# Redistribution of this program in any form, with or without
# modifications, is permitted, provided that the above copyright is
# retained in distributions of this program in source form.
#
# (This is a free, non-copyleft license compatible with pretty much any
# other free or proprietary license, including the GPL. It's essentially
# a scaled-down version of the "modified" BSD license.)
1 change: 1 addition & 0 deletions options/locale/locale_ja-JP.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3092,6 +3092,7 @@ container.details.platform=プラットフォーム
container.details.repository_site=リポジトリサイト
container.details.documentation_site=ドキュメントサイト
container.pull=コマンドラインでイメージを取得します:
container.digest=ダイジェスト:
container.documentation=Container レジストリの詳細については、 <a target="_blank" rel="noopener noreferrer" href="https://docs.gitea.io/en-us/packages/container/">ドキュメント</a> を参照してください。
container.multi_arch=OS / アーキテクチャ
container.layers=イメージレイヤー
Expand Down
Loading

0 comments on commit 3107305

Please sign in to comment.