mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-25 14:35:40 +00:00
Fix cli command restore-repo: "units" should be splitted to string slice, to match the old behavior and match the dump-repo's behavior (#20183)
This commit is contained in:
parent
2eb713bacc
commit
7c1f18a2bb
|
@ -134,7 +134,9 @@ func runDumpRepository(ctx *cli.Context) error {
|
||||||
} else {
|
} else {
|
||||||
units := strings.Split(ctx.String("units"), ",")
|
units := strings.Split(ctx.String("units"), ",")
|
||||||
for _, unit := range units {
|
for _, unit := range units {
|
||||||
switch strings.ToLower(unit) {
|
switch strings.ToLower(strings.TrimSpace(unit)) {
|
||||||
|
case "":
|
||||||
|
continue
|
||||||
case "wiki":
|
case "wiki":
|
||||||
opts.Wiki = true
|
opts.Wiki = true
|
||||||
case "issues":
|
case "issues":
|
||||||
|
@ -151,6 +153,8 @@ func runDumpRepository(ctx *cli.Context) error {
|
||||||
opts.Comments = true
|
opts.Comments = true
|
||||||
case "pull_requests":
|
case "pull_requests":
|
||||||
opts.PullRequests = true
|
opts.PullRequests = true
|
||||||
|
default:
|
||||||
|
return errors.New("invalid unit: " + unit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ package cmd
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/private"
|
"code.gitea.io/gitea/modules/private"
|
||||||
|
@ -37,10 +38,10 @@ var CmdRestoreRepository = cli.Command{
|
||||||
Value: "",
|
Value: "",
|
||||||
Usage: "Restore destination repository name",
|
Usage: "Restore destination repository name",
|
||||||
},
|
},
|
||||||
cli.StringSliceFlag{
|
cli.StringFlag{
|
||||||
Name: "units",
|
Name: "units",
|
||||||
Value: nil,
|
Value: "",
|
||||||
Usage: `Which items will be restored, one or more units should be repeated with this flag.
|
Usage: `Which items will be restored, one or more units should be separated as comma.
|
||||||
wiki, issues, labels, releases, release_assets, milestones, pull_requests, comments are allowed. Empty means all units.`,
|
wiki, issues, labels, releases, release_assets, milestones, pull_requests, comments are allowed. Empty means all units.`,
|
||||||
},
|
},
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{
|
||||||
|
@ -55,13 +56,16 @@ func runRestoreRepository(c *cli.Context) error {
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
setting.LoadFromExisting()
|
setting.LoadFromExisting()
|
||||||
|
var units []string
|
||||||
|
if s := c.String("units"); s != "" {
|
||||||
|
units = strings.Split(s, ",")
|
||||||
|
}
|
||||||
statusCode, errStr := private.RestoreRepo(
|
statusCode, errStr := private.RestoreRepo(
|
||||||
ctx,
|
ctx,
|
||||||
c.String("repo_dir"),
|
c.String("repo_dir"),
|
||||||
c.String("owner_name"),
|
c.String("owner_name"),
|
||||||
c.String("repo_name"),
|
c.String("repo_name"),
|
||||||
c.StringSlice("units"),
|
units,
|
||||||
c.Bool("validation"),
|
c.Bool("validation"),
|
||||||
)
|
)
|
||||||
if statusCode == http.StatusOK {
|
if statusCode == http.StatusOK {
|
||||||
|
|
|
@ -590,7 +590,7 @@ func updateOptionsUnits(opts *base.MigrateOptions, units []string) error {
|
||||||
opts.ReleaseAssets = true
|
opts.ReleaseAssets = true
|
||||||
} else {
|
} else {
|
||||||
for _, unit := range units {
|
for _, unit := range units {
|
||||||
switch strings.ToLower(unit) {
|
switch strings.ToLower(strings.TrimSpace(unit)) {
|
||||||
case "":
|
case "":
|
||||||
continue
|
continue
|
||||||
case "wiki":
|
case "wiki":
|
||||||
|
|
Loading…
Reference in a new issue