aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/launchpad/config.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-12-10 00:42:23 +0100
committerGitHub <noreply@github.com>2019-12-10 00:42:23 +0100
commitf1ed857cbd3a253d77b31c0c896fdc4ade40844f (patch)
treed1efe28a1fa666039bf8180bbed0202f0437910f /bridge/launchpad/config.go
parent69af7a1e0c2647c354fd9c5b55a254ba677200e1 (diff)
parent58c0e5aac97eabc02fa890123f3845ae6fe632a8 (diff)
downloadgit-bug-f1ed857cbd3a253d77b31c0c896fdc4ade40844f.tar.gz
Merge pull request #271 from MichaelMure/bridge-credentials
bridge: huge refactor to accept multiple kind of credentials
Diffstat (limited to 'bridge/launchpad/config.go')
-rw-r--r--bridge/launchpad/config.go39
1 files changed, 19 insertions, 20 deletions
diff --git a/bridge/launchpad/config.go b/bridge/launchpad/config.go
index be81c0ac..8db39100 100644
--- a/bridge/launchpad/config.go
+++ b/bridge/launchpad/config.go
@@ -11,7 +11,7 @@ import (
"time"
"github.com/MichaelMure/git-bug/bridge/core"
- "github.com/MichaelMure/git-bug/repository"
+ "github.com/MichaelMure/git-bug/cache"
)
var ErrBadProjectURL = errors.New("bad Launchpad project URL")
@@ -22,9 +22,9 @@ const (
defaultTimeout = 60 * time.Second
)
-func (l *Launchpad) Configure(repo repository.RepoCommon, params core.BridgeParams) (core.Configuration, error) {
- if params.Token != "" {
- fmt.Println("warning: --token is ineffective for a Launchpad bridge")
+func (l *Launchpad) Configure(repo *cache.RepoCache, params core.BridgeParams) (core.Configuration, error) {
+ if params.TokenRaw != "" {
+ fmt.Println("warning: token params are ineffective for a Launchpad bridge")
}
if params.Owner != "" {
fmt.Println("warning: --owner is ineffective for a Launchpad bridge")
@@ -34,22 +34,19 @@ func (l *Launchpad) Configure(repo repository.RepoCommon, params core.BridgePara
var err error
var project string
- if params.Project != "" {
+ switch {
+ case params.Project != "":
project = params.Project
-
- } else if params.URL != "" {
+ case params.URL != "":
// get project name from url
project, err = splitURL(params.URL)
- if err != nil {
- return nil, err
- }
-
- } else {
+ default:
// get project name from terminal prompt
project, err = promptProjectName()
- if err != nil {
- return nil, err
- }
+ }
+
+ if err != nil {
+ return nil, err
}
// verify project
@@ -61,8 +58,8 @@ func (l *Launchpad) Configure(repo repository.RepoCommon, params core.BridgePara
return nil, fmt.Errorf("project doesn't exist")
}
- conf[keyProject] = project
conf[core.ConfigKeyTarget] = target
+ conf[keyProject] = project
err = l.ValidateConfig(conf)
if err != nil {
@@ -73,12 +70,14 @@ func (l *Launchpad) Configure(repo repository.RepoCommon, params core.BridgePara
}
func (*Launchpad) ValidateConfig(conf core.Configuration) error {
- if _, ok := conf[keyProject]; !ok {
- return fmt.Errorf("missing %s key", keyProject)
+ if v, ok := conf[core.ConfigKeyTarget]; !ok {
+ return fmt.Errorf("missing %s key", core.ConfigKeyTarget)
+ } else if v != target {
+ return fmt.Errorf("unexpected target name: %v", v)
}
- if _, ok := conf[core.ConfigKeyTarget]; !ok {
- return fmt.Errorf("missing %s key", core.ConfigKeyTarget)
+ if _, ok := conf[keyProject]; !ok {
+ return fmt.Errorf("missing %s key", keyProject)
}
return nil