diff options
author | Michael Muré <batolettre@gmail.com> | 2020-02-15 13:54:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-15 13:54:30 +0100 |
commit | 02548c0e8f96a5c08efe46bd5f71f97fdd211de3 (patch) | |
tree | bb537e52035aa1d60d0405f7177b510e96aff1a6 /bridge/github/config.go | |
parent | 362c0c7e2e1ce9a8e2918376a340c76f46569d64 (diff) | |
parent | 87b97ca4b2f39240c698596ac14a6d3532f6363d (diff) | |
download | git-bug-02548c0e8f96a5c08efe46bd5f71f97fdd211de3.tar.gz |
Merge pull request #326 from MichaelMure/bridge-refactor
bridges: more refactor and cleanup
Diffstat (limited to 'bridge/github/config.go')
-rw-r--r-- | bridge/github/config.go | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/bridge/github/config.go b/bridge/github/config.go index 9167ac26..269c6144 100644 --- a/bridge/github/config.go +++ b/bridge/github/config.go @@ -143,7 +143,7 @@ func (g *Github) Configure(repo *cache.RepoCache, params core.BridgeParams) (cor return conf, core.FinishConfig(repo, metaKeyGithubLogin, login) } -func (Github) ValidateConfig(conf core.Configuration) error { +func (*Github) ValidateConfig(conf core.Configuration) error { if v, ok := conf[core.ConfigKeyTarget]; !ok { return fmt.Errorf("missing %s key", core.ConfigKeyTarget) } else if v != target { @@ -252,13 +252,18 @@ func promptTokenOptions(repo repository.RepoConfig, login, owner, project string return nil, err } - cred, err := input.PromptCredentialWithInteractive(target, "token", creds) - switch err { - case nil: + cred, index, err := input.PromptCredential(target, "token", creds, []string{ + "enter my token", + "interactive token creation", + }) + switch { + case err != nil: + return nil, err + case cred != nil: return cred, nil - case input.ErrDirectPrompt: + case index == 0: return promptToken() - case input.ErrInteractiveCreation: + case index == 1: value, err := loginAndRequestToken(login, owner, project) if err != nil { return nil, err @@ -267,7 +272,7 @@ func promptTokenOptions(repo repository.RepoConfig, login, owner, project string token.SetMetadata(auth.MetaKeyLogin, login) return token, nil default: - return nil, err + panic("missed case") } } @@ -322,31 +327,19 @@ func loginAndRequestToken(login, owner, project string) (string, error) { fmt.Println() // prompt project visibility to know the token scope needed for the repository - i, err := input.PromptChoice("repository visibility", []string{"public", "private"}) + index, err := input.PromptChoice("repository visibility", []string{"public", "private"}) if err != nil { return "", err } - isPublic := i == 0 + scope := []string{"public_repo", "repo"}[index] password, err := input.PromptPassword("Password", "password", input.Required) if err != nil { return "", err } - var scope string - if isPublic { - // public_repo is requested to be able to read public repositories - scope = "public_repo" - } else { - // 'repo' is request to be able to read private repositories - // /!\ token will have read/write rights on every private repository you have access to - scope = "repo" - } - // Attempt to authenticate and create a token - note := fmt.Sprintf("git-bug - %s/%s", owner, project) - resp, err := requestToken(note, login, password, scope) if err != nil { return "", err |