Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cli command restore-repo: "units" should be parsed as StringSlice #19953

Merged
merged 7 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cmd/restore_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ var CmdRestoreRepository = cli.Command{
Value: "",
Usage: "Restore destination repository name",
},
cli.StringFlag{
cli.StringSliceFlag{
Name: "units",
Value: "",
Usage: `Which items will be restored, one or more units should be separated as comma.
Value: nil,
Usage: `Which items will be restored, one or more units should be repeated with this flag.
wiki, issues, labels, releases, release_assets, milestones, pull_requests, comments are allowed. Empty means all units.`,
},
cli.BoolFlag{
Expand Down
12 changes: 10 additions & 2 deletions services/migrations/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package migrations

import (
"context"
"errors"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -572,7 +573,7 @@ func DumpRepository(ctx context.Context, baseDir, ownerName string, opts base.Mi
return nil
}

func updateOptionsUnits(opts *base.MigrateOptions, units []string) {
func updateOptionsUnits(opts *base.MigrateOptions, units []string) error {
if len(units) == 0 {
opts.Wiki = true
opts.Issues = true
Expand All @@ -585,6 +586,8 @@ func updateOptionsUnits(opts *base.MigrateOptions, units []string) {
} else {
for _, unit := range units {
switch strings.ToLower(unit) {
case "":
continue
case "wiki":
opts.Wiki = true
case "issues":
Expand All @@ -601,9 +604,12 @@ func updateOptionsUnits(opts *base.MigrateOptions, units []string) {
opts.Comments = true
case "pull_requests":
opts.PullRequests = true
default:
return errors.New("invalid unit: " + unit)
}
}
}
return nil
}

// RestoreRepository restore a repository from the disk directory
Expand All @@ -626,7 +632,9 @@ func RestoreRepository(ctx context.Context, baseDir, ownerName, repoName string,
migrateOpts := base.MigrateOptions{
GitServiceType: structs.GitServiceType(tp),
}
updateOptionsUnits(&migrateOpts, units)
if err = updateOptionsUnits(&migrateOpts, units); err != nil {
6543 marked this conversation as resolved.
Show resolved Hide resolved
return err
}

if err = migrateRepository(downloader, uploader, migrateOpts, nil); err != nil {
if err1 := uploader.Rollback(); err1 != nil {
Expand Down