Skip to content

Commit b0f5f48

Browse files
committed
Merge branch 'main' into feature/load-referencing-branches-and-tags
2 parents 0012681 + 1c6c38f commit b0f5f48

File tree

409 files changed

+2817
-3430
lines changed

Some content is hidden

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

409 files changed

+2817
-3430
lines changed

.github/workflows/pull-compliance.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ jobs:
154154
node-version: 20
155155
- run: make deps-frontend
156156
- run: make lint-md
157-
- run: make docs # test if build could succeed
157+
- run: make docs
158158

159159
actions:
160160
if: needs.files-changed.outputs.actions == 'true' || needs.files-changed.outputs.actions == 'true'

Makefile

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ help:
197197
@echo " - clean delete backend and integration files"
198198
@echo " - clean-all delete backend, frontend and integration files"
199199
@echo " - deps install dependencies"
200-
@echo " - deps-docs install docs dependencies"
201200
@echo " - deps-frontend install frontend dependencies"
202201
@echo " - deps-backend install backend dependencies"
203202
@echo " - deps-tools install tool dependencies"
@@ -373,11 +372,11 @@ lint-backend-fix: lint-go-fix lint-go-vet lint-editorconfig
373372

374373
.PHONY: lint-js
375374
lint-js: node_modules
376-
npx eslint --color --max-warnings=0 --ext js,vue web_src/js build *.config.js docs/assets/js tests/e2e
375+
npx eslint --color --max-warnings=0 --ext js,vue web_src/js build *.config.js tests/e2e
377376

378377
.PHONY: lint-js-fix
379378
lint-js-fix: node_modules
380-
npx eslint --color --max-warnings=0 --ext js,vue web_src/js build *.config.js docs/assets/js tests/e2e --fix
379+
npx eslint --color --max-warnings=0 --ext js,vue web_src/js build *.config.js tests/e2e --fix
381380

382381
.PHONY: lint-css
383382
lint-css: node_modules
@@ -879,20 +878,14 @@ release-sources: | $(DIST_DIRS)
879878

880879
.PHONY: release-docs
881880
release-docs: | $(DIST_DIRS) docs
882-
tar -czf $(DIST)/release/gitea-docs-$(VERSION).tar.gz -C ./docs/public .
881+
tar -czf $(DIST)/release/gitea-docs-$(VERSION).tar.gz -C ./docs .
883882

884883
.PHONY: docs
885-
docs: deps-docs
886-
cd docs; make trans-copy clean build-offline;
887-
888-
.PHONY: deps-docs
889-
deps-docs:
890-
@hash hugo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
891-
curl -sL https://github.com/gohugoio/hugo/releases/download/v$(HUGO_VERSION)/hugo_$(HUGO_VERSION)_Linux-64bit.tar.gz | tar zxf - -C /tmp && mkdir -p ~/go/bin && mv /tmp/hugo ~/go/bin/hugo && chmod +x ~/go/bin/hugo; \
892-
fi
884+
docs:
885+
cd docs; bash scripts/trans-copy.sh;
893886

894887
.PHONY: deps
895-
deps: deps-frontend deps-backend deps-tools deps-docs deps-py
888+
deps: deps-frontend deps-backend deps-tools deps-py
896889

897890
.PHONY: deps-py
898891
deps-py: .venv

assets/go-licenses.json

Lines changed: 10 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/admin.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package cmd
66

