Skip to content

Commit d51ac9b

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Fix JS error when opening to expanded code comment (go-gitea#30463) fix: Fix to delete cookie when AppSubURL is non-empty (go-gitea#30375) Add `interface{}` to `any` replacement to `make fmt`, exclude `*.pb.go` (go-gitea#30461) Fix network error when open/close organization/individual projects and redirect to project page (go-gitea#30387) Avoid losing token when updating mirror settings (go-gitea#30429) Fix label rendering (go-gitea#30456) Add comment for ContainsRedirectURI about the exact match (go-gitea#30457) Update JS and PY deps, lock eslint and related plugins (go-gitea#30452) Refactor cache and disable go-chi cache (go-gitea#30417) Fix admin notice view-detail (go-gitea#30450) Fix mirror error when mirror repo is empty (go-gitea#30432) Add `/public/assets/img/webpack` to ignore files again (go-gitea#30451) Lock a few tool dependencies to major versions (go-gitea#30439) Fix commit status cache which missed target_url (go-gitea#30426) Remove jQuery from the commit graph (except Fomantic) (go-gitea#30395) Fix rename branch 500 when the target branch is deleted but exist in database (go-gitea#30430) Limit the max line length when parsing git grep output (go-gitea#30418)
2 parents 3bcab84 + ce130ae commit d51ac9b

Some content is hidden

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

47 files changed

+861
-658
lines changed

.dockerignore

+3
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ cpu.out
9595
/.air
9696
/.go-licenses
9797

98+
# Files and folders that were previously generated
99+
/public/assets/img/webpack
100+
98101
# Snapcraft
99102
snap/.snapcraft/
100103
parts/

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
* text=auto eol=lf
22
*.tmpl linguist-language=Handlebars
3+
*.pb.go linguist-generated
34
/assets/*.json linguist-generated
45
/public/assets/img/svg/*.svg linguist-generated
56
/templates/swagger/v1_json.tmpl linguist-generated

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ cpu.out
9494
/.air
9595
/.go-licenses
9696

97+
# Files and folders that were previously generated
98+
/public/assets/img/webpack
99+
97100
# Snapcraft
98101
/gitea_a*.txt
99102
snap/.snapcraft/

.golangci.yml

+2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ linters-settings:
8686
desc: do not use the internal package, use AddXxx function instead
8787
- pkg: gopkg.in/ini.v1
8888
desc: do not use the ini package, use gitea's config system instead
89+
- pkg: gitea.com/go-chi/cache
90+
desc: do not use the go-chi cache package, use gitea's cache system
8991

9092
issues:
9193
max-issues-per-linter: 0

Makefile

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ COMMA := ,
2525

2626
XGO_VERSION := go-1.22.x
2727

28-
AIR_PACKAGE ?= github.com/cosmtrek/air@v1.49.0
28+
AIR_PACKAGE ?= github.com/cosmtrek/air@v1
2929
EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/cmd/editorconfig-checker@2.7.0
3030
GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@v0.6.0
3131
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.57.2
3232
GXZ_PACKAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.11
3333
MISSPELL_PACKAGE ?= github.com/golangci/misspell/cmd/misspell@v0.4.1
3434
SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/swagger@db51e79a0e37c572d8b59ae0c58bf2bbbbe53285
3535
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
36-
GO_LICENSES_PACKAGE ?= github.com/google/go-licenses@v1.6.0
37-
GOVULNCHECK_PACKAGE ?= golang.org/x/vuln/cmd/govulncheck@v1.0.3
38-
ACTIONLINT_PACKAGE ?= github.com/rhysd/actionlint/cmd/actionlint@v1.6.26
36+
GO_LICENSES_PACKAGE ?= github.com/google/go-licenses@v1
37+
GOVULNCHECK_PACKAGE ?= golang.org/x/vuln/cmd/govulncheck@v1
38+
ACTIONLINT_PACKAGE ?= github.com/rhysd/actionlint/cmd/actionlint@v1
3939

4040
DOCKER_IMAGE ?= gitea/gitea
4141
DOCKER_TAG ?= latest
@@ -295,7 +295,7 @@ clean:
295295

296296
.PHONY: fmt
297297
fmt:
298-
GOFUMPT_PACKAGE=$(GOFUMPT_PACKAGE) $(GO) run build/code-batch-process.go gitea-fmt -w '{file-list}'
298+
@GOFUMPT_PACKAGE=$(GOFUMPT_PACKAGE) $(GO) run build/code-batch-process.go gitea-fmt -w '{file-list}'
299299
$(eval TEMPLATES := $(shell find templates -type f -name '*.tmpl'))
300300
@# strip whitespace after '{{' or '(' and before '}}' or ')' unless there is only
301301
@# whitespace before it

build/code-batch-process.go

+3-12
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func newFileCollector(fileFilter string, batchSize int) (*fileCollector, error)
6969
co.includePatterns = append(co.includePatterns, regexp.MustCompile(`.*\.go$`))
7070

7171
co.excludePatterns = append(co.excludePatterns, regexp.MustCompile(`.*\bbindata\.go$`))
72+
co.excludePatterns = append(co.excludePatterns, regexp.MustCompile(`\.pb\.go$`))
7273
co.excludePatterns = append(co.excludePatterns, regexp.MustCompile(`tests/gitea-repositories-meta`))
7374
co.excludePatterns = append(co.excludePatterns, regexp.MustCompile(`tests/integration/migration-test`))
7475
co.excludePatterns = append(co.excludePatterns, regexp.MustCompile(`modules/git/tests`))
@@ -203,17 +204,6 @@ Example:
203204
`, "file-batch-exec")
204205
}
205206

206-
func getGoVersion() string {
207-
goModFile, err := os.ReadFile("go.mod")
208-
if err != nil {
209-
log.Fatalf(`Faild to read "go.mod": %v`, err)
210-
os.Exit(1)
211-
}
212-
goModVersionRegex := regexp.MustCompile(`go \d+\.\d+`)
213-
goModVersionLine := goModVersionRegex.Find(goModFile)
214-
return string(goModVersionLine[3:])
215-
}
216-
217207
func newFileCollectorFromMainOptions(mainOptions map[string]string) (fc *fileCollector, err error) {
218208
fileFilter := mainOptions["file-filter"]
219209
if fileFilter == "" {
@@ -278,7 +268,8 @@ func main() {
278268
log.Print("the -d option is not supported by gitea-fmt")
279269
}
280270
cmdErrors = append(cmdErrors, giteaFormatGoImports(files, containsString(subArgs, "-w")))
281-
cmdErrors = append(cmdErrors, passThroughCmd("go", append([]string{"run", os.Getenv("GOFUMPT_PACKAGE"), "-extra", "-lang", getGoVersion()}, substArgs...)))
271+
cmdErrors = append(cmdErrors, passThroughCmd("gofmt", append([]string{"-w", "-r", "interface{} -> any"}, substArgs...)))
272+
cmdErrors = append(cmdErrors, passThroughCmd("go", append([]string{"run", os.Getenv("GOFUMPT_PACKAGE"), "-extra"}, substArgs...)))
282273
default:
283274
log.Fatalf("unknown cmd: %s %v", subCmd, subArgs)
284275
}

models/auth/oauth2.go

+5
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ func (app *OAuth2Application) TableName() string {
137137

138138
// ContainsRedirectURI checks if redirectURI is allowed for app
139139
func (app *OAuth2Application) ContainsRedirectURI(redirectURI string) bool {
140+
// OAuth2 requires the redirect URI to be an exact match, no dynamic parts are allowed.
141+
// https://stackoverflow.com/questions/55524480/should-dynamic-query-parameters-be-present-in-the-redirection-uri-for-an-oauth2
142+
// https://www.rfc-editor.org/rfc/rfc6819#section-5.2.3.3
143+
// https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest
144+
// https://datatracker.ietf.org/doc/html/draft-ietf-oauth-security-topics-12#section-3.1
140145
contains := func(s string) bool {
141146
s = strings.TrimSuffix(strings.ToLower(s), "/")
142147
for _, u := range app.RedirectURIs {

models/git/branch.go

+25-6
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ func RenameBranch(ctx context.Context, repo *repo_model.Repository, from, to str
297297

298298
sess := db.GetEngine(ctx)
299299

300+
// check whether from branch exist
300301
var branch Branch
301302
exist, err := db.GetEngine(ctx).Where("repo_id=? AND name=?", repo.ID, from).Get(&branch)
302303
if err != nil {
@@ -308,6 +309,24 @@ func RenameBranch(ctx context.Context, repo *repo_model.Repository, from, to str
308309
}
309310
}
310311

312+
// check whether to branch exist or is_deleted
313+
var dstBranch Branch
314+
exist, err = db.GetEngine(ctx).Where("repo_id=? AND name=?", repo.ID, to).Get(&dstBranch)
315+
if err != nil {
316+
return err
317+
}
318+
if exist {
319+
if !dstBranch.IsDeleted {
320+
return ErrBranchAlreadyExists{
321+
BranchName: to,
322+
}
323+
}
324+
325+
if _, err := db.GetEngine(ctx).ID(dstBranch.ID).NoAutoCondition().Delete(&dstBranch); err != nil {
326+
return err
327+
}
328+
}
329+
311330
// 1. update branch in database
312331
if n, err := sess.Where("repo_id=? AND name=?", repo.ID, from).Update(&Branch{
313332
Name: to,
@@ -362,12 +381,7 @@ func RenameBranch(ctx context.Context, repo *repo_model.Repository, from, to str
362381
return err
363382
}
364383

365-
// 5. do git action
366-
if err = gitAction(ctx, isDefault); err != nil {
367-
return err
368-
}
369-
370-
// 6. insert renamed branch record
384+
// 5. insert renamed branch record
371385
renamedBranch := &RenamedBranch{
372386
RepoID: repo.ID,
373387
From: from,
@@ -378,6 +392,11 @@ func RenameBranch(ctx context.Context, repo *repo_model.Repository, from, to str
378392
return err
379393
}
380394

395+
// 6. do git action
396+
if err = gitAction(ctx, isDefault); err != nil {
397+
return err
398+
}
399+
381400
return committer.Commit()
382401
}
383402

modules/cache/cache.go

+32-106
Original file line numberDiff line numberDiff line change
@@ -4,149 +4,75 @@
44
package cache
55

66
import (
7-
"fmt"
87
"strconv"
8+
"time"
99

1010
"code.gitea.io/gitea/modules/setting"
11-
12-
mc "gitea.com/go-chi/cache"
13-
14-
_ "gitea.com/go-chi/cache/memcache" // memcache plugin for cache
1511
)
1612

17-
var conn mc.Cache
18-
19-
func newCache(cacheConfig setting.Cache) (mc.Cache, error) {
20-
return mc.NewCacher(mc.Options{
21-
Adapter: cacheConfig.Adapter,
22-
AdapterConfig: cacheConfig.Conn,
23-
Interval: cacheConfig.Interval,
24-
})
25-
}
13+
var defaultCache StringCache
2614

2715
// Init start cache service
2816
func Init() error {
29-
var err error
30-
31-
if conn == nil {
32-
if conn, err = newCache(setting.CacheService.Cache); err != nil {
17+
if defaultCache == nil {
18+
c, err := NewStringCache(setting.CacheService.Cache)
19+
if err != nil {
3320
return err
3421
}
35-
if err = conn.Ping(); err != nil {
22+
for i := 0; i < 10; i++ {
23+
if err = c.Ping(); err == nil {
24+
break
25+
}
26+
time.Sleep(time.Second)
27+
}
28+
if err != nil {
3629
return err
3730
}
31+
defaultCache = c
3832
}
39-
40-
return err
33+
return nil
4134
}
4235

4336
// GetCache returns the currently configured cache
44-
func GetCache() mc.Cache {
45-
return conn
37+
func GetCache() StringCache {
38+
return defaultCache
4639
}
4740

4841
// GetString returns the key value from cache with callback when no key exists in cache
4942
func GetString(key string, getFunc func() (string, error)) (string, error) {
50-
if conn == nil || setting.CacheService.TTL == 0 {
43+
if defaultCache == nil || setting.CacheService.TTL == 0 {
5144
return getFunc()
5245
}
53-
54-
cached := conn.Get(key)
55-
56-
if cached == nil {
46+
cached, exist := defaultCache.Get(key)
47+
if !exist {
5748
value, err := getFunc()
5849
if err != nil {
5950
return value, err
6051
}
61-
return value, conn.Put(key, value, setting.CacheService.TTLSeconds())
62-
}
63-
64-
if value, ok := cached.(string); ok {
65-
return value, nil
66-
}
67-
68-
if stringer, ok := cached.(fmt.Stringer); ok {
69-
return stringer.String(), nil
70-
}
71-
72-
return fmt.Sprintf("%s", cached), nil
73-
}
74-
75-
// GetInt returns key value from cache with callback when no key exists in cache
76-
func GetInt(key string, getFunc func() (int, error)) (int, error) {
77-
if conn == nil || setting.CacheService.TTL == 0 {
78-
return getFunc()
79-
}
80-
81-
cached := conn.Get(key)
82-
83-
if cached == nil {
84-
value, err := getFunc()
85-
if err != nil {
86-
return value, err
87-
}
88-
89-
return value, conn.Put(key, value, setting.CacheService.TTLSeconds())
90-
}
91-
92-
switch v := cached.(type) {
93-
case int:
94-
return v, nil
95-
case string:
96-
value, err := strconv.Atoi(v)
97-
if err != nil {
98-
return 0, err
99-
}
100-
return value, nil
101-
default:
102-
value, err := getFunc()
103-
if err != nil {
104-
return value, err
105-
}
106-
return value, conn.Put(key, value, setting.CacheService.TTLSeconds())
52+
return value, defaultCache.Put(key, value, setting.CacheService.TTLSeconds())
10753
}
54+
return cached, nil
10855
}
10956

11057
// GetInt64 returns key value from cache with callback when no key exists in cache
11158
func GetInt64(key string, getFunc func() (int64, error)) (int64, error) {
112-
if conn == nil || setting.CacheService.TTL == 0 {
113-
return getFunc()
114-
}
115-
116-
cached := conn.Get(key)
117-
118-
if cached == nil {
119-
value, err := getFunc()
120-
if err != nil {
121-
return value, err
122-
}
123-
124-
return value, conn.Put(key, value, setting.CacheService.TTLSeconds())
59+
s, err := GetString(key, func() (string, error) {
60+
v, err := getFunc()
61+
return strconv.FormatInt(v, 10), err
62+
})
63+
if err != nil {
64+
return 0, err
12565
}
126-
127-
switch v := conn.Get(key).(type) {
128-
case int64:
129-
return v, nil
130-
case string:
131-
value, err := strconv.ParseInt(v, 10, 64)
132-
if err != nil {
133-
return 0, err
134-
}
135-
return value, nil
136-
default:
137-
value, err := getFunc()
138-
if err != nil {
139-
return value, err
140-
}
141-
142-
return value, conn.Put(key, value, setting.CacheService.TTLSeconds())
66+
if s == "" {
67+
return 0, nil
14368
}
69+
return strconv.ParseInt(s, 10, 64)
14470
}
14571

14672
// Remove key from cache
14773
func Remove(key string) {
148-
if conn == nil {
74+
if defaultCache == nil {
14975
return
15076
}
151-
_ = conn.Delete(key)
77+
_ = defaultCache.Delete(key)
15278
}

modules/cache/cache_redis.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"code.gitea.io/gitea/modules/graceful"
1212
"code.gitea.io/gitea/modules/nosql"
1313

14-
"gitea.com/go-chi/cache"
14+
"gitea.com/go-chi/cache" //nolint:depguard
1515
"github.com/redis/go-redis/v9"
1616
)
1717

0 commit comments

Comments
 (0)