aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/github
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-02-15 13:45:14 +0100
committerMichael Muré <batolettre@gmail.com>2020-02-15 13:45:14 +0100
commit87b97ca4b2f39240c698596ac14a6d3532f6363d (patch)
treebb537e52035aa1d60d0405f7177b510e96aff1a6 /bridge/github
parentfe3d5c95e4be5874066402b5463ada34894c7f01 (diff)
downloadgit-bug-87b97ca4b2f39240c698596ac14a6d3532f6363d.tar.gz
bridges: more refactor and cleanup
Diffstat (limited to 'bridge/github')
-rw-r--r--bridge/github/config.go35
-rw-r--r--bridge/github/github.go6
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{}
}