Skip to content

Commit e67f35e

Browse files
authored
Merge branch 'main' into container-build-cache
2 parents a9261ff + b148bef commit e67f35e

File tree

95 files changed

+1409
-467
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

+1409
-467
lines changed

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,12 @@ TEST_TAGS ?= $(TAGS_SPLIT) sqlite sqlite_unlock_notify
163163

164164
TAR_EXCLUDES := .git data indexers queues log node_modules $(EXECUTABLE) $(DIST) $(MAKE_EVIDENCE_DIR) $(AIR_TMP_DIR) $(GO_LICENSE_TMP_DIR)
165165

166-
GO_DIRS := build cmd models modules routers services tests
166+
GO_DIRS := build cmd models modules routers services tests tools
167167
WEB_DIRS := web_src/js web_src/css
168168

169169
ESLINT_FILES := web_src/js tools *.ts tests/e2e
170170
STYLELINT_FILES := web_src/css web_src/js/components/*.vue
171-
SPELLCHECK_FILES := $(GO_DIRS) $(WEB_DIRS) templates options/locale/locale_en-US.ini .github $(filter-out CHANGELOG.md, $(wildcard *.go *.md *.yml *.yaml *.toml)) $(filter-out tools/misspellings.csv, $(wildcard tools/*))
171+
SPELLCHECK_FILES := $(GO_DIRS) $(WEB_DIRS) templates options/locale/locale_en-US.ini .github $(filter-out CHANGELOG.md, $(wildcard *.go *.md *.yml *.yaml *.toml))
172172
EDITORCONFIG_FILES := templates .github/workflows options/locale/locale_en-US.ini
173173

174174
GO_SOURCES := $(wildcard *.go)
@@ -376,11 +376,11 @@ lint-md: node_modules ## lint markdown files
376376

377377
.PHONY: lint-spell
378378
lint-spell: ## lint spelling
379-
@go run $(MISSPELL_PACKAGE) -dict tools/misspellings.csv -error $(SPELLCHECK_FILES)
379+
@go run $(MISSPELL_PACKAGE) -dict assets/misspellings.csv -error $(SPELLCHECK_FILES)
380380

381381
.PHONY: lint-spell-fix
382382
lint-spell-fix: ## lint spelling and fix issues
383-
@go run $(MISSPELL_PACKAGE) -dict tools/misspellings.csv -w $(SPELLCHECK_FILES)
383+
@go run $(MISSPELL_PACKAGE) -dict assets/misspellings.csv -w $(SPELLCHECK_FILES)
384384

385385
.PHONY: lint-go
386386
lint-go: ## lint go files
File renamed without changes.

cmd/cmd.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ func globalBool(c *cli.Command, name string) bool {
121121
// Any log appears in git stdout pipe will break the git protocol, eg: client can't push and hangs forever.
122122
func PrepareConsoleLoggerLevel(defaultLevel log.Level) func(context.Context, *cli.Command) (context.Context, error) {
123123
return func(ctx context.Context, c *cli.Command) (context.Context, error) {
124+
if setting.InstallLock {
125+
// During config loading, there might also be logs (for example: deprecation warnings).
126+
// It must make sure that console logger is set up before config is loaded.
127+
log.Error("Config is loaded before console logger is setup, it will cause bugs. Please fix it.")
128+
return nil, errors.New("console logger must be setup before config is loaded")
129+
}
124130
level := defaultLevel
125131
if globalBool(c, "quiet") {
126132
level = log.FATAL

cmd/keys.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
var CmdKeys = &cli.Command{
2020
Name: "keys",
2121
Usage: "(internal) Should only be called by SSH server",
22-
Hidden: true, // internal commands shouldn't not be visible
22+
Hidden: true, // internal commands shouldn't be visible
2323
Description: "Queries the Gitea database to get the authorized command for a given ssh key fingerprint",
2424
Before: PrepareConsoleLoggerLevel(log.FATAL),
2525
Action: runKeys,

cmd/main.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,15 @@ DEFAULT CONFIGURATION:
5050

5151
func prepareSubcommandWithGlobalFlags(originCmd *cli.Command) {
5252
originBefore := originCmd.Before
53-
originCmd.Before = func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
54-
prepareWorkPathAndCustomConf(cmd)
53+
originCmd.Before = func(ctxOrig context.Context, cmd *cli.Command) (ctx context.Context, err error) {
54+
ctx = ctxOrig
5555
if originBefore != nil {
56-
return originBefore(ctx, cmd)
56+
ctx, err = originBefore(ctx, cmd)
57+
if err != nil {
58+
return ctx, err
59+
}
5760
}
61+
prepareWorkPathAndCustomConf(cmd)
5862
return ctx, nil
5963
}
6064
}

cmd/main_test.go

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"code.gitea.io/gitea/models/unittest"
1616
"code.gitea.io/gitea/modules/setting"
1717
"code.gitea.io/gitea/modules/test"
18+
"code.gitea.io/gitea/modules/util"
1819

1920
"github.com/stretchr/testify/assert"
2021
"github.com/urfave/cli/v3"
@@ -28,11 +29,11 @@ func makePathOutput(workPath, customPath, customConf string) string {
2829
return fmt.Sprintf("WorkPath=%s\nCustomPath=%s\nCustomConf=%s", workPath, customPath, customConf)
2930
}
3031

31-
func newTestApp(testCmdAction cli.ActionFunc) *cli.Command {
32+
func newTestApp(testCmd cli.Command) *cli.Command {
3233
app := NewMainApp(AppVersion{})
33-
testCmd := &cli.Command{Name: "test-cmd", Action: testCmdAction}
34-
prepareSubcommandWithGlobalFlags(testCmd)
35-
app.Commands = append(app.Commands, testCmd)
34+
testCmd.Name = util.IfZero(testCmd.Name, "test-cmd")
35+
prepareSubcommandWithGlobalFlags(&testCmd)
36+
app.Commands = append(app.Commands, &testCmd)
3637
app.DefaultCommand = testCmd.Name
3738
return app
3839
}
@@ -156,9 +157,11 @@ func TestCliCmd(t *testing.T) {
156157

157158
for _, c := range cases {
158159
t.Run(c.cmd, func(t *testing.T) {
159-
app := newTestApp(func(ctx context.Context, cmd *cli.Command) error {
160-
_, _ = fmt.Fprint(cmd.Root().Writer, makePathOutput(setting.AppWorkPath, setting.CustomPath, setting.CustomConf))
161-
return nil
160+
app := newTestApp(cli.Command{
161+
Action: func(ctx context.Context, cmd *cli.Command) error {
162+
_, _ = fmt.Fprint(cmd.Root().Writer, makePathOutput(setting.AppWorkPath, setting.CustomPath, setting.CustomConf))
163+
return nil
164+
},
162165
})
163166
for k, v := range c.env {
164167
t.Setenv(k, v)
@@ -173,31 +176,54 @@ func TestCliCmd(t *testing.T) {
173176
}
174177

175178
func TestCliCmdError(t *testing.T) {
176-
app := newTestApp(func(ctx context.Context, cmd *cli.Command) error { return errors.New("normal error") })
179+
app := newTestApp(cli.Command{Action: func(ctx context.Context, cmd *cli.Command) error { return errors.New("normal error") }})
177180
r, err := runTestApp(app, "./gitea", "test-cmd")
178181
assert.Error(t, err)
179182
assert.Equal(t, 1, r.ExitCode)
180183
assert.Empty(t, r.Stdout)
181184
assert.Equal(t, "Command error: normal error\n", r.Stderr)
182185

183-
app = newTestApp(func(ctx context.Context, cmd *cli.Command) error { return cli.Exit("exit error", 2) })
186+
app = newTestApp(cli.Command{Action: func(ctx context.Context, cmd *cli.Command) error { return cli.Exit("exit error", 2) }})
184187
r, err = runTestApp(app, "./gitea", "test-cmd")
185188
assert.Error(t, err)
186189
assert.Equal(t, 2, r.ExitCode)
187190
assert.Empty(t, r.Stdout)
188191
assert.Equal(t, "exit error\n", r.Stderr)
189192

190-
app = newTestApp(func(ctx context.Context, cmd *cli.Command) error { return nil })
193+
app = newTestApp(cli.Command{Action: func(ctx context.Context, cmd *cli.Command) error { return nil }})
191194
r, err = runTestApp(app, "./gitea", "test-cmd", "--no-such")
192195
assert.Error(t, err)
193196
assert.Equal(t, 1, r.ExitCode)
194197
assert.Empty(t, r.Stdout)
195198
assert.Equal(t, "Incorrect Usage: flag provided but not defined: -no-such\n\n", r.Stderr)
196199

197-
app = newTestApp(func(ctx context.Context, cmd *cli.Command) error { return nil })
200+
app = newTestApp(cli.Command{Action: func(ctx context.Context, cmd *cli.Command) error { return nil }})
198201
r, err = runTestApp(app, "./gitea", "test-cmd")
199202
assert.NoError(t, err)
200203
assert.Equal(t, -1, r.ExitCode) // the cli.OsExiter is not called
201204
assert.Empty(t, r.Stdout)
202205
assert.Empty(t, r.Stderr)
203206
}
207+
208+
func TestCliCmdBefore(t *testing.T) {
209+
ctxNew := context.WithValue(context.Background(), any("key"), "value")
210+
configValues := map[string]string{}
211+
setting.CustomConf = "/tmp/any.ini"
212+
var actionCtx context.Context
213+
app := newTestApp(cli.Command{
214+
Before: func(context.Context, *cli.Command) (context.Context, error) {
215+
configValues["before"] = setting.CustomConf
216+
return ctxNew, nil
217+
},
218+
Action: func(ctx context.Context, cmd *cli.Command) error {
219+
configValues["action"] = setting.CustomConf
220+
actionCtx = ctx
221+
return nil
222+
},
223+
})
224+
_, err := runTestApp(app, "./gitea", "--config", "/dev/null", "test-cmd")
225+
assert.NoError(t, err)
226+
assert.Equal(t, ctxNew, actionCtx)
227+
assert.Equal(t, "/tmp/any.ini", configValues["before"], "BeforeFunc must be called before preparing config")
228+
assert.Equal(t, "/dev/null", configValues["action"])
229+
}

eslint.config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,7 @@ export default defineConfig([
774774
'unicorn/no-empty-file': [2],
775775
'unicorn/no-for-loop': [0],
776776
'unicorn/no-hex-escape': [0],
777+
'unicorn/no-immediate-mutation': [0],
777778
'unicorn/no-instanceof-array': [0],
778779
'unicorn/no-invalid-fetch-options': [2],
779780
'unicorn/no-invalid-remove-event-listener': [2],
@@ -799,6 +800,7 @@ export default defineConfig([
799800
'unicorn/no-unreadable-array-destructuring': [0],
800801
'unicorn/no-unreadable-iife': [2],
801802
'unicorn/no-unused-properties': [2],
803+
'unicorn/no-useless-collection-argument': [2],
802804
'unicorn/no-useless-fallback-in-spread': [2],
803805
'unicorn/no-useless-length-check': [2],
804806
'unicorn/no-useless-promise-resolve-reject': [2],
@@ -810,8 +812,8 @@ export default defineConfig([
810812
'unicorn/numeric-separators-style': [0],
811813
'unicorn/prefer-add-event-listener': [2],
812814
'unicorn/prefer-array-find': [2],
813-
'unicorn/prefer-array-flat-map': [2],
814815
'unicorn/prefer-array-flat': [2],
816+
'unicorn/prefer-array-flat-map': [2],
815817
'unicorn/prefer-array-index-of': [2],
816818
'unicorn/prefer-array-some': [2],
817819
'unicorn/prefer-at': [0],
@@ -846,6 +848,7 @@ export default defineConfig([
846848
'unicorn/prefer-query-selector': [2],
847849
'unicorn/prefer-reflect-apply': [0],
848850
'unicorn/prefer-regexp-test': [2],
851+
'unicorn/prefer-response-static-json': [2],
849852
'unicorn/prefer-set-has': [0],
850853
'unicorn/prefer-set-size': [2],
851854
'unicorn/prefer-spread': [0],
@@ -921,6 +924,7 @@ export default defineConfig([
921924
'vue/html-closing-bracket-spacing': [2, {startTag: 'never', endTag: 'never', selfClosingTag: 'never'}],
922925
'vue/max-attributes-per-line': [0],
923926
'vue/singleline-html-element-content-newline': [0],
927+
'vue/require-typed-ref': [2],
924928
},
925929
},
926930
{

models/migrations/base/tests.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919

2020
"github.com/stretchr/testify/require"
2121
"xorm.io/xorm"
22+
"xorm.io/xorm/schemas"
2223
)
2324

2425
// FIXME: this file shouldn't be in a normal package, it should only be compiled for tests
@@ -88,6 +89,16 @@ func PrepareTestEnv(t *testing.T, skip int, syncModels ...any) (*xorm.Engine, fu
8889
return x, deferFn
8990
}
9091

92+
func LoadTableSchemasMap(t *testing.T, x *xorm.Engine) map[string]*schemas.Table {
93+
tables, err := x.DBMetas()
94+
require.NoError(t, err)
95+
tableMap := make(map[string]*schemas.Table)
96+
for _, table := range tables {
97+
tableMap[table.Name] = table
98+
}
99+
return tableMap
100+
}
101+
91102
func MainTest(m *testing.M) {
92103
testlogger.Init()
93104

models/migrations/migrations.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"code.gitea.io/gitea/models/migrations/v1_23"
2626
"code.gitea.io/gitea/models/migrations/v1_24"
2727
"code.gitea.io/gitea/models/migrations/v1_25"
28+
"code.gitea.io/gitea/models/migrations/v1_26"
2829
"code.gitea.io/gitea/models/migrations/v1_6"
2930
"code.gitea.io/gitea/models/migrations/v1_7"
3031
"code.gitea.io/gitea/models/migrations/v1_8"
@@ -379,8 +380,8 @@ func prepareMigrationTasks() []*migration {
379380
newMigration(309, "Improve Notification table indices", v1_23.ImproveNotificationTableIndices),
380381
newMigration(310, "Add Priority to ProtectedBranch", v1_23.AddPriorityToProtectedBranch),
381382
newMigration(311, "Add TimeEstimate to Issue table", v1_23.AddTimeEstimateColumnToIssueTable),
382-
383383
// Gitea 1.23.0-rc0 ends at migration ID number 311 (database version 312)
384+
384385
newMigration(312, "Add DeleteBranchAfterMerge to AutoMerge", v1_24.AddDeleteBranchAfterMergeForAutoMerge),
385386
newMigration(313, "Move PinOrder from issue table to a new table issue_pin", v1_24.MovePinOrderToTableIssuePin),
386387
newMigration(314, "Update OwnerID as zero for repository level action tables", v1_24.UpdateOwnerIDOfRepoLevelActionsTables),
@@ -390,11 +391,13 @@ func prepareMigrationTasks() []*migration {
390391
newMigration(318, "Add anonymous_access_mode for repo_unit", v1_24.AddRepoUnitAnonymousAccessMode),
391392
newMigration(319, "Add ExclusiveOrder to Label table", v1_24.AddExclusiveOrderColumnToLabelTable),
392393
newMigration(320, "Migrate two_factor_policy to login_source table", v1_24.MigrateSkipTwoFactor),
394+
// Gitea 1.24.0 ends at migration ID number 320 (database version 321)
393395

394-
// Gitea 1.24.0 ends at database version 321
395396
newMigration(321, "Use LONGTEXT for some columns and fix review_state.updated_files column", v1_25.UseLongTextInSomeColumnsAndFixBugs),
396397
newMigration(322, "Extend comment tree_path length limit", v1_25.ExtendCommentTreePathLength),
397-
newMigration(323, "Add support for actions concurrency", v1_25.AddActionsConcurrency),
398+
// Gitea 1.25.0 ends at migration ID number 322 (database version 323)
399+
400+
newMigration(323, "Add support for actions concurrency", v1_26.AddActionsConcurrency),
398401
}
399402
return preparedMigrations
400403
}

models/migrations/v1_25/v321_test.go

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"code.gitea.io/gitea/modules/timeutil"
1212

1313
"github.com/stretchr/testify/assert"
14+
"github.com/stretchr/testify/require"
1415
)
1516

1617
func Test_UseLongTextInSomeColumnsAndFixBugs(t *testing.T) {
@@ -38,33 +39,26 @@ func Test_UseLongTextInSomeColumnsAndFixBugs(t *testing.T) {
3839
type Notice struct {
3940
ID int64 `xorm:"pk autoincr"`
4041
Type int
41-
Description string `xorm:"LONGTEXT"`
42+
Description string `xorm:"TEXT"`
4243
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
4344
}
4445

4546
// Prepare and load the testing database
46-
x, deferable := base.PrepareTestEnv(t, 0, new(ReviewState), new(PackageProperty), new(Notice))
47-
defer deferable()
47+
x, deferrable := base.PrepareTestEnv(t, 0, new(ReviewState), new(PackageProperty), new(Notice))
48+
defer deferrable()
4849

49-
assert.NoError(t, UseLongTextInSomeColumnsAndFixBugs(x))
50+
require.NoError(t, UseLongTextInSomeColumnsAndFixBugs(x))
5051

51-
tables, err := x.DBMetas()
52-
assert.NoError(t, err)
52+
tables := base.LoadTableSchemasMap(t, x)
53+
table := tables["review_state"]
54+
column := table.GetColumn("updated_files")
55+
assert.Equal(t, "LONGTEXT", column.SQLType.Name)
5356

54-
for _, table := range tables {
55-
switch table.Name {
56-
case "review_state":
57-
column := table.GetColumn("updated_files")
58-
assert.NotNil(t, column)
59-
assert.Equal(t, "LONGTEXT", column.SQLType.Name)
60-
case "package_property":
61-
column := table.GetColumn("value")
62-
assert.NotNil(t, column)
63-
assert.Equal(t, "LONGTEXT", column.SQLType.Name)
64-
case "notice":
65-
column := table.GetColumn("description")
66-
assert.NotNil(t, column)
67-
assert.Equal(t, "LONGTEXT", column.SQLType.Name)
68-
}
69-
}
57+
table = tables["package_property"]
58+
column = table.GetColumn("value")
59+
assert.Equal(t, "LONGTEXT", column.SQLType.Name)
60+
61+
table = tables["notice"]
62+
column = table.GetColumn("description")
63+
assert.Equal(t, "LONGTEXT", column.SQLType.Name)
7064
}

0 commit comments

Comments
 (0)