diff options
Diffstat (limited to 'bridge/core/bridge.go')
-rw-r--r-- | bridge/core/bridge.go | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/bridge/core/bridge.go b/bridge/core/bridge.go index ac0d47d7..62fd70f6 100644 --- a/bridge/core/bridge.go +++ b/bridge/core/bridge.go @@ -4,6 +4,7 @@ package core import ( "context" "fmt" + "os" "reflect" "regexp" "sort" @@ -30,18 +31,6 @@ const ( var bridgeImpl map[string]reflect.Type var bridgeLoginMetaKey map[string]string -// BridgeParams holds parameters to simplify the bridge configuration without -// having to make terminal prompts. -type BridgeParams struct { - Owner string // owner of the repo (Github) - Project string // name of the repo (Github, Launchpad) - URL string // complete URL of a repo (Github, Gitlab, Launchpad) - BaseURL string // base URL for self-hosted instance ( Gitlab) - CredPrefix string // ID prefix of the credential to use (Github, Gitlab) - TokenRaw string // pre-existing token to use (Github, Gitlab) - Login string // username for the passed credential (Github, Gitlab) -} - // Bridge is a wrapper around a BridgeImpl that will bind low-level // implementation with utility code to provide high-level functions. type Bridge struct { @@ -220,6 +209,8 @@ func RemoveBridge(repo repository.RepoConfig, name string) error { // Configure run the target specific configuration process func (b *Bridge) Configure(params BridgeParams) error { + validateParams(params, b.impl) + conf, err := b.impl.Configure(b.repo, params) if err != nil { return err @@ -234,6 +225,22 @@ func (b *Bridge) Configure(params BridgeParams) error { return b.storeConfig(conf) } +func validateParams(params BridgeParams, impl BridgeImpl) { + validParams := impl.ValidParams() + + paramsValue := reflect.ValueOf(params) + paramsType := paramsValue.Type() + + for i := 0; i < paramsValue.NumField(); i++ { + name := paramsType.Field(i).Name + val := paramsValue.Field(i).Interface().(string) + _, valid := validParams[name] + if val != "" && !valid { + _, _ = fmt.Fprintln(os.Stderr, params.fieldWarning(name, impl.Target())) + } + } +} + func (b *Bridge) storeConfig(conf Configuration) error { for key, val := range conf { storeKey := fmt.Sprintf("git-bug.bridge.%s.%s", b.Name, key) |