Skip to content

Commit 040100f

Browse files
committed
check invalid unit names
1 parent 180e935 commit 040100f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

services/migrations/dump.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package migrations
66

77
import (
88
"context"
9+
"errors"
910
"fmt"
1011
"io"
1112
"net/http"
@@ -572,7 +573,7 @@ func DumpRepository(ctx context.Context, baseDir, ownerName string, opts base.Mi
572573
return nil
573574
}
574575

575-
func updateOptionsUnits(opts *base.MigrateOptions, units []string) {
576+
func updateOptionsUnits(opts *base.MigrateOptions, units []string) error {
576577
if len(units) == 0 {
577578
opts.Wiki = true
578579
opts.Issues = true
@@ -585,6 +586,8 @@ func updateOptionsUnits(opts *base.MigrateOptions, units []string) {
585586
} else {
586587
for _, unit := range units {
587588
switch strings.ToLower(unit) {
589+
case "":
590+
continue
588591
case "wiki":
589592
opts.Wiki = true
590593
case "issues":
@@ -601,9 +604,12 @@ func updateOptionsUnits(opts *base.MigrateOptions, units []string) {
601604
opts.Comments = true
602605
case "pull_requests":
603606
opts.PullRequests = true
607+
default:
608+
return errors.New("invalid unit: " + unit)
604609
}
605610
}
606611
}
612+
return nil
607613
}
608614

609615
// RestoreRepository restore a repository from the disk directory
@@ -626,7 +632,9 @@ func RestoreRepository(ctx context.Context, baseDir, ownerName, repoName string,
626632
migrateOpts := base.MigrateOptions{
627633
GitServiceType: structs.GitServiceType(tp),
628634
}
629-
updateOptionsUnits(&migrateOpts, units)
635+
if err = updateOptionsUnits(&migrateOpts, units); err != nil {
636+
return err
637+
}
630638

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

0 commit comments

Comments
 (0)