Skip to content

Commit d98bdfc

Browse files
committed
Merge remote-tracking branch 'origin/main' into noext
* origin/main: Replace deprecated `math/rand` functions (go-gitea#30733) Make Ctrl+Enter work for issue/comment edit (go-gitea#30720) Rename migration package name for 1.22-rc1 (go-gitea#30730) Issue card improvements (go-gitea#30687) Don't show loading indicators when refreshing the system status (go-gitea#30712) Add some tests to clarify the "must-change-password" behavior (go-gitea#30693) Prevent allow/reject reviews on merged/closed PRs (go-gitea#30686) Update JS dependencies (go-gitea#30713) Improve diff stats bar (go-gitea#30669) Remove unused parameter for some functions in `services/mirror` (go-gitea#30724) Update misspell to 0.5.1 and add `misspellings.csv` (go-gitea#30573) Suppress browserslist warning in webpack target (go-gitea#30571) [skip ci] Updated translations via Crowdin Diff color enhancements, add line number background (go-gitea#30670) feat(api): enhance Actions Secrets Management API for repository (go-gitea#30656) Fix code search input for different views (go-gitea#30678) Fix incorrect object id hash function (go-gitea#30708)
2 parents 432207d + 7b8e418 commit d98bdfc

File tree

93 files changed

+1199
-876
lines changed

Some content is hidden

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

93 files changed

+1199
-876
lines changed

Makefile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-che
3030
GOFUMPT_PACKAGE ?= mvdan.cc/[email protected]
3131
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/[email protected]
3232
GXZ_PACKAGE ?= github.com/ulikunitz/xz/cmd/[email protected]
33-
MISSPELL_PACKAGE ?= github.com/golangci/misspell/cmd/misspell@v0.4.1
33+
MISSPELL_PACKAGE ?= github.com/golangci/misspell/cmd/misspell@v0.5.1
3434
SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/swagger@db51e79a0e37c572d8b59ae0c58bf2bbbbe53285
3535
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
3636
GO_LICENSES_PACKAGE ?= github.com/google/go-licenses@v1
@@ -397,11 +397,11 @@ lint-md: node_modules
397397

398398
.PHONY: lint-spell
399399
lint-spell:
400-
@go run $(MISSPELL_PACKAGE) -error $(SPELLCHECK_FILES)
400+
@go run $(MISSPELL_PACKAGE) -dict tools/misspellings.csv -error $(SPELLCHECK_FILES)
401401

402402
.PHONY: lint-spell-fix
403403
lint-spell-fix:
404-
@go run $(MISSPELL_PACKAGE) -w $(SPELLCHECK_FILES)
404+
@go run $(MISSPELL_PACKAGE) -dict tools/misspellings.csv -w $(SPELLCHECK_FILES)
405405

406406
.PHONY: lint-go
407407
lint-go:
@@ -908,8 +908,9 @@ webpack: $(WEBPACK_DEST)
908908

909909
$(WEBPACK_DEST): $(WEBPACK_SOURCES) $(WEBPACK_CONFIGS) package-lock.json
910910
@$(MAKE) -s node-check node_modules
911-
rm -rf $(WEBPACK_DEST_ENTRIES)
912-
npx webpack
911+
@rm -rf $(WEBPACK_DEST_ENTRIES)
912+
@echo "Running webpack..."
913+
@BROWSERSLIST_IGNORE_OLD_DATA=true npx webpack
913914
@touch $(WEBPACK_DEST)
914915

915916
.PHONY: svg

cmd/admin_user_change_password.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var microcmdUserChangePassword = &cli.Command{
3535
},
3636
&cli.BoolFlag{
3737
Name: "must-change-password",
38-
Usage: "User must change password",
38+
Usage: "User must change password (can be disabled by --must-change-password=false)",
3939
Value: true,
4040
},
4141
},

cmd/admin_user_create.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package cmd
55

