Skip to content

Commit 055d479

Browse files
authored
Merge branch 'main' into main
2 parents 0960631 + 1dac4d1 commit 055d479

File tree

12 files changed

+74
-46
lines changed

12 files changed

+74
-46
lines changed

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

options/locale/locale_ja-JP.ini

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3914,6 +3914,14 @@ variables.update.success=変数を更新しました。
39143914
logs.always_auto_scroll=常にログを自動スクロール
39153915
logs.always_expand_running=常に実行中のログを展開
39163916

3917+
general=一般
3918+
general.enable_actions=Actionsの有効化
3919+
general.collaborative_owners_management=協力オーナーの管理
3920+
general.collaborative_owners_management_help=協力オーナーとは、このリポジトリのActionやワークフローに、自身のプライベートリポジトリからアクセスできるユーザーまたは組織のことです。
3921+
general.add_collaborative_owner=協力オーナーを追加
3922+
general.collaborative_owner_not_exist=協力オーナーが存在しません。
3923+
general.remove_collaborative_owner=協力オーナーの削除
3924+
general.remove_collaborative_owner_desc=協力オーナーを削除すると、そのオーナーのリポジトリはこのリポジトリのActionにアクセスできなくなります。 続行しますか?
39173925

39183926
[projects]
39193927
deleted.display_name=削除されたプロジェクト

routers/api/v1/repo/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ func MergePullRequest(ctx *context.APIContext) {
10161016
}
10171017
}
10181018

1019-
if err := pull_service.Merge(ctx, pr, ctx.Doer, ctx.Repo.GitRepo, repo_model.MergeStyle(form.Do), form.HeadCommitID, message, false); err != nil {
1019+
if err := pull_service.Merge(ctx, pr, ctx.Doer, repo_model.MergeStyle(form.Do), form.HeadCommitID, message, false); err != nil {
10201020
if pull_service.IsErrInvalidMergeStyle(err) {
10211021
ctx.APIError(http.StatusMethodNotAllowed, fmt.Errorf("%s is not allowed an allowed merge style for this repository", repo_model.MergeStyle(form.Do)))
10221022
} else if pull_service.IsErrMergeConflicts(err) {

routers/web/repo/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,7 @@ func MergePullRequest(ctx *context.Context) {
11521152
}
11531153
}
11541154

1155-
if err := pull_service.Merge(ctx, pr, ctx.Doer, ctx.Repo.GitRepo, repo_model.MergeStyle(form.Do), form.HeadCommitID, message, false); err != nil {
1155+
if err := pull_service.Merge(ctx, pr, ctx.Doer, repo_model.MergeStyle(form.Do), form.HeadCommitID, message, false); err != nil {
11561156
if pull_service.IsErrInvalidMergeStyle(err) {
11571157
ctx.JSONError(ctx.Tr("repo.pulls.invalid_merge_option"))
11581158
} else if pull_service.IsErrMergeConflicts(err) {

services/automerge/automerge.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ func handlePullRequestAutoMerge(pullID int64, sha string) {
260260
return
261261
}
262262

263-
if err := pull_service.Merge(ctx, pr, doer, baseGitRepo, scheduledPRM.MergeStyle, "", scheduledPRM.Message, true); err != nil {
263+
if err := pull_service.Merge(ctx, pr, doer, scheduledPRM.MergeStyle, "", scheduledPRM.Message, true); err != nil {
264264
log.Error("pull_service.Merge: %v", err)
265265
// FIXME: if merge failed, we should display some error message to the pull request page.
266266
// The resolution is add a new column on automerge table named `error_message` to store the error message and displayed

services/pull/merge.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func (err ErrInvalidMergeStyle) Unwrap() error {
220220

221221
// Merge merges pull request to base repository.
222222
// Caller should check PR is ready to be merged (review and status checks)
223-
func Merge(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.User, baseGitRepo *git.Repository, mergeStyle repo_model.MergeStyle, expectedHeadCommitID, message string, wasAutoMerged bool) error {
223+
func Merge(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.User, mergeStyle repo_model.MergeStyle, expectedHeadCommitID, message string, wasAutoMerged bool) error {
224224
if err := pr.LoadBaseRepo(ctx); err != nil {
225225
log.Error("Unable to load base repo: %v", err)
226226
return fmt.Errorf("unable to load base repo: %w", err)
@@ -668,7 +668,7 @@ func MergedManually(ctx context.Context, pr *issues_model.PullRequest, doer *use
668668
return err
669669
}
670670

671-
notify_service.MergePullRequest(baseGitRepo.Ctx, doer, pr)
671+
notify_service.MergePullRequest(ctx, doer, pr)
672672
log.Info("manuallyMerged[%d]: Marked as manually merged into %s/%s by commit id: %s", pr.ID, pr.BaseRepo.Name, pr.BaseBranch, commitID)
673673

674674
return handleCloseCrossReferences(ctx, pr, doer)

services/release/release.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ func UpdateRelease(ctx context.Context, doer *user_model.User, gitRepo *git.Repo
262262
if rel.ID == 0 {
263263
return errors.New("UpdateRelease only accepts an exist release")
264264
}
265-
isTagCreated, err := createTag(gitRepo.Ctx, gitRepo, rel, "")
265+
isTagCreated, err := createTag(ctx, gitRepo, rel, "")
266266
if err != nil {
267267
return err
268268
}

0 commit comments

Comments
 (0)