diff options
author | silverwind <me@silverwind.io> | 2022-05-10 23:55:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-10 23:55:54 +0200 |
commit | 318f360252777c6eb819ab206a1f276fa4969f3a (patch) | |
tree | 7a73ede2df5b52be940dd9b4005137c1d5d53c04 /modules | |
parent | 3c658dff233e791856496761325f5ebf787d7521 (diff) | |
download | gitea-318f360252777c6eb819ab206a1f276fa4969f3a.tar.gz gitea-318f360252777c6eb819ab206a1f276fa4969f3a.zip |
Update go tool dependencies (#19676)
* Update go tool dependencies
Updated all tool dependencies to latest tags, hoping CI will like it.
* fix new lint errors
* handle more strings.Title cases
* remove lint skip
Diffstat (limited to 'modules')
-rw-r--r-- | modules/repository/generate.go | 2 | ||||
-rw-r--r-- | modules/setting/log.go | 5 | ||||
-rw-r--r-- | modules/templates/helper.go | 4 | ||||
-rw-r--r-- | modules/util/util.go | 10 | ||||
-rw-r--r-- | modules/util/util_test.go | 5 |
5 files changed, 21 insertions, 5 deletions
diff --git a/modules/repository/generate.go b/modules/repository/generate.go index 1436d764f0..b3ce809173 100644 --- a/modules/repository/generate.go +++ b/modules/repository/generate.go @@ -43,7 +43,7 @@ var defaultTransformers = []transformer{ {Name: "PASCAL", Transform: xstrings.ToCamelCase}, {Name: "LOWER", Transform: strings.ToLower}, {Name: "UPPER", Transform: strings.ToUpper}, - {Name: "TITLE", Transform: strings.Title}, + {Name: "TITLE", Transform: util.ToTitleCase}, } func generateExpansion(src string, templateRepo, generateRepo *repo_model.Repository) string { diff --git a/modules/setting/log.go b/modules/setting/log.go index 008a419b09..d69b5c6888 100644 --- a/modules/setting/log.go +++ b/modules/setting/log.go @@ -15,6 +15,7 @@ import ( "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/util" ini "gopkg.in/ini.v1" ) @@ -245,7 +246,7 @@ func generateNamedLogger(key string, options defaultLogOptions) *LogDescription Provider: provider, Config: config, }) - log.Info("%s Log: %s(%s:%s)", strings.Title(key), strings.Title(name), provider, levelName) + log.Info("%s Log: %s(%s:%s)", util.ToTitleCase(key), util.ToTitleCase(name), provider, levelName) } AddLogDescription(key, &description) @@ -331,7 +332,7 @@ func newLogService() { Provider: provider, Config: config, }) - log.Info("Gitea Log Mode: %s(%s:%s)", strings.Title(name), strings.Title(provider), levelName) + log.Info("Gitea Log Mode: %s(%s:%s)", util.ToTitleCase(name), util.ToTitleCase(provider), levelName) } AddLogDescription(log.DEFAULT, &description) diff --git a/modules/templates/helper.go b/modules/templates/helper.go index 682459d94a..1ee9cb00e0 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -52,7 +52,7 @@ var mailSubjectSplit = regexp.MustCompile(`(?m)^-{3,}[\s]*$`) func NewFuncMap() []template.FuncMap { return []template.FuncMap{map[string]interface{}{ "GoVer": func() string { - return strings.Title(runtime.Version()) + return util.ToTitleCase(runtime.Version()) }, "UseHTTPS": func() bool { return strings.HasPrefix(setting.AppURL, "https") @@ -398,7 +398,7 @@ func NewFuncMap() []template.FuncMap { func NewTextFuncMap() []texttmpl.FuncMap { return []texttmpl.FuncMap{map[string]interface{}{ "GoVer": func() string { - return strings.Title(runtime.Version()) + return util.ToTitleCase(runtime.Version()) }, "AppName": func() string { return setting.AppName diff --git a/modules/util/util.go b/modules/util/util.go index af6581f7cd..351a345473 100644 --- a/modules/util/util.go +++ b/modules/util/util.go @@ -11,6 +11,9 @@ import ( "math/big" "strconv" "strings" + + "golang.org/x/text/cases" + "golang.org/x/text/language" ) // OptionalBool a boolean that can be "null" @@ -181,3 +184,10 @@ func ToUpperASCII(s string) string { } return string(b) } + +var titleCaser = cases.Title(language.English) + +// ToTitleCase returns s with all english words capitalized +func ToTitleCase(s string) string { + return titleCaser.String(s) +} diff --git a/modules/util/util_test.go b/modules/util/util_test.go index 0c2792a9cb..ca5bd87eae 100644 --- a/modules/util/util_test.go +++ b/modules/util/util_test.go @@ -220,3 +220,8 @@ func BenchmarkToUpper(b *testing.B) { }) } } + +func TestToTitleCase(t *testing.T) { + assert.Equal(t, ToTitleCase(`foo bar baz`), `Foo Bar Baz`) + assert.Equal(t, ToTitleCase(`FOO BAR BAZ`), `Foo Bar Baz`) +} |