aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-11-26 20:45:32 +0100
committerMichael Muré <batolettre@gmail.com>2019-11-26 20:45:32 +0100
commit4f856d6f78f8ffe1795a71195244e5a332ac3215 (patch)
treeb0c702f60a10426ff2989bf66d155548e3efc383
parentafe69d0c93bf9a4aaa0b6b39e8fce48c2d4ec346 (diff)
downloadgit-bug-4f856d6f78f8ffe1795a71195244e5a332ac3215.tar.gz
gitlab: configurator cleanup
-rw-r--r--bridge/github/config.go2
-rw-r--r--bridge/gitlab/config.go35
2 files changed, 27 insertions, 10 deletions
diff --git a/bridge/github/config.go b/bridge/github/config.go
index f6fbe7ec..9d059b00 100644
--- a/bridge/github/config.go
+++ b/bridge/github/config.go
@@ -253,7 +253,7 @@ func promptTokenOptions(repo repository.RepoCommon, owner, project string) (*cor
}
fmt.Println()
- fmt.Println("[1]: user provided token")
+ fmt.Println("[1]: enter my token")
fmt.Println("[2]: interactive token creation")
if len(tokens) > 0 {
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
}