diff options
author | Michael Muré <batolettre@gmail.com> | 2019-12-10 00:42:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-10 00:42:23 +0100 |
commit | f1ed857cbd3a253d77b31c0c896fdc4ade40844f (patch) | |
tree | d1efe28a1fa666039bf8180bbed0202f0437910f /bridge/launchpad | |
parent | 69af7a1e0c2647c354fd9c5b55a254ba677200e1 (diff) | |
parent | 58c0e5aac97eabc02fa890123f3845ae6fe632a8 (diff) | |
download | git-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')
-rw-r--r-- | bridge/launchpad/config.go | 39 | ||||
-rw-r--r-- | bridge/launchpad/import.go | 4 |
2 files changed, 21 insertions, 22 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 diff --git a/bridge/launchpad/import.go b/bridge/launchpad/import.go index 59fc5c5f..619631b3 100644 --- a/bridge/launchpad/import.go +++ b/bridge/launchpad/import.go @@ -15,7 +15,7 @@ type launchpadImporter struct { conf core.Configuration } -func (li *launchpadImporter) Init(conf core.Configuration) error { +func (li *launchpadImporter) Init(repo *cache.RepoCache, conf core.Configuration) error { li.conf = conf return nil } @@ -31,7 +31,7 @@ func (li *launchpadImporter) ensurePerson(repo *cache.RepoCache, owner LPPerson) if err == nil { return i, nil } - if _, ok := err.(entity.ErrMultipleMatch); ok { + if entity.IsErrMultipleMatch(err) { return nil, err } |