77
import (
8+
"context"
89
"errors"
910
"fmt"
1011
"net/url"
@@ -297,10 +298,12 @@ var (
297298
&cli.BoolFlag{
298299
Name: "force-smtps",
299300
Usage: "SMTPS is always used on port 465. Set this to force SMTPS on other ports.",
301+
Value: true,
300302
},
301303
&cli.BoolFlag{
302304
Name: "skip-verify",
303305
Usage: "Skip TLS verify.",
306+
Value: true,
304307
},
305308
&cli.StringFlag{
306309
Name: "helo-hostname",
@@ -310,6 +313,7 @@ var (
310313
&cli.BoolFlag{
311314
Name: "disable-helo",
312315
Usage: "Disable SMTP helo.",
316+
Value: true,
313317
},
314318
&cli.StringFlag{
315319
Name: "allowed-domains",
@@ -319,10 +323,12 @@ var (
319323
&cli.BoolFlag{
320324
Name: "skip-local-2fa",
321325
Usage: "Skip 2FA to log on.",
326+
Value: true,
322327
},
323328
&cli.BoolFlag{
324329
Name: "active",
325330
Usage: "This Authentication Source is Activated.",
331+
Value: true,
326332
},
327333
}
328334

@@ -373,7 +379,7 @@ func runRepoSyncReleases(_ *cli.Context) error {
373379
continue
374380
}
375381

376-
oldnum, err := getReleaseCount(repo.ID)
382+
oldnum, err := getReleaseCount(ctx, repo.ID)
377383
if err != nil {
378384
log.Warn(" GetReleaseCountByRepoID: %v", err)
379385
}
@@ -385,7 +391,7 @@ func runRepoSyncReleases(_ *cli.Context) error {
385391
continue
386392
}
387393

388-
count, err = getReleaseCount(repo.ID)
394+
count, err = getReleaseCount(ctx, repo.ID)
389395
if err != nil {
390396
log.Warn(" GetReleaseCountByRepoID: %v", err)
391397
gitRepo.Close()
@@ -401,9 +407,9 @@ func runRepoSyncReleases(_ *cli.Context) error {
401407
return nil
402408
}
403409

404-
func getReleaseCount(id int64) (int64, error) {
410+
func getReleaseCount(ctx context.Context, id int64) (int64, error) {
405411
return repo_model.GetReleaseCountByRepoID(
406-
db.DefaultContext,
412+
ctx,
407413
id,
408414
repo_model.FindReleasesOptions{
409415
IncludeTags: true,

cmd/admin_user_generate_access_token.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,28 @@ func runGenerateAccessToken(c *cli.Context) error {
5757
return err
5858
}
5959

60-
accessTokenScope, err := auth_model.AccessTokenScope(c.String("scopes")).Normalize()
60+
// construct token with name and user so we can make sure it is unique
61+
t := &auth_model.AccessToken{
62+
Name: c.String("token-name"),
63+
UID: user.ID,
64+
}
65+
66+
exist, err := auth_model.AccessTokenByNameExists(t)
6167
if err != nil {
6268
return err
6369
}
70+
if exist {
71+
return fmt.Errorf("access token name has been used already")
72+
}
6473

65-
t := &auth_model.AccessToken{
66-
Name: c.String("token-name"),
67-
UID: user.ID,
68-
Scope: accessTokenScope,
74+
// make sure the scopes are valid
75+
accessTokenScope, err := auth_model.AccessTokenScope(c.String("scopes")).Normalize()
76+
if err != nil {
77+
return fmt.Errorf("invalid access token scope provided: %w", err)
6978
}
79+
t.Scope = accessTokenScope
7080

81+
// create the token
7182
if err := auth_model.NewAccessToken(t); err != nil {
7283
return err
7384
}

cmd/doctor.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@ import (
2222
"xorm.io/xorm"
2323
)
2424

25-
// CmdDoctor represents the available doctor sub-command.
26-
var CmdDoctor = &cli.Command{
27-
Name: "doctor",
25+
var cmdDoctorCheck = &cli.Command{
26+
Name: "check",
2827
Usage: "Diagnose and optionally fix problems",
2928
Description: "A command to diagnose problems with the current Gitea instance according to the given configuration. Some problems can optionally be fixed by modifying the database or data storage.",
30-
Action: runDoctor,
29+
Action: runDoctorCheck,
3130
Flags: []cli.Flag{
3231
&cli.BoolFlag{
3332
Name: "list",
@@ -51,16 +50,26 @@ var CmdDoctor = &cli.Command{
5150
},
5251
&cli.StringFlag{
5352
Name: "log-file",
54-
Usage: `Name of the log file (default: "doctor.log"). Set to "-" to output to stdout, set to "" to disable`,
53+
Usage: `Name of the log file (no verbose log output by default). Set to "-" to output to stdout`,
5554
},
5655
&cli.BoolFlag{
5756
Name: "color",
5857
Aliases: []string{"H"},
5958
Usage: "Use color for outputted information",
6059
},
6160
},
61+
}
62+
63+
// CmdDoctor represents the available doctor sub-command.
64+
var CmdDoctor = &cli.Command{
65+
Name: "doctor",
66+
Usage: "Diagnose and optionally fix problems",
67+
Description: "A command to diagnose problems with the current Gitea instance according to the given configuration. Some problems can optionally be fixed by modifying the database or data storage.",
68+
6269
Subcommands: []*cli.Command{
70+
cmdDoctorCheck,
6371
cmdRecreateTable,
72+
cmdDoctorConvert,
6473
},
6574
}
6675

@@ -133,16 +142,9 @@ func setupDoctorDefaultLogger(ctx *cli.Context, colorize bool) {
133142
setupConsoleLogger(log.FATAL, log.CanColorStderr, os.Stderr)
134143

135144
logFile := ctx.String("log-file")
136-
if !ctx.IsSet("log-file") {
137-
logFile = "doctor.log"
138-
}
139-
140-
if len(logFile) == 0 {
141-
// if no doctor log-file is set, do not show any log from default logger
142-
return
143-
}
144-
145-
if logFile == "-" {
145+
if logFile == "" {
146+
return // if no doctor log-file is set, do not show any log from default logger
147+
} else if logFile == "-" {
146148
setupConsoleLogger(log.TRACE, colorize, os.Stdout)
147149
} else {
148150
logFile, _ = filepath.Abs(logFile)
@@ -156,7 +158,7 @@ func setupDoctorDefaultLogger(ctx *cli.Context, colorize bool) {
156158
}
157159
}
158160

159-
func runDoctor(ctx *cli.Context) error {
161+
func runDoctorCheck(ctx *cli.Context) error {
160162
stdCtx, cancel := installSignals()
161163
defer cancel()
162164

cmd/convert.go renamed to cmd/doctor_convert.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ import (
1313
"github.com/urfave/cli/v2"
1414
)
1515

16-
// CmdConvert represents the available convert sub-command.
17-
var CmdConvert = &cli.Command{
16+
// cmdDoctorConvert represents the available convert sub-command.
17+
var cmdDoctorConvert = &cli.Command{
1818
Name: "convert",
1919
Usage: "Convert the database",
2020
Description: "A command to convert an existing MySQL database from utf8 to utf8mb4 or MSSQL database from varchar to nvarchar",
21-
Action: runConvert,
21+
Action: runDoctorConvert,
2222
}
2323

24-
func runConvert(ctx *cli.Context) error {
24+
func runDoctorConvert(ctx *cli.Context) error {
2525
stdCtx, cancel := installSignals()
2626
defer cancel()
2727

cmd/main.go

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

1212
"code.gitea.io/gitea/modules/log"
1313
"code.gitea.io/gitea/modules/setting"
14+
"code.gitea.io/gitea/modules/util"
1415

1516
"github.com/urfave/cli/v2"
1617
)
@@ -23,9 +24,13 @@ func cmdHelp() *cli.Command {
2324
Usage: "Shows a list of commands or help for one command",
2425
ArgsUsage: "[command]",
2526
Action: func(c *cli.Context) (err error) {
26-
args := c.Args()
27-
if args.Present() {
28-
err = cli.ShowCommandHelp(c, args.First())
27+
lineage := c.Lineage() // The order is from child to parent: help, doctor, Gitea, {Command:nil}
28+
targetCmdIdx := 0
29+
if c.Command.Name == "help" {
30+
targetCmdIdx = 1
31+
}
32+
if lineage[targetCmdIdx+1].Command != nil {
33+
err = cli.ShowCommandHelp(lineage[targetCmdIdx+1], lineage[targetCmdIdx].Command.Name)
2934
} else {
3035
err = cli.ShowAppHelp(c)
3136
}
@@ -94,9 +99,8 @@ func prepareSubcommandWithConfig(command *cli.Command, globalFlags []cli.Flag) {
9499
func prepareWorkPathAndCustomConf(action cli.ActionFunc) func(ctx *cli.Context) error {
95100
return func(ctx *cli.Context) error {
96101
var args setting.ArgWorkPathAndCustomConf
97-
ctxLineage := ctx.Lineage()
98-
for i := len(ctxLineage) - 1; i >= 0; i-- {
99-
curCtx := ctxLineage[i]
102+
// from children to parent, check the global flags
103+
for _, curCtx := range ctx.Lineage() {
100104
if curCtx.IsSet("work-path") && args.WorkPath == "" {
101105
args.WorkPath = curCtx.String("work-path")
102106
}
@@ -159,7 +163,6 @@ func NewMainApp() *cli.App {
159163
CmdAdmin,
160164
CmdMigrate,
161165
CmdKeys,
162-
CmdConvert,
163166
CmdDoctor,
164167
CmdManager,
165168
CmdEmbedded,
@@ -170,6 +173,10 @@ func NewMainApp() *cli.App {
170173
cmdHelp(), // the "help" sub-command was used to show the more information for "work path" and "custom config"
171174
}
172175

176+
cmdConvert := util.ToPointer(*cmdDoctorConvert)
177+
cmdConvert.Hidden = true // still support the legacy "./gitea doctor" by the hidden sub-command, remove it in next release
178+
subCmdWithConfig = append(subCmdWithConfig, cmdConvert)
179+
173180
// these sub-commands do not need the config file, and they do not depend on any path or environment variable.
174181
subCmdStandalone := []*cli.Command{
175182
CmdCert,

cmd/manager_logging.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ var (
117117
Name: "rotate",
118118
Aliases: []string{"r"},
119119
Usage: "Rotate logs",
120+
Value: true,
120121
},
121122
&cli.Int64Flag{
122123
Name: "max-size",
@@ -127,6 +128,7 @@ var (
127128
Name: "daily",
128129
Aliases: []string{"d"},
129130
Usage: "Rotate logs daily",
131+
Value: true,
130132
},
131133
&cli.IntFlag{
132134
Name: "max-days",
@@ -137,6 +139,7 @@ var (
137139
Name: "compress",
138140
Aliases: []string{"z"},
139141
Usage: "Compress rotated logs",
142+
Value: true,
140143
},
141144
&cli.IntFlag{
142145
Name: "compression-level",

0 commit comments

Comments
 (0)