aboutsummaryrefslogtreecommitdiffstats
path: root/bridge
diff options
context:
space:
mode:
Diffstat (limited to 'bridge')
-rw-r--r--bridge/core/bridge.go28
-rw-r--r--bridge/github/config.go38
-rw-r--r--bridge/gitlab/config.go35
3 files changed, 56 insertions, 45 deletions
diff --git a/bridge/core/bridge.go b/bridge/core/bridge.go
index 3a36dfaa..1cad10e9 100644
--- a/bridge/core/bridge.go
+++ b/bridge/core/bridge.go
@@ -365,39 +365,21 @@ func (b *Bridge) ImportAll(ctx context.Context) (<-chan ImportResult, error) {
return b.ImportAllSince(ctx, time.Time{})
}
-func (b *Bridge) ExportAll(ctx context.Context, since time.Time) error {
+func (b *Bridge) ExportAll(ctx context.Context, since time.Time) (<-chan ExportResult, error) {
exporter := b.getExporter()
if exporter == nil {
- return ErrExportNotSupported
+ return nil, ErrExportNotSupported
}
err := b.ensureConfig()
if err != nil {
- return err
+ return nil, err
}
err = b.ensureInit()
if err != nil {
- return err
- }
-
- events, err := exporter.ExportAll(ctx, b.repo, since)
- if err != nil {
- return err
- }
-
- exportedIssues := 0
- for result := range events {
- if result.Event != ExportEventNothing {
- fmt.Println(result.String())
- }
-
- switch result.Event {
- case ExportEventBug:
- exportedIssues++
- }
+ return nil, err
}
- fmt.Printf("exported %d issues with %s bridge\n", exportedIssues, b.Name)
- return nil
+ return exporter.ExportAll(ctx, b.repo, since)
}
diff --git a/bridge/github/config.go b/bridge/github/config.go
index f0403062..9d059b00 100644
--- a/bridge/github/config.go
+++ b/bridge/github/config.go
@@ -17,12 +17,14 @@ import (
"syscall"
"time"
+ text "github.com/MichaelMure/go-term-text"
"github.com/pkg/errors"
"golang.org/x/crypto/ssh/terminal"
"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"
"github.com/MichaelMure/git-bug/util/interrupt"
)
@@ -43,31 +45,29 @@ var (
func (g *Github) Configure(repo repository.RepoCommon, params core.BridgeParams) (core.Configuration, error) {
conf := make(core.Configuration)
var err error
- var token string
- var tokenId entity.Id
- var tokenObj *core.Token
- var owner string
- var project string
if (params.Token != "" || params.TokenId != "" || params.TokenStdin) &&
(params.URL == "" && (params.Project == "" || params.Owner == "")) {
return nil, fmt.Errorf("you must provide a project URL or Owner/Name to configure this bridge with a token")
}
+ var owner string
+ var project string
// getting owner and project name
- if params.Owner != "" && params.Project != "" {
+ switch {
+ case params.Owner != "" && params.Project != "":
// first try to use params if both or project and owner are provided
owner = params.Owner
project = params.Project
- } else if params.URL != "" {
+ case params.URL != "":
// try to parse params URL and extract owner and project
owner, project, err = splitURL(params.URL)
if err != nil {
return nil, err
}
- } else {
+ default:
// remote suggestions
remotes, err := repo.GetRemotes()
if err != nil {
@@ -90,6 +90,10 @@ func (g *Github) Configure(repo repository.RepoCommon, params core.BridgeParams)
return nil, fmt.Errorf("invalid parameter owner: %v", owner)
}
+ var token string
+ var tokenId entity.Id
+ var tokenObj *core.Token
+
// try to get token from params if provided, else use terminal prompt
// to either enter a token or login and generate a new one, or choose
// an existing token
@@ -118,7 +122,7 @@ func (g *Github) Configure(repo repository.RepoCommon, params core.BridgeParams)
return nil, err
}
} else if tokenId != "" {
- tokenObj, err = core.LoadToken(repo, entity.Id(tokenId))
+ tokenObj, err = core.LoadToken(repo, tokenId)
if err != nil {
return nil, err
}
@@ -249,17 +253,25 @@ 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 {
- fmt.Println("known tokens for Github:")
+ fmt.Println()
+ fmt.Println("Existing tokens for Github:")
for i, token := range tokens {
if token.Target == target {
- fmt.Printf("[%d]: %s\n", i+3, token.ID())
+ fmt.Printf("[%d]: %s => %s (%s)\n",
+ i+3,
+ 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')
@@ -330,7 +342,7 @@ func promptToken() (string, error) {
}
func loginAndRequestToken(owner, project string) (string, error) {
- fmt.Println("git-bug will now generate an access token in your Github profile. Your credential are not stored and are only used to generate the token. The token is stored in the repository git config.")
+ fmt.Println("git-bug will now generate an access token in your Github profile. Your credential are not stored and are only used to generate the token. The token is stored in the global git config.")
fmt.Println()
fmt.Println("The access scope depend on the type of repository.")
fmt.Println("Public:")
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
}