Skip to content

Commit

Permalink
refactor: manage errors when validate config.
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Aug 29, 2017
1 parent 709c439 commit 8ef685d
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions gcg.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ The generator use only Pull Requests.
log.Printf("Run GCG command with config : %+v\n", config)
log.Printf("Run GCG command with config : %+v\n", config.DisplayLabelOptions)
}
required(config.CurrentRef, "current-ref")
required(config.PreviousRef, "previous-ref")
required(config.Owner, "owner")
required(config.RepositoryName, "repo-name")

err := validateConfig(config)
if err != nil {
return err
}

core.Generate(config)
return nil
Expand All @@ -56,6 +57,22 @@ The generator use only Pull Requests.
flag.Run()
}

func validateConfig(config *types.Configuration) error {
err := required(config.CurrentRef, "current-ref")
if err != nil {
return err
}
err = required(config.PreviousRef, "previous-ref")
if err != nil {
return err
}
err = required(config.Owner, "owner")
if err != nil {
return err
}
return required(config.RepositoryName, "repo-name")
}

func required(field string, fieldName string) error {
if len(field) == 0 {
log.Fatalf("%s is mandatory.", fieldName)
Expand Down

0 comments on commit 8ef685d

Please sign in to comment.