bridge: use a single KeyTarget constant for all bridges

Michael Muré created

Change summary

bridge/core/bridge.go      | 4 ++--
bridge/github/config.go    | 7 +++----
bridge/launchpad/config.go | 7 +++----
3 files changed, 8 insertions(+), 10 deletions(-)

Detailed changes

bridge/core/bridge.go 🔗

@@ -19,7 +19,7 @@ var ErrImportNotSupported = errors.New("import is not supported")
 var ErrExportNotSupported = errors.New("export is not supported")
 
 const (
-	keyTarget             = "target"
+	KeyTarget             = "target"
 	bridgeConfigKeyPrefix = "git-bug.bridge"
 )
 
@@ -92,7 +92,7 @@ func LoadBridge(repo *cache.RepoCache, name string) (*Bridge, error) {
 		return nil, err
 	}
 
-	target := conf[keyTarget]
+	target := conf[KeyTarget]
 	bridge, err := NewBridge(repo, target, name)
 	if err != nil {
 		return nil, err

bridge/github/config.go 🔗

@@ -26,7 +26,6 @@ import (
 const (
 	target      = "github"
 	githubV3Url = "https://api.github.com"
-	keyTarget   = "target"
 	keyOwner    = "owner"
 	keyProject  = "project"
 	keyToken    = "token"
@@ -102,7 +101,7 @@ func (*Github) Configure(repo repository.RepoCommon, params core.BridgeParams) (
 		return nil, fmt.Errorf("project doesn't exist or authentication token has an incorrect scope")
 	}
 
-	conf[keyTarget] = target
+	conf[core.KeyTarget] = target
 	conf[keyToken] = token
 	conf[keyOwner] = owner
 	conf[keyProject] = project
@@ -111,8 +110,8 @@ func (*Github) Configure(repo repository.RepoCommon, params core.BridgeParams) (
 }
 
 func (*Github) ValidateConfig(conf core.Configuration) error {
-	if v, ok := conf[keyTarget]; !ok {
-		return fmt.Errorf("missing %s key", keyTarget)
+	if v, ok := conf[core.KeyTarget]; !ok {
+		return fmt.Errorf("missing %s key", core.KeyTarget)
 	} else if v != target {
 		return fmt.Errorf("unexpected target name: %v", v)
 	}

bridge/launchpad/config.go 🔗

@@ -19,7 +19,6 @@ var ErrBadProjectURL = errors.New("bad Launchpad project URL")
 const (
 	target         = "launchpad-preview"
 	keyProject     = "project"
-	keyTarget      = "target"
 	defaultTimeout = 60 * time.Second
 )
 
@@ -63,7 +62,7 @@ func (*Launchpad) Configure(repo repository.RepoCommon, params core.BridgeParams
 	}
 
 	conf[keyProject] = project
-	conf[keyTarget] = target
+	conf[core.KeyTarget] = target
 	return conf, nil
 }
 
@@ -72,8 +71,8 @@ func (*Launchpad) ValidateConfig(conf core.Configuration) error {
 		return fmt.Errorf("missing %s key", keyProject)
 	}
 
-	if _, ok := conf[keyTarget]; !ok {
-		return fmt.Errorf("missing %s key", keyTarget)
+	if _, ok := conf[core.KeyTarget]; !ok {
+		return fmt.Errorf("missing %s key", core.KeyTarget)
 	}
 
 	return nil