aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/core/bridge.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-02-15 03:01:45 +0100
committerGitHub <noreply@github.com>2020-02-15 03:01:45 +0100
commit362c0c7e2e1ce9a8e2918376a340c76f46569d64 (patch)
tree29f04fae0dc3d5d4883d4989012c26109ba754dc /bridge/core/bridge.go
parent2df72942f2b057956c7873f908b64880ab647331 (diff)
parentfe3d5c95e4be5874066402b5463ada34894c7f01 (diff)
downloadgit-bug-362c0c7e2e1ce9a8e2918376a340c76f46569d64.tar.gz
Merge pull request #325 from MichaelMure/bridge-refactor
bridges: massive refactor
Diffstat (limited to 'bridge/core/bridge.go')
-rw-r--r--bridge/core/bridge.go31
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)