66
import (
7+
"context"
78
"errors"
89
"fmt"
910

@@ -48,7 +49,7 @@ var microcmdUserCreate = &cli.Command{
4849
},
4950
&cli.BoolFlag{
5051
Name: "must-change-password",
51-
Usage: "Set to false to prevent forcing the user to change their password after initial login",
52+
Usage: "User must change password after initial login, defaults to true for all users except the first one (can be disabled by --must-change-password=false)",
5253
DisableDefaultText: true,
5354
},
5455
&cli.IntFlag{
@@ -91,11 +92,16 @@ func runCreateUser(c *cli.Context) error {
9192
_, _ = fmt.Fprintf(c.App.ErrWriter, "--name flag is deprecated. Use --username instead.\n")
9293
}
9394

94-
ctx, cancel := installSignals()
95-
defer cancel()
96-
97-
if err := initDB(ctx); err != nil {
98-
return err
95+
ctx := c.Context
96+
if !setting.IsInTesting {
97+
// FIXME: need to refactor the "installSignals/initDB" related code later
98+
// it doesn't make sense to call it in (almost) every command action function
99+
var cancel context.CancelFunc
100+
ctx, cancel = installSignals()
101+
defer cancel()
102+
if err := initDB(ctx); err != nil {
103+
return err
104+
}
99105
}
100106

101107
var password string
@@ -123,8 +129,8 @@ func runCreateUser(c *cli.Context) error {
123129
if err != nil {
124130
return fmt.Errorf("IsTableNotEmpty: %w", err)
125131
}
126-
if !hasUserRecord && isAdmin {
127-
// if this is the first admin being created, don't force to change password (keep the old behavior)
132+
if !hasUserRecord {
133+
// if this is the first one being created, don't force to change password (keep the old behavior)
128134
mustChangePassword = false
129135
}
130136
}

cmd/admin_user_create_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package cmd
5+
6+
import (
7+
"fmt"
8+
"strings"
9+
"testing"
10+
11+
"code.gitea.io/gitea/models/db"
12+
"code.gitea.io/gitea/models/unittest"
13+
user_model "code.gitea.io/gitea/models/user"
14+
15+
"github.com/stretchr/testify/assert"
16+
)
17+
18+
func TestAdminUserCreate(t *testing.T) {
19+
app := NewMainApp(AppVersion{})
20+
21+
reset := func() {
22+
assert.NoError(t, db.TruncateBeans(db.DefaultContext, &user_model.User{}))
23+
assert.NoError(t, db.TruncateBeans(db.DefaultContext, &user_model.EmailAddress{}))
24+
}
25+
26+
type createCheck struct{ IsAdmin, MustChangePassword bool }
27+
createUser := func(name, args string) createCheck {
28+
assert.NoError(t, app.Run(strings.Fields(fmt.Sprintf("./gitea admin user create --username %s --email %[email protected] %s --password foobar", name, name, args))))
29+
u := unittest.AssertExistsAndLoadBean(t, &user_model.User{LowerName: name})
30+
return createCheck{u.IsAdmin, u.MustChangePassword}
31+
}
32+
reset()
33+
assert.Equal(t, createCheck{IsAdmin: false, MustChangePassword: false}, createUser("u", ""), "first non-admin user doesn't need to change password")
34+
35+
reset()
36+
assert.Equal(t, createCheck{IsAdmin: true, MustChangePassword: false}, createUser("u", "--admin"), "first admin user doesn't need to change password")
37+
38+
reset()
39+
assert.Equal(t, createCheck{IsAdmin: true, MustChangePassword: true}, createUser("u", "--admin --must-change-password"))
40+
assert.Equal(t, createCheck{IsAdmin: true, MustChangePassword: true}, createUser("u2", "--admin"))
41+
assert.Equal(t, createCheck{IsAdmin: true, MustChangePassword: false}, createUser("u3", "--admin --must-change-password=false"))
42+
assert.Equal(t, createCheck{IsAdmin: false, MustChangePassword: true}, createUser("u4", ""))
43+
assert.Equal(t, createCheck{IsAdmin: false, MustChangePassword: false}, createUser("u5", "--must-change-password=false"))
44+
}

cmd/main.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,18 @@ func prepareWorkPathAndCustomConf(action cli.ActionFunc) func(ctx *cli.Context)
112112
}
113113
}
114114

115-
func NewMainApp(version, versionExtra string) *cli.App {
115+
type AppVersion struct {
116+
Version string
117+
Extra string
118+
}
119+
120+
func NewMainApp(appVer AppVersion) *cli.App {
116121
app := cli.NewApp()
117122
app.Name = "Gitea"
118123
app.HelpName = "gitea"
119124
app.Usage = "A painless self-hosted Git service"
120125
app.Description = `Gitea program contains "web" and other subcommands. If no subcommand is given, it starts the web server by default. Use "web" subcommand for more web server arguments, use other subcommands for other purposes.`
121-
app.Version = version + versionExtra
126+
app.Version = appVer.Version + appVer.Extra
122127
app.EnableBashCompletion = true
123128

124129
// these sub-commands need to use config file

cmd/main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func makePathOutput(workPath, customPath, customConf string) string {
2828
}
2929

3030
func newTestApp(testCmdAction func(ctx *cli.Context) error) *cli.App {
31-
app := NewMainApp("version", "version-extra")
31+
app := NewMainApp(AppVersion{})
3232
testCmd := &cli.Command{Name: "test-cmd", Action: testCmdAction}
3333
prepareSubcommandWithConfig(testCmd, appGlobalFlags())
3434
app.Commands = append(app.Commands, testCmd)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,7 @@ Defaultly every storage has their default base path like below
13221322
| actions_log | actions_log/ |
13231323
| actions_artifacts | actions_artifacts/ |
13241324

1325-
And bucket, basepath or `SERVE_DIRECT` could be special or overrided, if you want to use a different you can:
1325+
And bucket, basepath or `SERVE_DIRECT` could be special or overridden, if you want to use a different you can:
13261326

13271327
```ini
13281328
[storage.actions_log]

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func main() {
4242
log.GetManager().Close()
4343
os.Exit(code)
4444
}
45-
app := cmd.NewMainApp(Version, formatBuiltWith())
45+
app := cmd.NewMainApp(cmd.AppVersion{Version: Version, Extra: formatBuiltWith()})
4646
_ = cmd.RunMainApp(app, os.Args...) // all errors should have been handled by the RunMainApp
4747
log.GetManager().Close()
4848
}

models/actions/run.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,11 @@ func CancelPreviousJobs(ctx context.Context, repoID int64, ref, workflowID strin
262262

263263
// InsertRun inserts a run
264264
func InsertRun(ctx context.Context, run *ActionRun, jobs []*jobparser.SingleWorkflow) error {
265-
ctx, commiter, err := db.TxContext(ctx)
265+
ctx, committer, err := db.TxContext(ctx)
266266
if err != nil {
267267
return err
268268
}
269-
defer commiter.Close()
269+
defer committer.Close()
270270

271271
index, err := db.GetNextResourceIndex(ctx, "action_run_index", run.RepoID)
272272
if err != nil {
@@ -331,7 +331,7 @@ func InsertRun(ctx context.Context, run *ActionRun, jobs []*jobparser.SingleWork
331331
}
332332
}
333333

334-
return commiter.Commit()
334+
return committer.Commit()
335335
}
336336

337337
func GetRunByID(ctx context.Context, id int64) (*ActionRun, error) {

models/actions/task.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,11 @@ func GetRunningTaskByToken(ctx context.Context, token string) (*ActionTask, erro
216216
}
217217

218218
func CreateTaskForRunner(ctx context.Context, runner *ActionRunner) (*ActionTask, bool, error) {
219-
ctx, commiter, err := db.TxContext(ctx)
219+
ctx, committer, err := db.TxContext(ctx)
220220
if err != nil {
221221
return nil, false, err
222222
}
223-
defer commiter.Close()
223+
defer committer.Close()
224224

225225
e := db.GetEngine(ctx)
226226

@@ -322,7 +322,7 @@ func CreateTaskForRunner(ctx context.Context, runner *ActionRunner) (*ActionTask
322322

323323
task.Job = job
324324

325-
if err := commiter.Commit(); err != nil {
325+
if err := committer.Commit(); err != nil {
326326
return nil, false, err
327327
}
328328

@@ -347,11 +347,11 @@ func UpdateTaskByState(ctx context.Context, state *runnerv1.TaskState) (*ActionT
347347
stepStates[v.Id] = v
348348
}
349349

350-
ctx, commiter, err := db.TxContext(ctx)
350+
ctx, committer, err := db.TxContext(ctx)
351351
if err != nil {
352352
return nil, err
353353
}
354-
defer commiter.Close()
354+
defer committer.Close()
355355

356356
e := db.GetEngine(ctx)
357357

@@ -412,7 +412,7 @@ func UpdateTaskByState(ctx context.Context, state *runnerv1.TaskState) (*ActionT
412412
}
413413
}
414414

415-
if err := commiter.Commit(); err != nil {
415+
if err := committer.Commit(); err != nil {
416416
return nil, err
417417
}
418418

0 commit comments

Comments
 (0)