Skip to content

Commit bd7f5fc

Browse files
committed
Merge remote-tracking branch 'upstream/main'
* upstream/main: Use User.ID instead of User.Name in ActivityPub API for Person IRI (go-gitea#23823) Remove fomantic ".link" selector and styles (go-gitea#23888) [skip ci] Updated translations via Crowdin Fix `cases.Title` crash for concurrency (go-gitea#23885) Disable editing tags (go-gitea#23883) Fix user profile description rendering (go-gitea#23882) Introduce GiteaLocaleNumber custom element to handle number localization on pages. (go-gitea#23861) Convert .Source.SkipVerify to $cfg.SkipVerify (go-gitea#23839) Fix review box viewport overflow issue (go-gitea#23800) Fix owner team access mode value in team_unit table (go-gitea#23675) Fix submit button won't refresh in New Repository Fork page (go-gitea#22994) Introduce GitHub markdown editor, keep EasyMDE as fallback (go-gitea#23876) Improve LoadUnitConfig to handle invalid or duplicate units (go-gitea#23736) Append `(comment)` when a link points at a comment rather than the whole issue (go-gitea#23734) Rename actions unit to `repo.actions` and add docs for it (go-gitea#23733) Try to catch more broken translations (go-gitea#23867)
2 parents a6741d8 + 17f2318 commit bd7f5fc

File tree

95 files changed

+1169
-1217
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+1169
-1217
lines changed

build/backport-locales.go

+30-5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ func main() {
6262

6363
// use old en-US as the base, and copy the new translations to the old locales
6464
enUsOld := inisOld["options/locale/locale_en-US.ini"]
65+
brokenWarned := map[string]bool{}
6566
for path, iniOld := range inisOld {
6667
if iniOld == enUsOld {
6768
continue
@@ -77,11 +78,14 @@ func main() {
7778
if secNew.HasKey(keyEnUs.Name()) {
7879
oldStr := secOld.Key(keyEnUs.Name()).String()
7980
newStr := secNew.Key(keyEnUs.Name()).String()
80-
if oldStr != "" && strings.Count(oldStr, "%") != strings.Count(newStr, "%") {
81-
fmt.Printf("WARNING: locale %s [%s]%s has different number of arguments, skipping\n", path, secEnUS.Name(), keyEnUs.Name())
82-
fmt.Printf("\told: %s\n", oldStr)
83-
fmt.Printf("\tnew: %s\n", newStr)
84-
fmt.Println("---- ")
81+
broken := oldStr != "" && strings.Count(oldStr, "%") != strings.Count(newStr, "%")
82+
broken = broken || strings.Contains(oldStr, "\n") || strings.Contains(oldStr, "\n")
83+
if broken {
84+
brokenWarned[secOld.Name()+"."+keyEnUs.Name()] = true
85+
fmt.Println("----")
86+
fmt.Printf("WARNING: skip broken locale: %s , [%s] %s\n", path, secEnUS.Name(), keyEnUs.Name())
87+
fmt.Printf("\told: %s\n", strings.ReplaceAll(oldStr, "\n", "\\n"))
88+
fmt.Printf("\tnew: %s\n", strings.ReplaceAll(newStr, "\n", "\\n"))
8589
continue
8690
}
8791
secOld.Key(keyEnUs.Name()).SetValue(newStr)
@@ -90,4 +94,25 @@ func main() {
9094
}
9195
mustNoErr(iniOld.SaveTo(path))
9296
}
97+
98+
fmt.Println("========")
99+
100+
for path, iniNew := range inisNew {
101+
for _, sec := range iniNew.Sections() {
102+
for _, key := range sec.Keys() {
103+
str := sec.Key(key.Name()).String()
104+
broken := strings.Contains(str, "\n")
105+
broken = broken || strings.HasPrefix(str, "`") != strings.HasSuffix(str, "`")
106+
broken = broken || strings.HasPrefix(str, "\"`")
107+
broken = broken || strings.HasPrefix(str, "`\"")
108+
broken = broken || strings.Count(str, `"`)%2 == 1
109+
broken = broken || strings.Count(str, "`")%2 == 1
110+
if broken && !brokenWarned[sec.Name()+"."+key.Name()] {
111+
fmt.Printf("WARNING: found broken locale: %s , [%s] %s\n", path, sec.Name(), key.Name())
112+
fmt.Printf("\tstr: %s\n", strings.ReplaceAll(str, "\n", "\\n"))
113+
fmt.Println("----")
114+
}
115+
}
116+
}
117+
}
93118
}

custom/conf/app.example.ini

+2-2
Original file line numberDiff line numberDiff line change
@@ -947,10 +947,10 @@ ROUTER = console
947947
;USE_COMPAT_SSH_URI = false
948948
;;
949949
;; Close issues as long as a commit on any branch marks it as fixed
950-
;; Comma separated list of globally disabled repo units. Allowed values: repo.issues, repo.ext_issues, repo.pulls, repo.wiki, repo.ext_wiki, repo.projects, repo.packages
950+
;; Comma separated list of globally disabled repo units. Allowed values: repo.issues, repo.ext_issues, repo.pulls, repo.wiki, repo.ext_wiki, repo.projects, repo.packages, repo.actions.
951951
;DISABLED_REPO_UNITS =
952952
;;
953-
;; Comma separated list of default new repo units. Allowed values: repo.code, repo.releases, repo.issues, repo.pulls, repo.wiki, repo.projects, repo.packages.
953+
;; Comma separated list of default new repo units. Allowed values: repo.code, repo.releases, repo.issues, repo.pulls, repo.wiki, repo.projects, repo.packages, repo.actions.
954954
;; Note: Code and Releases can currently not be deactivated. If you specify default repo units you should still list them for future compatibility.
955955
;; External wiki and issue tracker can't be enabled by default as it requires additional settings.
956956
;; Disabled repo units will not be added to new repositories regardless if it is in the default list.

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ In addition there is _`StaticRootPath`_ which can be set as a built-in at build
103103
- `DEFAULT_CLOSE_ISSUES_VIA_COMMITS_IN_ANY_BRANCH`: **false**: Close an issue if a commit on a non default branch marks it as closed.
104104
- `ENABLE_PUSH_CREATE_USER`: **false**: Allow users to push local repositories to Gitea and have them automatically created for a user.
105105
- `ENABLE_PUSH_CREATE_ORG`: **false**: Allow users to push local repositories to Gitea and have them automatically created for an org.
106-
- `DISABLED_REPO_UNITS`: **_empty_**: Comma separated list of globally disabled repo units. Allowed values: \[repo.issues, repo.ext_issues, repo.pulls, repo.wiki, repo.ext_wiki, repo.projects\]
107-
- `DEFAULT_REPO_UNITS`: **repo.code,repo.releases,repo.issues,repo.pulls,repo.wiki,repo.projects,repo.packages**: Comma separated list of default new repo units. Allowed values: \[repo.code, repo.releases, repo.issues, repo.pulls, repo.wiki, repo.projects\]. Note: Code and Releases can currently not be deactivated. If you specify default repo units you should still list them for future compatibility. External wiki and issue tracker can't be enabled by default as it requires additional settings. Disabled repo units will not be added to new repositories regardless if it is in the default list.
106+
- `DISABLED_REPO_UNITS`: **_empty_**: Comma separated list of globally disabled repo units. Allowed values: \[repo.issues, repo.ext_issues, repo.pulls, repo.wiki, repo.ext_wiki, repo.projects, repo.packages, repo.actions\]
107+
- `DEFAULT_REPO_UNITS`: **repo.code,repo.releases,repo.issues,repo.pulls,repo.wiki,repo.projects,repo.packages**: Comma separated list of default new repo units. Allowed values: \[repo.code, repo.releases, repo.issues, repo.pulls, repo.wiki, repo.projects, repo.packages, repo.actions\]. Note: Code and Releases can currently not be deactivated. If you specify default repo units you should still list them for future compatibility. External wiki and issue tracker can't be enabled by default as it requires additional settings. Disabled repo units will not be added to new repositories regardless if it is in the default list.
108108
- `DEFAULT_FORK_REPO_UNITS`: **repo.code,repo.pulls**: Comma separated list of default forked repo units. The set of allowed values and rules is the same as `DEFAULT_REPO_UNITS`.
109109
- `PREFIX_ARCHIVE_FILES`: **true**: Prefix archive files by placing them in a directory named after the repository.
110110
- `DISABLE_MIGRATIONS`: **false**: Disable migrating feature.

models/migrations/migrations.go

+2
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,8 @@ var migrations = []Migration{
479479
NewMigration("Improve Action table indices v3", v1_20.ImproveActionTableIndices),
480480
// v250 -> v251
481481
NewMigration("Change Container Metadata", v1_20.ChangeContainerMetadataMultiArch),
482+
// v251 -> v252
483+
NewMigration("Fix incorrect owner team unit access mode", v1_20.FixIncorrectOwnerTeamUnitAccessMode),
482484
}
483485

484486
// GetCurrentDBVersion returns the current db version

models/migrations/v1_20/v251.go

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_20 //nolint
5+
6+
import (
7+
"code.gitea.io/gitea/modules/log"
8+
9+
"xorm.io/xorm"
10+
)
11+
12+
func FixIncorrectOwnerTeamUnitAccessMode(x *xorm.Engine) error {
13+
type UnitType int
14+
type AccessMode int
15+
16+
type TeamUnit struct {
17+
ID int64 `xorm:"pk autoincr"`
18+
OrgID int64 `xorm:"INDEX"`
19+
TeamID int64 `xorm:"UNIQUE(s)"`
20+
Type UnitType `xorm:"UNIQUE(s)"`
21+
AccessMode AccessMode
22+
}
23+
24+
const (
25+
// AccessModeOwner owner access
26+
AccessModeOwner = 4
27+
)
28+
29+
sess := x.NewSession()
30+
defer sess.Close()
31+
32+
if err := sess.Begin(); err != nil {
33+
return err
34+
}
35+
36+
count, err := sess.Table("team_unit").
37+
Where("team_id IN (SELECT id FROM team WHERE authorize = ?)", AccessModeOwner).
38+
Update(&TeamUnit{
39+
AccessMode: AccessModeOwner,
40+
})
41+
if err != nil {
42+
return err
43+
}
44+
log.Debug("Updated %d owner team unit access mode to belong to owner instead of none", count)
45+
46+
return sess.Commit()
47+
}

models/organization/org.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,10 @@ func CreateOrganization(org *Organization, owner *user_model.User) (err error) {
338338
units := make([]TeamUnit, 0, len(unit.AllRepoUnitTypes))
339339
for _, tp := range unit.AllRepoUnitTypes {
340340
units = append(units, TeamUnit{
341-
OrgID: org.ID,
342-
TeamID: t.ID,
343-
Type: tp,
341+
OrgID: org.ID,
342+
TeamID: t.ID,
343+
Type: tp,
344+
AccessMode: perm.AccessModeOwner,
344345
})
345346
}
346347

models/repo/release.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ type Release struct {
7979
RenderedNote string `xorm:"-"`
8080
IsDraft bool `xorm:"NOT NULL DEFAULT false"`
8181
IsPrerelease bool `xorm:"NOT NULL DEFAULT false"`
82-
IsTag bool `xorm:"NOT NULL DEFAULT false"`
82+
IsTag bool `xorm:"NOT NULL DEFAULT false"` // will be true only if the record is a tag and has no related releases
8383
Attachments []*Attachment `xorm:"-"`
8484
CreatedUnix timeutil.TimeStamp `xorm:"INDEX"`
8585
}

models/unit/unit.go

+24-17
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,11 @@ func validateDefaultRepoUnits(defaultUnits, settingDefaultUnits []Type) []Type {
151151

152152
// LoadUnitConfig load units from settings
153153
func LoadUnitConfig() {
154-
DisabledRepoUnits = FindUnitTypes(setting.Repository.DisabledRepoUnits...)
154+
var invalidKeys []string
155+
DisabledRepoUnits, invalidKeys = FindUnitTypes(setting.Repository.DisabledRepoUnits...)
156+
if len(invalidKeys) > 0 {
157+
log.Warn("Invalid keys in disabled repo units: %s", strings.Join(invalidKeys, ", "))
158+
}
155159
// Check that must units are not disabled
156160
for i, disabledU := range DisabledRepoUnits {
157161
if !disabledU.CanDisable() {
@@ -160,9 +164,15 @@ func LoadUnitConfig() {
160164
}
161165
}
162166

163-
setDefaultRepoUnits := FindUnitTypes(setting.Repository.DefaultRepoUnits...)
167+
setDefaultRepoUnits, invalidKeys := FindUnitTypes(setting.Repository.DefaultRepoUnits...)
168+
if len(invalidKeys) > 0 {
169+
log.Warn("Invalid keys in default repo units: %s", strings.Join(invalidKeys, ", "))
170+
}
164171
DefaultRepoUnits = validateDefaultRepoUnits(DefaultRepoUnits, setDefaultRepoUnits)
165-
setDefaultForkRepoUnits := FindUnitTypes(setting.Repository.DefaultForkRepoUnits...)
172+
setDefaultForkRepoUnits, invalidKeys := FindUnitTypes(setting.Repository.DefaultForkRepoUnits...)
173+
if len(invalidKeys) > 0 {
174+
log.Warn("Invalid keys in default fork repo units: %s", strings.Join(invalidKeys, ", "))
175+
}
166176
DefaultForkRepoUnits = validateDefaultRepoUnits(DefaultForkRepoUnits, setDefaultForkRepoUnits)
167177
}
168178

@@ -312,7 +322,7 @@ var (
312322

313323
UnitActions = Unit{
314324
TypeActions,
315-
"actions.actions",
325+
"repo.actions",
316326
"/actions",
317327
"actions.unit.desc",
318328
7,
@@ -334,22 +344,19 @@ var (
334344
}
335345
)
336346

337-
// FindUnitTypes give the unit key names and return unit
338-
func FindUnitTypes(nameKeys ...string) (res []Type) {
347+
// FindUnitTypes give the unit key names and return valid unique units and invalid keys
348+
func FindUnitTypes(nameKeys ...string) (res []Type, invalidKeys []string) {
349+
m := map[Type]struct{}{}
339350
for _, key := range nameKeys {
340-
var found bool
341-
for t, u := range Units {
342-
if strings.EqualFold(key, u.NameKey) {
343-
res = append(res, t)
344-
found = true
345-
break
346-
}
347-
}
348-
if !found {
349-
res = append(res, TypeInvalid)
351+
t := TypeFromKey(key)
352+
if t == TypeInvalid {
353+
invalidKeys = append(invalidKeys, key)
354+
} else if _, ok := m[t]; !ok {
355+
res = append(res, t)
356+
m[t] = struct{}{}
350357
}
351358
}
352-
return res
359+
return res, invalidKeys
353360
}
354361

355362
// TypeFromKey give the unit key name and return unit

models/unit/unit_test.go

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package unit
5+
6+
import (
7+
"testing"
8+
9+
"code.gitea.io/gitea/modules/setting"
10+
11+
"github.com/stretchr/testify/assert"
12+
)
13+
14+
func TestLoadUnitConfig(t *testing.T) {
15+
defer func(disabledRepoUnits, defaultRepoUnits, defaultForkRepoUnits []Type) {
16+
DisabledRepoUnits = disabledRepoUnits
17+
DefaultRepoUnits = defaultRepoUnits
18+
DefaultForkRepoUnits = defaultForkRepoUnits
19+
}(DisabledRepoUnits, DefaultRepoUnits, DefaultForkRepoUnits)
20+
defer func(disabledRepoUnits, defaultRepoUnits, defaultForkRepoUnits []string) {
21+
setting.Repository.DisabledRepoUnits = disabledRepoUnits
22+
setting.Repository.DefaultRepoUnits = defaultRepoUnits
23+
setting.Repository.DefaultForkRepoUnits = defaultForkRepoUnits
24+
}(setting.Repository.DisabledRepoUnits, setting.Repository.DefaultRepoUnits, setting.Repository.DefaultForkRepoUnits)
25+
26+
t.Run("regular", func(t *testing.T) {
27+
setting.Repository.DisabledRepoUnits = []string{"repo.issues"}
28+
setting.Repository.DefaultRepoUnits = []string{"repo.code", "repo.releases", "repo.issues", "repo.pulls"}
29+
setting.Repository.DefaultForkRepoUnits = []string{"repo.releases"}
30+
LoadUnitConfig()
31+
assert.Equal(t, []Type{TypeIssues}, DisabledRepoUnits)
32+
assert.Equal(t, []Type{TypeCode, TypeReleases, TypePullRequests}, DefaultRepoUnits)
33+
assert.Equal(t, []Type{TypeCode, TypeReleases}, DefaultForkRepoUnits)
34+
})
35+
t.Run("invalid", func(t *testing.T) {
36+
setting.Repository.DisabledRepoUnits = []string{"repo.issues", "invalid.1"}
37+
setting.Repository.DefaultRepoUnits = []string{"repo.code", "invalid.2", "repo.releases", "repo.issues", "repo.pulls"}
38+
setting.Repository.DefaultForkRepoUnits = []string{"invalid.3", "repo.releases"}
39+
LoadUnitConfig()
40+
assert.Equal(t, []Type{TypeIssues}, DisabledRepoUnits)
41+
assert.Equal(t, []Type{TypeCode, TypeReleases, TypePullRequests}, DefaultRepoUnits)
42+
assert.Equal(t, []Type{TypeCode, TypeReleases}, DefaultForkRepoUnits)
43+
})
44+
t.Run("duplicate", func(t *testing.T) {
45+
setting.Repository.DisabledRepoUnits = []string{"repo.issues", "repo.issues"}
46+
setting.Repository.DefaultRepoUnits = []string{"repo.code", "repo.releases", "repo.issues", "repo.pulls", "repo.code"}
47+
setting.Repository.DefaultForkRepoUnits = []string{"repo.releases", "repo.releases"}
48+
LoadUnitConfig()
49+
assert.Equal(t, []Type{TypeIssues}, DisabledRepoUnits)
50+
assert.Equal(t, []Type{TypeCode, TypeReleases, TypePullRequests}, DefaultRepoUnits)
51+
assert.Equal(t, []Type{TypeCode, TypeReleases}, DefaultForkRepoUnits)
52+
})
53+
}

modules/base/tool.go

-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"code.gitea.io/gitea/modules/git"
2323
"code.gitea.io/gitea/modules/log"
2424
"code.gitea.io/gitea/modules/setting"
25-
"code.gitea.io/gitea/modules/util"
2625

2726
"github.com/dustin/go-humanize"
2827
"github.com/minio/sha256-simd"
@@ -142,12 +141,6 @@ func FileSize(s int64) string {
142141
return humanize.IBytes(uint64(s))
143142
}
144143

145-
// PrettyNumber produces a string form of the given number in base 10 with
146-
// commas after every three orders of magnitude
147-
func PrettyNumber(i interface{}) string {
148-
return humanize.Comma(util.NumberIntoInt64(i))
149-
}
150-
151144
// Subtract deals with subtraction of all types of number.
152145
func Subtract(left, right interface{}) interface{} {
153146
var rleft, rright int64

modules/base/tool_test.go

-7
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,6 @@ func TestFileSize(t *testing.T) {
114114
assert.Equal(t, "2.0 EiB", FileSize(size))
115115
}
116116

117-
func TestPrettyNumber(t *testing.T) {
118-
assert.Equal(t, "23,342,432", PrettyNumber(23342432))
119-
assert.Equal(t, "23,342,432", PrettyNumber(int32(23342432)))
120-
assert.Equal(t, "0", PrettyNumber(0))
121-
assert.Equal(t, "-100,000", PrettyNumber(-100000))
122-
}
123-
124117
func TestSubtract(t *testing.T) {
125118
toFloat64 := func(n interface{}) float64 {
126119
switch v := n.(type) {

modules/context/context.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,9 @@ func (ctx *Context) Value(key interface{}) interface{} {
628628
if key == git.RepositoryContextKey && ctx.Repo != nil {
629629
return ctx.Repo.GitRepo
630630
}
631-
631+
if key == translation.ContextKey && ctx.Locale != nil {
632+
return ctx.Locale
633+
}
632634
return ctx.Req.Context().Value(key)
633635
}
634636

0 commit comments

Comments
 (0)