aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/github/config.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-02-15 13:54:51 +0100
committerMichael Muré <batolettre@gmail.com>2020-02-15 13:54:51 +0100
commitcfa005889a7d398ee71eac4a6d4b23a691a7ef2a (patch)
tree15d115fa77e61194b39ff0e7745778de8924070f /bridge/github/config.go
parent432a816dde18a12c1479ed8151a11c29929476e0 (diff)
parent02548c0e8f96a5c08efe46bd5f71f97fdd211de3 (diff)
downloadgit-bug-cfa005889a7d398ee71eac4a6d4b23a691a7ef2a.tar.gz
Merge remote-tracking branch 'origin/master' into cheshirekow-jira
Diffstat (limited to 'bridge/github/config.go')
-rw-r--r--bridge/github/config.go35
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