diff options
author | Michael Muré <batolettre@gmail.com> | 2020-02-15 13:54:51 +0100 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2020-02-15 13:54:51 +0100 |
commit | cfa005889a7d398ee71eac4a6d4b23a691a7ef2a (patch) | |
tree | 15d115fa77e61194b39ff0e7745778de8924070f /bridge/github | |
parent | 432a816dde18a12c1479ed8151a11c29929476e0 (diff) | |
parent | 02548c0e8f96a5c08efe46bd5f71f97fdd211de3 (diff) | |
download | git-bug-cfa005889a7d398ee71eac4a6d4b23a691a7ef2a.tar.gz |
Merge remote-tracking branch 'origin/master' into cheshirekow-jira
Diffstat (limited to 'bridge/github')
-rw-r--r-- | bridge/github/config.go | 35 | ||||
-rw-r--r-- | bridge/github/github.go | 6 |
2 files changed, 17 insertions, 24 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 diff --git a/bridge/github/github.go b/bridge/github/github.go index a02d9460..3a99cec7 100644 --- a/bridge/github/github.go +++ b/bridge/github/github.go @@ -30,7 +30,7 @@ var _ core.BridgeImpl = &Github{} type Github struct{} -func (Github) Target() string { +func (*Github) Target() string { return target } @@ -38,11 +38,11 @@ func (g *Github) LoginMetaKey() string { return metaKeyGithubLogin } -func (Github) NewImporter() core.Importer { +func (*Github) NewImporter() core.Importer { return &githubImporter{} } -func (Github) NewExporter() core.Exporter { +func (*Github) NewExporter() core.Exporter { return &githubExporter{} } |