Skip to content

Commit 289aed7

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: 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)
2 parents 2197282 + 8de2992 commit 289aed7

Some content is hidden

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

75 files changed

+764
-550
lines changed

Makefile

+6-5
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

+1-1
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

+14-8
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

+44
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

+7-2
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

+1-1
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

+1-1
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

+1-1
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

+3-3
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

+6-6
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

models/actions/tasks_version.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
// ActionTasksVersion
1515
// If both ownerID and repoID is zero, its scope is global.
16-
// If ownerID is not zero and repoID is zero, its scope is org (there is no user-level runner currrently).
16+
// If ownerID is not zero and repoID is zero, its scope is org (there is no user-level runner currently).
1717
// If ownerID is zero and repoID is not zero, its scope is repo.
1818
type ActionTasksVersion struct {
1919
ID int64 `xorm:"pk autoincr"`
@@ -73,11 +73,11 @@ func increaseTasksVersionByScope(ctx context.Context, ownerID, repoID int64) err
7373
}
7474

7575
func IncreaseTaskVersion(ctx context.Context, ownerID, repoID int64) error {
76-
ctx, commiter, err := db.TxContext(ctx)
76+
ctx, committer, err := db.TxContext(ctx)
7777
if err != nil {
7878
return err
7979
}
80-
defer commiter.Close()
80+
defer committer.Close()
8181

8282
// 1. increase global
8383
if err := increaseTasksVersionByScope(ctx, 0, 0); err != nil {
@@ -101,5 +101,5 @@ func IncreaseTaskVersion(ctx context.Context, ownerID, repoID int64) error {
101101
}
102102
}
103103

104-
return commiter.Commit()
104+
return committer.Commit()
105105
}

models/fixtures/pull_request.yml

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-
22
id: 1
33
type: 0 # gitea pull request
4-
status: 2 # mergable
4+
status: 2 # mergeable
55
issue_id: 2
66
index: 2
77
head_repo_id: 1
@@ -16,7 +16,7 @@
1616
-
1717
id: 2
1818
type: 0 # gitea pull request
19-
status: 2 # mergable
19+
status: 2 # mergeable
2020
issue_id: 3
2121
index: 3
2222
head_repo_id: 1
@@ -29,7 +29,7 @@
2929
-
3030
id: 3
3131
type: 0 # gitea pull request
32-
status: 2 # mergable
32+
status: 2 # mergeable
3333
issue_id: 8
3434
index: 1
3535
head_repo_id: 11
@@ -42,7 +42,7 @@
4242
-
4343
id: 4
4444
type: 0 # gitea pull request
45-
status: 2 # mergable
45+
status: 2 # mergeable
4646
issue_id: 9
4747
index: 1
4848
head_repo_id: 48
@@ -55,7 +55,7 @@
5555
-
5656
id: 5 # this PR is outdated (one commit behind branch1 )
5757
type: 0 # gitea pull request
58-
status: 2 # mergable
58+
status: 2 # mergeable
5959
issue_id: 11
6060
index: 5
6161
head_repo_id: 1
@@ -68,7 +68,7 @@
6868
-
6969
id: 6
7070
type: 0 # gitea pull request
71-
status: 2 # mergable
71+
status: 2 # mergeable
7272
issue_id: 12
7373
index: 2
7474
head_repo_id: 3
@@ -81,7 +81,7 @@
8181
-
8282
id: 7
8383
type: 0 # gitea pull request
84-
status: 2 # mergable
84+
status: 2 # mergeable
8585
issue_id: 19
8686
index: 1
8787
head_repo_id: 58
@@ -94,7 +94,7 @@
9494
-
9595
id: 8
9696
type: 0 # gitea pull request
97-
status: 2 # mergable
97+
status: 2 # mergeable
9898
issue_id: 20
9999
index: 1
100100
head_repo_id: 23
@@ -103,7 +103,7 @@
103103
-
104104
id: 9
105105
type: 0 # gitea pull request
106-
status: 2 # mergable
106+
status: 2 # mergeable
107107
issue_id: 21
108108
index: 1
109109
head_repo_id: 60
@@ -112,7 +112,7 @@
112112
-
113113
id: 10
114114
type: 0 # gitea pull request
115-
status: 2 # mergable
115+
status: 2 # mergeable
116116
issue_id: 22
117117
index: 1
118118
head_repo_id: 61

models/issues/pull.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ func UpdateAllowEdits(ctx context.Context, pr *PullRequest) error {
807807

808808
// Mergeable returns if the pullrequest is mergeable.
809809
func (pr *PullRequest) Mergeable(ctx context.Context) bool {
810-
// If a pull request isn't mergable if it's:
810+
// If a pull request isn't mergeable if it's:
811811
// - Being conflict checked.
812812
// - Has a conflict.
813813
// - Received a error while being conflict checked.

0 commit comments

Comments
 (0)