Skip to content

Commit de5074c

Browse files
committed
Merge remote-tracking branch 'origin/main' into overflow-menu
* origin/main: (29 commits) Tweak actions color and borders (go-gitea#29640) Add download URL for executable files (go-gitea#28260) Move all login and account creation page labels to be above inputs (go-gitea#29432) Avoid issue info panic (go-gitea#29625) Cache repository default branch commit status to reduce query on commit status table (go-gitea#29444) Avoid unexpected panic in graceful manager (go-gitea#29629) Add a link for the recently pushed branch notification (go-gitea#29627) Fix wrong header of org project view page (go-gitea#29626) Detect broken git hooks (go-gitea#29494) Sync branches to DB immediately when handle git hook calling (go-gitea#29493) Fix wrong line number in code search result (go-gitea#29260) Make wiki default branch name changable (go-gitea#29603) A small refactor for agit implementation (go-gitea#29614) Update Twitter Logo (go-gitea#29621) Fix 500 error when adding PR comment (go-gitea#29622) Run editorconfig-checker on `locale_en-US.ini` (go-gitea#29608) bump protobuf module (go-gitea#29617) Add ac claim for old docker/build-push-action@v3 / current buildx gha cache (go-gitea#29584) Skip email domain check when admins edit user emails (go-gitea#29609) Improve natural sort (go-gitea#29611) ...
2 parents 8718035 + 16f1326 commit de5074c

File tree

109 files changed

+1246
-627
lines changed

Some content is hidden

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

109 files changed

+1246
-627
lines changed

.github/workflows/files-changed.yml

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ jobs:
4848
- "Makefile"
4949
- ".golangci.yml"
5050
- ".editorconfig"
51+
- "options/locale/locale_en-US.ini"
5152
5253
frontend:
5354
- "**/*.js"

Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ GO_DIRS := build cmd models modules routers services tests
147147
WEB_DIRS := web_src/js web_src/css
148148

149149
SPELLCHECK_FILES := $(GO_DIRS) $(WEB_DIRS) docs/content templates options/locale/locale_en-US.ini .github
150+
EDITORCONFIG_FILES := templates .github/workflows options/locale/locale_en-US.ini
150151

151152
GO_SOURCES := $(wildcard *.go)
152153
GO_SOURCES += $(shell find $(GO_DIRS) -type f -name "*.go" ! -path modules/options/bindata.go ! -path modules/public/bindata.go ! -path modules/templates/bindata.go)
@@ -426,7 +427,7 @@ lint-go-vet:
426427

427428
.PHONY: lint-editorconfig
428429
lint-editorconfig:
429-
$(GO) run $(EDITORCONFIG_CHECKER_PACKAGE) templates .github/workflows
430+
@$(GO) run $(EDITORCONFIG_CHECKER_PACKAGE) $(EDITORCONFIG_FILES)
430431

431432
.PHONY: lint-actions
432433
lint-actions:

docs/content/contributing/guidelines-frontend.en-us.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ We recommend [Google HTML/CSS Style Guide](https://google.github.io/styleguide/h
4747
9. Avoid unnecessary `!important` in CSS, add comments to explain why it's necessary if it can't be avoided.
4848
10. Avoid mixing different events in one event listener, prefer to use individual event listeners for every event.
4949
11. Custom event names are recommended to use `ce-` prefix.
50-
12. Gitea's tailwind-style CSS classes use `gt-` prefix (`gt-relative`), while Gitea's own private framework-level CSS classes use `g-` prefix (`g-modal-confirm`).
50+
12. Prefer using Tailwind CSS which is available via `tw-` prefix, e.g. `tw-relative`. Gitea's helper CSS classes use `gt-` prefix (`gt-df`), while Gitea's own private framework-level CSS classes use `g-` prefix (`g-modal-confirm`).
5151
13. Avoid inline scripts & styles as much as possible, it's recommended to put JS code into JS files and use CSS classes. If inline scripts & styles are unavoidable, explain the reason why it can't be avoided.
5252

5353
### Accessibility / ARIA

docs/content/contributing/guidelines-frontend.zh-cn.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ HTML 页面由[Go HTML Template](https://pkg.go.dev/html/template)渲染。
4747
9. 避免在 CSS 中使用不必要的`!important`,如果无法避免,添加注释解释为什么需要它。
4848
10. 避免在一个事件监听器中混合不同的事件,优先为每个事件使用独立的事件监听器。
4949
11. 推荐使用自定义事件名称前缀`ce-`
50-
12. Gitea 的 tailwind-style CSS 类使用`gt-`前缀(`gt-relative`),Gitea 自身的私有框架级 CSS 类使用`g-`前缀(`g-modal-confirm`)。
50+
12. 建议使用 Tailwind CSS,它可以通过 `tw-` 前缀获得,例如 `tw-relative`. Gitea 自身的助手类 CSS 使用 `gt-` 前缀(`gt-df`),Gitea 自身的私有框架级 CSS 类使用 `g-` 前缀(`g-modal-confirm`)。
5151
13. 尽量避免内联脚本和样式,建议将JS代码放入JS文件中并使用CSS类。如果内联脚本和样式不可避免,请解释无法避免的原因。
5252

5353
### 可访问性 / ARIA

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ require (
113113
golang.org/x/text v0.14.0
114114
golang.org/x/tools v0.17.0
115115
google.golang.org/grpc v1.60.1
116-
google.golang.org/protobuf v1.32.0
116+
google.golang.org/protobuf v1.33.0
117117
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
118118
gopkg.in/ini.v1 v1.67.0
119119
gopkg.in/yaml.v3 v3.0.1

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -1308,8 +1308,8 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba
13081308
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
13091309
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
13101310
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
1311-
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
1312-
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
1311+
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
1312+
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
13131313
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc h1:2gGKlE2+asNV9m7xrywl36YYNnBG5ZQ0r/BOOxqPpmk=
13141314
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc/go.mod h1:m7x9LTH6d71AHyAX77c9yqWCCa3UKHcVEj9y7hAtKDk=
13151315
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

models/activities/action.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,14 @@ func (a *Action) GetCreate() time.Time {
393393
return a.CreatedUnix.AsTime()
394394
}
395395

396-
// GetIssueInfos returns a list of issues associated with
397-
// the action.
396+
// GetIssueInfos returns a list of associated information with the action.
398397
func (a *Action) GetIssueInfos() []string {
399-
return strings.SplitN(a.Content, "|", 3)
398+
// make sure it always returns 3 elements, because there are some access to the a[1] and a[2] without checking the length
399+
ret := strings.SplitN(a.Content, "|", 3)
400+
for len(ret) < 3 {
401+
ret = append(ret, "")
402+
}
403+
return ret
400404
}
401405

402406
// GetIssueTitle returns the title of first issue associated with the action.

models/git/branch.go

+5
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ func GetBranch(ctx context.Context, repoID int64, branchName string) (*Branch, e
158158
return &branch, nil
159159
}
160160

161+
func GetBranches(ctx context.Context, repoID int64, branchNames []string) ([]*Branch, error) {
162+
branches := make([]*Branch, 0, len(branchNames))
163+
return branches, db.GetEngine(ctx).Where("repo_id=?", repoID).In("name", branchNames).Find(&branches)
164+
}
165+
161166
func AddBranches(ctx context.Context, branches []*Branch) error {
162167
for _, branch := range branches {
163168
if _, err := db.GetEngine(ctx).Insert(branch); err != nil {

models/migrations/migrations.go

+2
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,8 @@ var migrations = []Migration{
562562
NewMigration("Use Slug instead of ID for Badges", v1_22.UseSlugInsteadOfIDForBadges),
563563
// v288 -> v289
564564
NewMigration("Add user_blocking table", v1_22.AddUserBlockingTable),
565+
// v289 -> v290
566+
NewMigration("Add default_wiki_branch to repository table", v1_22.AddDefaultWikiBranch),
565567
}
566568

567569
// GetCurrentDBVersion returns the current db version

models/migrations/v1_22/v289.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2024 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_22 //nolint
5+
6+
import "xorm.io/xorm"
7+
8+
func AddDefaultWikiBranch(x *xorm.Engine) error {
9+
type Repository struct {
10+
ID int64
11+
DefaultWikiBranch string
12+
}
13+
if err := x.Sync(&Repository{}); err != nil {
14+
return err
15+
}
16+
_, err := x.Exec("UPDATE `repository` SET default_wiki_branch = 'master' WHERE (default_wiki_branch IS NULL) OR (default_wiki_branch = '')")
17+
return err
18+
}

models/repo/repo.go

+4
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ type Repository struct {
136136
OriginalServiceType api.GitServiceType `xorm:"index"`
137137
OriginalURL string `xorm:"VARCHAR(2048)"`
138138
DefaultBranch string
139+
DefaultWikiBranch string
139140

140141
NumWatches int
141142
NumStars int
@@ -285,6 +286,9 @@ func (repo *Repository) AfterLoad() {
285286
repo.NumOpenMilestones = repo.NumMilestones - repo.NumClosedMilestones
286287
repo.NumOpenProjects = repo.NumProjects - repo.NumClosedProjects
287288
repo.NumOpenActionRuns = repo.NumActionRuns - repo.NumClosedActionRuns
289+
if repo.DefaultWikiBranch == "" {
290+
repo.DefaultWikiBranch = setting.Repository.DefaultBranch
291+
}
288292
}
289293

290294
// LoadAttributes loads attributes of the repository.

models/user/email_address.go

+47-28
Original file line numberDiff line numberDiff line change
@@ -154,37 +154,18 @@ func UpdateEmailAddress(ctx context.Context, email *EmailAddress) error {
154154

155155
var emailRegexp = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]*@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")
156156

157-
// ValidateEmail check if email is a allowed address
157+
// ValidateEmail check if email is a valid & allowed address
158158
func ValidateEmail(email string) error {
159-
if len(email) == 0 {
160-
return ErrEmailInvalid{email}
161-
}
162-
163-
if !emailRegexp.MatchString(email) {
164-
return ErrEmailCharIsNotSupported{email}
165-
}
166-
167-
if email[0] == '-' {
168-
return ErrEmailInvalid{email}
169-
}
170-
171-
if _, err := mail.ParseAddress(email); err != nil {
172-
return ErrEmailInvalid{email}
173-
}
174-
175-
// if there is no allow list, then check email against block list
176-
if len(setting.Service.EmailDomainAllowList) == 0 &&
177-
validation.IsEmailDomainListed(setting.Service.EmailDomainBlockList, email) {
178-
return ErrEmailInvalid{email}
179-
}
180-
181-
// if there is an allow list, then check email against allow list
182-
if len(setting.Service.EmailDomainAllowList) > 0 &&
183-
!validation.IsEmailDomainListed(setting.Service.EmailDomainAllowList, email) {
184-
return ErrEmailInvalid{email}
159+
if err := validateEmailBasic(email); err != nil {
160+
return err
185161
}
162+
return validateEmailDomain(email)
163+
}
186164

187-
return nil
165+
// ValidateEmailForAdmin check if email is a valid address when admins manually add or edit users
166+
func ValidateEmailForAdmin(email string) error {
167+
return validateEmailBasic(email)
168+
// In this case we do not need to check the email domain
188169
}
189170

190171
func GetEmailAddressByEmail(ctx context.Context, email string) (*EmailAddress, error) {
@@ -534,3 +515,41 @@ func ActivateUserEmail(ctx context.Context, userID int64, email string, activate
534515

535516
return committer.Commit()
536517
}
518+
519+
// validateEmailBasic checks whether the email complies with the rules
520+
func validateEmailBasic(email string) error {
521+
if len(email) == 0 {
522+
return ErrEmailInvalid{email}
523+
}
524+
525+
if !emailRegexp.MatchString(email) {
526+
return ErrEmailCharIsNotSupported{email}
527+
}
528+
529+
if email[0] == '-' {
530+
return ErrEmailInvalid{email}
531+
}
532+
533+
if _, err := mail.ParseAddress(email); err != nil {
534+
return ErrEmailInvalid{email}
535+
}
536+
537+
return nil
538+
}
539+
540+
// validateEmailDomain checks whether the email domain is allowed or blocked
541+
func validateEmailDomain(email string) error {
542+
// if there is no allow list, then check email against block list
543+
if len(setting.Service.EmailDomainAllowList) == 0 &&
544+
validation.IsEmailDomainListed(setting.Service.EmailDomainBlockList, email) {
545+
return ErrEmailInvalid{email}
546+
}
547+
548+
// if there is an allow list, then check email against allow list
549+
if len(setting.Service.EmailDomainAllowList) > 0 &&
550+
!validation.IsEmailDomainListed(setting.Service.EmailDomainAllowList, email) {
551+
return ErrEmailInvalid{email}
552+
}
553+
554+
return nil
555+
}

models/user/user.go

+18-2
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,16 @@ type CreateUserOverwriteOptions struct {
586586

587587
// CreateUser creates record of a new user.
588588
func CreateUser(ctx context.Context, u *User, overwriteDefault ...*CreateUserOverwriteOptions) (err error) {
589+
return createUser(ctx, u, false, overwriteDefault...)
590+
}
591+
592+
// AdminCreateUser is used by admins to manually create users
593+
func AdminCreateUser(ctx context.Context, u *User, overwriteDefault ...*CreateUserOverwriteOptions) (err error) {
594+
return createUser(ctx, u, true, overwriteDefault...)
595+
}
596+
597+
// createUser creates record of a new user.
598+
func createUser(ctx context.Context, u *User, createdByAdmin bool, overwriteDefault ...*CreateUserOverwriteOptions) (err error) {
589599
if err = IsUsableUsername(u.Name); err != nil {
590600
return err
591601
}
@@ -639,8 +649,14 @@ func CreateUser(ctx context.Context, u *User, overwriteDefault ...*CreateUserOve
639649
return err
640650
}
641651

642-
if err := ValidateEmail(u.Email); err != nil {
643-
return err
652+
if createdByAdmin {
653+
if err := ValidateEmailForAdmin(u.Email); err != nil {
654+
return err
655+
}
656+
} else {
657+
if err := ValidateEmail(u.Email); err != nil {
658+
return err
659+
}
644660
}
645661

646662
ctx, committer, err := db.TxContext(ctx)

modules/base/natural_sort.go

+4-77
Original file line numberDiff line numberDiff line change
@@ -4,85 +4,12 @@
44
package base
55

66
import (
7-
"math/big"
8-
"unicode/utf8"
7+
"golang.org/x/text/collate"
8+
"golang.org/x/text/language"
99
)
1010

1111
// NaturalSortLess compares two strings so that they could be sorted in natural order
1212
func NaturalSortLess(s1, s2 string) bool {
13-
var i1, i2 int
14-
for {
15-
rune1, j1, end1 := getNextRune(s1, i1)
16-
rune2, j2, end2 := getNextRune(s2, i2)
17-
if end1 || end2 {
18-
return end1 != end2 && end1
19-
}
20-
dec1 := isDecimal(rune1)
21-
dec2 := isDecimal(rune2)
22-
var less, equal bool
23-
if dec1 && dec2 {
24-
i1, i2, less, equal = compareByNumbers(s1, i1, s2, i2)
25-
} else if !dec1 && !dec2 {
26-
equal = rune1 == rune2
27-
less = rune1 < rune2
28-
i1 = j1
29-
i2 = j2
30-
} else {
31-
return rune1 < rune2
32-
}
33-
if !equal {
34-
return less
35-
}
36-
}
37-
}
38-
39-
func getNextRune(str string, pos int) (rune, int, bool) {
40-
if pos < len(str) {
41-
r, w := utf8.DecodeRuneInString(str[pos:])
42-
// Fallback to ascii
43-
if r == utf8.RuneError {
44-
r = rune(str[pos])
45-
w = 1
46-
}
47-
return r, pos + w, false
48-
}
49-
return 0, pos, true
50-
}
51-
52-
func isDecimal(r rune) bool {
53-
return '0' <= r && r <= '9'
54-
}
55-
56-
func compareByNumbers(str1 string, pos1 int, str2 string, pos2 int) (i1, i2 int, less, equal bool) {
57-
d1, d2 := true, true
58-
var dec1, dec2 string
59-
for d1 || d2 {
60-
if d1 {
61-
r, j, end := getNextRune(str1, pos1)
62-
if !end && isDecimal(r) {
63-
dec1 += string(r)
64-
pos1 = j
65-
} else {
66-
d1 = false
67-
}
68-
}
69-
if d2 {
70-
r, j, end := getNextRune(str2, pos2)
71-
if !end && isDecimal(r) {
72-
dec2 += string(r)
73-
pos2 = j
74-
} else {
75-
d2 = false
76-
}
77-
}
78-
}
79-
less, equal = compareBigNumbers(dec1, dec2)
80-
return pos1, pos2, less, equal
81-
}
82-
83-
func compareBigNumbers(dec1, dec2 string) (less, equal bool) {
84-
d1, _ := big.NewInt(0).SetString(dec1, 10)
85-
d2, _ := big.NewInt(0).SetString(dec2, 10)
86-
cmp := d1.Cmp(d2)
87-
return cmp < 0, cmp == 0
13+
c := collate.New(language.English, collate.Numeric)
14+
return c.CompareString(s1, s2) < 0
8815
}

modules/base/natural_sort_test.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
func TestNaturalSortLess(t *testing.T) {
1313
test := func(s1, s2 string, less bool) {
14-
assert.Equal(t, less, NaturalSortLess(s1, s2))
14+
assert.Equal(t, less, NaturalSortLess(s1, s2), "s1=%q, s2=%q", s1, s2)
1515
}
1616
test("v1.20.0", "v1.2.0", false)
1717
test("v1.20.0", "v1.29.0", true)
@@ -20,4 +20,11 @@ func TestNaturalSortLess(t *testing.T) {
2020
test("a-1-a", "a-1-b", true)
2121
test("2", "12", true)
2222
test("a", "ab", true)
23+
24+
test("A", "b", true)
25+
test("a", "B", true)
26+
27+
test("cafe", "café", true)
28+
test("café", "cafe", false)
29+
test("caff", "café", false)
2330
}

modules/git/repo_base_gogit.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ package git
88

99
import (
1010
"context"
11-
"errors"
1211
"path/filepath"
1312

1413
gitealog "code.gitea.io/gitea/modules/log"
1514
"code.gitea.io/gitea/modules/setting"
15+
"code.gitea.io/gitea/modules/util"
1616

1717
"github.com/go-git/go-billy/v5"
1818
"github.com/go-git/go-billy/v5/osfs"
@@ -52,7 +52,7 @@ func OpenRepository(ctx context.Context, repoPath string) (*Repository, error) {
5252
if err != nil {
5353
return nil, err
5454
} else if !isDir(repoPath) {
55-
return nil, errors.New("no such file or directory")
55+
return nil, util.NewNotExistErrorf("no such file or directory")
5656
}
5757

5858
fs := osfs.New(repoPath)

0 commit comments

Comments
 (0)