diff options
author | Michael Muré <batolettre@gmail.com> | 2019-11-26 20:45:32 +0100 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2019-11-26 20:45:32 +0100 |
commit | 4f856d6f78f8ffe1795a71195244e5a332ac3215 (patch) | |
tree | b0c702f60a10426ff2989bf66d155548e3efc383 /bridge/gitlab | |
parent | afe69d0c93bf9a4aaa0b6b39e8fce48c2d4ec346 (diff) | |
download | git-bug-4f856d6f78f8ffe1795a71195244e5a332ac3215.tar.gz |
gitlab: configurator cleanup
Diffstat (limited to 'bridge/gitlab')
-rw-r--r-- | bridge/gitlab/config.go | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/bridge/gitlab/config.go b/bridge/gitlab/config.go index 5c6ccb0e..6b85e8cb 100644 --- a/bridge/gitlab/config.go +++ b/bridge/gitlab/config.go @@ -8,13 +8,16 @@ import ( "regexp" "strconv" "strings" + "time" + text "github.com/MichaelMure/go-term-text" "github.com/pkg/errors" "github.com/xanzy/go-gitlab" "github.com/MichaelMure/git-bug/bridge/core" "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/repository" + "github.com/MichaelMure/git-bug/util/colors" ) var ( @@ -135,17 +138,31 @@ func promptTokenOptions(repo repository.RepoCommon) (*core.Token, error) { return nil, err } + if len(tokens) == 0 { + token, err := promptToken() + if err != nil { + return nil, err + } + return core.LoadOrCreateToken(repo, target, token) + } + fmt.Println() - fmt.Println("[1]: user provided token") - - if len(tokens) > 0 { - fmt.Println("known tokens for Gitlab:") - for i, token := range tokens { - if token.Target == target { - fmt.Printf("[%d]: %s\n", i+2, token.ID()) - } + fmt.Println("[1]: enter my token") + + fmt.Println() + fmt.Println("Existing tokens for Gitlab:") + for i, token := range tokens { + if token.Target == target { + fmt.Printf("[%d]: %s => %s (%s)\n", + i+2, + colors.Cyan(token.ID().Human()), + text.TruncateMax(token.Value, 10), + token.CreateTime.Format(time.RFC822), + ) } } + + fmt.Println() fmt.Print("Select option: ") line, err := bufio.NewReader(os.Stdin).ReadString('\n') @@ -251,7 +268,7 @@ func promptURL(remotes map[string]string) (string, error) { } url := strings.TrimSpace(line) - if line == "" { + if url == "" { fmt.Println("URL is empty") continue } |