Skip to content

Commit 8f883a1

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: [skip ci] Updated translations via Crowdin Upgrade `gopls` to v0.19.0, add `make fix` (go-gitea#34772) Refactor packages (func name & UI) (go-gitea#34773) Fix remaining issues after `gopls modernize` formatting (go-gitea#34771) Fix some package registry problems (go-gitea#34759) Fix incorrect cli default values and default command (go-gitea#34765) Support annotated tags when using create release API (go-gitea#31840) when using rules to delete packages, remove unclean bugs (go-gitea#34632) Fix readme path and markdown link paste (go-gitea#34755)
2 parents 915a14e + 6708343 commit 8f883a1

File tree

68 files changed

+483
-342
lines changed

Some content is hidden

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

68 files changed

+483
-342
lines changed

Makefile

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
3636
GO_LICENSES_PACKAGE ?= github.com/google/go-licenses@v1
3737
GOVULNCHECK_PACKAGE ?= golang.org/x/vuln/cmd/govulncheck@v1
3838
ACTIONLINT_PACKAGE ?= github.com/rhysd/actionlint/cmd/actionlint@v1
39-
GOPLS_PACKAGE ?= golang.org/x/tools/gopls@v0.17.1
39+
GOPLS_PACKAGE ?= golang.org/x/tools/gopls@v0.19.0
40+
GOPLS_MODERNIZE_PACKAGE ?= golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@v0.19.0
4041

4142
DOCKER_IMAGE ?= gitea/gitea
4243
DOCKER_TAG ?= latest
@@ -230,7 +231,7 @@ clean: ## delete backend and integration files
230231
tests/e2e/reports/ tests/e2e/test-artifacts/ tests/e2e/test-snapshots/
231232

232233
.PHONY: fmt
233-
fmt: ## format the Go code
234+
fmt: ## format the Go and template code
234235
@GOFUMPT_PACKAGE=$(GOFUMPT_PACKAGE) $(GO) run build/code-batch-process.go gitea-fmt -w '{file-list}'
235236
$(eval TEMPLATES := $(shell find templates -type f -name '*.tmpl'))
236237
@# strip whitespace after '{{' or '(' and before '}}' or ')' unless there is only
@@ -249,6 +250,19 @@ fmt-check: fmt
249250
exit 1; \
250251
fi
251252

253+
.PHONY: fix
254+
fix: ## apply automated fixes to Go code
255+
$(GO) run $(GOPLS_MODERNIZE_PACKAGE) -fix ./...
256+
257+
.PHONY: fix-check
258+
fix-check: fix
259+
@diff=$$(git diff --color=always $(GO_SOURCES)); \
260+
if [ -n "$$diff" ]; then \
261+
echo "Please run 'make fix' and commit the result:"; \
262+
printf "%s" "$${diff}"; \
263+
exit 1; \
264+
fi
265+
252266
.PHONY: $(TAGS_EVIDENCE)
253267
$(TAGS_EVIDENCE):
254268
@mkdir -p $(MAKE_EVIDENCE_DIR)
@@ -288,7 +302,7 @@ checks: checks-frontend checks-backend ## run various consistency checks
288302
checks-frontend: lockfile-check svg-check ## check frontend files
289303

290304
.PHONY: checks-backend
291-
checks-backend: tidy-check swagger-check fmt-check swagger-validate security-check ## check backend files
305+
checks-backend: tidy-check swagger-check fmt-check fix-check swagger-validate security-check ## check backend files
292306

293307
.PHONY: lint
294308
lint: lint-frontend lint-backend lint-spell ## lint everything
@@ -809,6 +823,7 @@ deps-tools: ## install tool dependencies
809823
$(GO) install $(GOVULNCHECK_PACKAGE) & \
810824
$(GO) install $(ACTIONLINT_PACKAGE) & \
811825
$(GO) install $(GOPLS_PACKAGE) & \
826+
$(GO) install $(GOPLS_MODERNIZE_PACKAGE) & \
812827
wait
813828

814829
node_modules: package-lock.json

cmd/admin_auth_smtp.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,10 @@ func smtpCLIFlags() []cli.Flag {
3939
&cli.BoolFlag{
4040
Name: "force-smtps",
4141
Usage: "SMTPS is always used on port 465. Set this to force SMTPS on other ports.",
42-
Value: true,
4342
},
4443
&cli.BoolFlag{
4544
Name: "skip-verify",
4645
Usage: "Skip TLS verify.",
47-
Value: true,
4846
},
4947
&cli.StringFlag{
5048
Name: "helo-hostname",
@@ -54,7 +52,6 @@ func smtpCLIFlags() []cli.Flag {
5452
&cli.BoolFlag{
5553
Name: "disable-helo",
5654
Usage: "Disable SMTP helo.",
57-
Value: true,
5855
},
5956
&cli.StringFlag{
6057
Name: "allowed-domains",
@@ -64,7 +61,6 @@ func smtpCLIFlags() []cli.Flag {
6461
&cli.BoolFlag{
6562
Name: "skip-local-2fa",
6663
Usage: "Skip 2FA to log on.",
67-
Value: true,
6864
},
6965
&cli.BoolFlag{
7066
Name: "active",

cmd/admin_auth_smtp_test.go

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,8 @@ func TestAddSMTP(t *testing.T) {
6060
Auth: "PLAIN",
6161
Host: "localhost",
6262
Port: 25,
63-
// ForceSMTPS: true,
64-
// SkipVerify: true,
6563
},
66-
TwoFactorPolicy: "skip",
64+
TwoFactorPolicy: "",
6765
},
6866
},
6967
{
@@ -73,12 +71,12 @@ func TestAddSMTP(t *testing.T) {
7371
"--host", "localhost",
7472
"--port", "25",
7573
"--auth-type", "LOGIN",
76-
"--force-smtps=false",
77-
"--skip-verify=false",
74+
"--force-smtps",
75+
"--skip-verify",
7876
"--helo-hostname", "example.com",
79-
"--disable-helo=false",
77+
"--disable-helo=true",
8078
"--allowed-domains", "example.com,example.org",
81-
"--skip-local-2fa=false",
79+
"--skip-local-2fa",
8280
"--active=false",
8381
},
8482
source: &auth_model.Source{
@@ -89,13 +87,13 @@ func TestAddSMTP(t *testing.T) {
8987
Auth: "LOGIN",
9088
Host: "localhost",
9189
Port: 25,
92-
ForceSMTPS: false,
93-
SkipVerify: false,
90+
ForceSMTPS: true,
91+
SkipVerify: true,
9492
HeloHostname: "example.com",
95-
DisableHelo: false,
93+
DisableHelo: true,
9694
AllowedDomains: "example.com,example.org",
9795
},
98-
TwoFactorPolicy: "",
96+
TwoFactorPolicy: "skip",
9997
},
10098
},
10199
}
@@ -157,13 +155,10 @@ func TestUpdateSMTP(t *testing.T) {
157155
Name: "old name",
158156
IsActive: true,
159157
Cfg: &smtp.Source{
160-
Auth: "PLAIN",
161-
Host: "old host",
162-
Port: 26,
163-
ForceSMTPS: true,
164-
SkipVerify: true,
158+
Auth: "PLAIN",
159+
Host: "old host",
160+
Port: 26,
165161
},
166-
TwoFactorPolicy: "",
167162
},
168163
args: []string{
169164
"--id", "1",
@@ -177,13 +172,10 @@ func TestUpdateSMTP(t *testing.T) {
177172
Name: "test",
178173
IsActive: true,
179174
Cfg: &smtp.Source{
180-
Auth: "PLAIN",
181-
Host: "localhost",
182-
Port: 25,
183-
ForceSMTPS: true,
184-
SkipVerify: true,
175+
Auth: "PLAIN",
176+
Host: "localhost",
177+
Port: 25,
185178
},
186-
TwoFactorPolicy: "skip",
187179
},
188180
},
189181
{
@@ -197,10 +189,7 @@ func TestUpdateSMTP(t *testing.T) {
197189
Auth: "PLAIN",
198190
Host: "old host",
199191
Port: 26,
200-
ForceSMTPS: true,
201-
SkipVerify: true,
202192
HeloHostname: "old.example.com",
203-
DisableHelo: false,
204193
AllowedDomains: "old.example.com",
205194
},
206195
TwoFactorPolicy: "",
@@ -211,12 +200,12 @@ func TestUpdateSMTP(t *testing.T) {
211200
"--host", "localhost",
212201
"--port", "25",
213202
"--auth-type", "LOGIN",
214-
"--force-smtps=false",
215-
"--skip-verify=false",
203+
"--force-smtps",
204+
"--skip-verify",
216205
"--helo-hostname", "example.com",
217-
"--disable-helo=true",
206+
"--disable-helo",
218207
"--allowed-domains", "example.com,example.org",
219-
"--skip-local-2fa=true",
208+
"--skip-local-2fa",
220209
"--active=false",
221210
},
222211
authSource: &auth_model.Source{
@@ -228,8 +217,8 @@ func TestUpdateSMTP(t *testing.T) {
228217
Auth: "LOGIN",
229218
Host: "localhost",
230219
Port: 25,
231-
ForceSMTPS: false,
232-
SkipVerify: false,
220+
ForceSMTPS: true,
221+
SkipVerify: true,
233222
HeloHostname: "example.com",
234223
DisableHelo: true,
235224
AllowedDomains: "example.com,example.org",
@@ -252,11 +241,8 @@ func TestUpdateSMTP(t *testing.T) {
252241
Name: "test",
253242
IsActive: true,
254243
Cfg: &smtp.Source{
255-
Auth: "PLAIN",
256-
SkipVerify: true,
257-
ForceSMTPS: true,
244+
Auth: "PLAIN",
258245
},
259-
TwoFactorPolicy: "skip",
260246
}, nil
261247
},
262248

cmd/cmd.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,13 @@ func PrepareConsoleLoggerLevel(defaultLevel log.Level) func(context.Context, *cl
132132
return ctx, nil
133133
}
134134
}
135+
136+
func isValidDefaultSubCommand(cmd *cli.Command) (string, bool) {
137+
// Dirty patch for urfave/cli's strange design.
138+
// "./gitea bad-cmd" should not start the web server.
139+
rootArgs := cmd.Root().Args().Slice()
140+
if len(rootArgs) != 0 && rootArgs[0] != cmd.Name {
141+
return rootArgs[0], false
142+
}
143+
return "", true
144+
}

cmd/cmd_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2025 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package cmd
5+
6+
import (
7+
"context"
8+
"testing"
9+
10+
"github.com/stretchr/testify/assert"
11+
"github.com/urfave/cli/v3"
12+
)
13+
14+
func TestDefaultCommand(t *testing.T) {
15+
test := func(t *testing.T, args []string, expectedRetName string, expectedRetValid bool) {
16+
called := false
17+
cmd := &cli.Command{
18+
DefaultCommand: "test",
19+
Commands: []*cli.Command{
20+
{
21+
Name: "test",
22+
Action: func(ctx context.Context, command *cli.Command) error {
23+
retName, retValid := isValidDefaultSubCommand(command)
24+
assert.Equal(t, expectedRetName, retName)
25+
assert.Equal(t, expectedRetValid, retValid)
26+
called = true
27+
return nil
28+
},
29+
},
30+
},
31+
}
32+
assert.NoError(t, cmd.Run(t.Context(), args))
33+
assert.True(t, called)
34+
}
35+
test(t, []string{"./gitea"}, "", true)
36+
test(t, []string{"./gitea", "test"}, "", true)
37+
test(t, []string{"./gitea", "other"}, "other", false)
38+
}

cmd/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ func NewMainApp(appVer AppVersion) *cli.Command {
152152
CmdDocs,
153153
}
154154

155+
// TODO: we should eventually drop the default command,
156+
// but not sure whether it would break Windows users who used to double-click the EXE to run.
155157
app.DefaultCommand = CmdWeb.Name
156158

157159
app.Flags = append(app.Flags, cli.VersionFlag)

cmd/manager_logging.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ var (
119119
Name: "rotate",
120120
Aliases: []string{"r"},
121121
Usage: "Rotate logs",
122-
Value: true,
123122
},
124123
&cli.Int64Flag{
125124
Name: "max-size",
@@ -130,7 +129,6 @@ var (
130129
Name: "daily",
131130
Aliases: []string{"d"},
132131
Usage: "Rotate logs daily",
133-
Value: true,
134132
},
135133
&cli.IntFlag{
136134
Name: "max-days",
@@ -141,7 +139,6 @@ var (
141139
Name: "compress",
142140
Aliases: []string{"z"},
143141
Usage: "Compress rotated logs",
144-
Value: true,
145142
},
146143
&cli.IntFlag{
147144
Name: "compression-level",

cmd/web.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,10 @@ func runWeb(_ context.Context, cmd *cli.Command) error {
251251
}
252252
}()
253253

254+
if subCmdName, valid := isValidDefaultSubCommand(cmd); !valid {
255+
return fmt.Errorf("unknown command: %s", subCmdName)
256+
}
257+
254258
managerCtx, cancel := context.WithCancel(context.Background())
255259
graceful.InitManager(managerCtx)
256260
defer cancel()

models/migrations/v1_22/v294_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package v1_22 //nolint
55

66
import (
7-
"slices"
87
"testing"
98

109
"code.gitea.io/gitea/models/migrations/base"
@@ -44,7 +43,7 @@ func Test_AddUniqueIndexForProjectIssue(t *testing.T) {
4443
for _, index := range tables[0].Indexes {
4544
if index.Type == schemas.UniqueType {
4645
found = true
47-
slices.Equal(index.Cols, []string{"project_id", "issue_id"})
46+
assert.ElementsMatch(t, index.Cols, []string{"project_id", "issue_id"})
4847
break
4948
}
5049
}

models/packages/nuget/search.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func SearchVersions(ctx context.Context, opts *packages_model.PackageSearchOptio
3333
Where(cond).
3434
OrderBy("package.name ASC")
3535
if opts.Paginator != nil {
36-
skip, take := opts.GetSkipTake()
36+
skip, take := opts.Paginator.GetSkipTake()
3737
inner = inner.Limit(take, skip)
3838
}
3939

models/packages/package_property.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ func DeletePropertyByID(ctx context.Context, propertyID int64) error {
9292
return err
9393
}
9494

95-
// DeletePropertyByName deletes properties by name
96-
func DeletePropertyByName(ctx context.Context, refType PropertyType, refID int64, name string) error {
95+
// DeletePropertiesByName deletes properties by name
96+
func DeletePropertiesByName(ctx context.Context, refType PropertyType, refID int64, name string) error {
9797
_, err := db.GetEngine(ctx).Where("ref_type = ? AND ref_id = ? AND name = ?", refType, refID, name).Delete(&PackageProperty{})
9898
return err
9999
}

0 commit comments

Comments
 (0)