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{
import (
"context"
+ "errors"
"fmt"
"io"
"net/http"
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
} else {
for _, unit := range units {
switch strings.ToLower(unit) {
+ case "":
+ continue
case "wiki":
opts.Wiki = true
case "issues":
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
migrateOpts := base.MigrateOptions{
GitServiceType: structs.GitServiceType(tp),
}
- updateOptionsUnits(&migrateOpts, units)
+ if err := updateOptionsUnits(&migrateOpts, units); err != nil {
+ return err
+ }
if err = migrateRepository(downloader, uploader, migrateOpts, nil); err != nil {
if err1 := uploader.Rollback(); err1 != nil {