aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/github
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-01-12 16:38:16 +0100
committerMichael Muré <batolettre@gmail.com>2020-02-08 17:18:28 +0100
commitae2f942ef907161af0aba5f3511db72cf9801dca (patch)
tree899e9a2d93d3d4be3b700f5763b7bc158c24ff30 /bridge/github
parent26f0152384f77d2bfd16c6762f5618bc966809a6 (diff)
downloadgit-bug-ae2f942ef907161af0aba5f3511db72cf9801dca.tar.gz
more wip
Diffstat (limited to 'bridge/github')
-rw-r--r--bridge/github/config.go8
-rw-r--r--bridge/github/config_test.go5
-rw-r--r--bridge/github/export.go45
-rw-r--r--bridge/github/import.go16
-rw-r--r--bridge/github/import_test.go8
5 files changed, 25 insertions, 57 deletions
diff --git a/bridge/github/config.go b/bridge/github/config.go
index e51f244b..fcb94079 100644
--- a/bridge/github/config.go
+++ b/bridge/github/config.go
@@ -81,7 +81,7 @@ func (g *Github) Configure(repo *cache.RepoCache, params core.BridgeParams) (cor
login := params.Login
if login == "" {
- login, err = input.Prompt("Github login", "", true, validateUsername)
+ login, err = input.Prompt("Github login", "login", input.Required, validateUsername)
if err != nil {
return nil, err
}
@@ -128,6 +128,10 @@ func (g *Github) Configure(repo *cache.RepoCache, params core.BridgeParams) (cor
return nil, err
}
+ // Todo: if no user exist with the given login
+ // - tag the default user with the github login
+ // - add a command to manually tag a user ?
+
// don't forget to store the now known valid token
if !auth.IdExist(repo, cred.ID()) {
err = auth.Store(repo, cred)
@@ -317,7 +321,7 @@ func promptToken() (string, error) {
return "token has incorrect format", nil
}
- return input.Prompt("Enter token", "token", "", input.Required, validator)
+ return input.Prompt("Enter token", "token", input.Required, validator)
}
func loginAndRequestToken(login, owner, project string) (string, error) {
diff --git a/bridge/github/config_test.go b/bridge/github/config_test.go
index 9798d26b..d7b1b38d 100644
--- a/bridge/github/config_test.go
+++ b/bridge/github/config_test.go
@@ -7,7 +7,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/MichaelMure/git-bug/bridge/core/auth"
- "github.com/MichaelMure/git-bug/entity"
)
func TestSplitURL(t *testing.T) {
@@ -155,8 +154,8 @@ func TestValidateProject(t *testing.T) {
t.Skip("Env var GITHUB_TOKEN_PUBLIC missing")
}
- tokenPrivate := auth.NewToken(entity.UnsetId, envPrivate, target)
- tokenPublic := auth.NewToken(entity.UnsetId, envPublic, target)
+ tokenPrivate := auth.NewToken(envPrivate, target)
+ tokenPublic := auth.NewToken(envPublic, target)
type args struct {
owner string
diff --git a/bridge/github/export.go b/bridge/github/export.go
index 6c089a47..1cc66dee 100644
--- a/bridge/github/export.go
+++ b/bridge/github/export.go
@@ -7,6 +7,7 @@ import (
"fmt"
"io/ioutil"
"net/http"
+ "os"
"strings"
"time"
@@ -19,6 +20,7 @@ import (
"github.com/MichaelMure/git-bug/bug"
"github.com/MichaelMure/git-bug/cache"
"github.com/MichaelMure/git-bug/entity"
+ "github.com/MichaelMure/git-bug/identity"
"github.com/MichaelMure/git-bug/repository"
)
@@ -33,13 +35,6 @@ type githubExporter struct {
// cache identities clients
identityClient map[entity.Id]*githubv4.Client
- // the client to use for non user-specific queries
- // should be the client of the default user
- defaultClient *githubv4.Client
-
- // the token of the default user
- defaultToken *auth.Token
-
// github repository ID
repositoryID string
@@ -58,43 +53,33 @@ func (ge *githubExporter) Init(repo *cache.RepoCache, conf core.Configuration) e
ge.cachedOperationIDs = make(map[entity.Id]string)
ge.cachedLabels = make(map[string]string)
- user, err := repo.GetUserIdentity()
- if err != nil {
- return err
- }
-
// preload all clients
- err = ge.cacheAllClient(repo)
- if err != nil {
- return err
- }
-
- ge.defaultClient, err = ge.getClientForIdentity(user.Id())
- if err != nil {
- return err
- }
-
- creds, err := auth.List(repo, auth.WithUserId(user.Id()), auth.WithTarget(target), auth.WithKind(auth.KindToken))
+ err := ge.cacheAllClient(repo)
if err != nil {
return err
}
- if len(creds) == 0 {
- return ErrMissingIdentityToken
- }
-
- ge.defaultToken = creds[0].(*auth.Token)
-
return nil
}
-func (ge *githubExporter) cacheAllClient(repo repository.RepoConfig) error {
+func (ge *githubExporter) cacheAllClient(repo *cache.RepoCache) error {
creds, err := auth.List(repo, auth.WithTarget(target), auth.WithKind(auth.KindToken))
if err != nil {
return err
}
for _, cred := range creds {
+ login, ok := cred.Metadata()[auth.MetaKeyLogin]
+ if !ok {
+ _, _ = fmt.Fprintf(os.Stderr, "credential %s is not tagged with Github login\n", cred.ID().Human())
+ continue
+ }
+
+ user, err := repo.ResolveIdentityImmutableMetadata(metaKeyGithubLogin, login)
+ if err == identity.ErrIdentityNotExist {
+ continue
+ }
+
if _, ok := ge.identityClient[cred.UserId()]; !ok {
client := buildClient(creds[0].(*auth.Token))
ge.identityClient[cred.UserId()] = client
diff --git a/bridge/github/import.go b/bridge/github/import.go
index 39aebccb..aac4f119 100644
--- a/bridge/github/import.go
+++ b/bridge/github/import.go
@@ -12,7 +12,6 @@ import (
"github.com/MichaelMure/git-bug/bug"
"github.com/MichaelMure/git-bug/cache"
"github.com/MichaelMure/git-bug/entity"
- "github.com/MichaelMure/git-bug/identity"
"github.com/MichaelMure/git-bug/util/text"
)
@@ -39,20 +38,7 @@ type githubImporter struct {
func (gi *githubImporter) Init(repo *cache.RepoCache, conf core.Configuration) error {
gi.conf = conf
- opts := []auth.Option{
- auth.WithTarget(target),
- auth.WithKind(auth.KindToken),
- }
-
- user, err := repo.GetUserIdentity()
- if err == nil {
- opts = append(opts, auth.WithUserId(user.Id()))
- }
- if err == identity.ErrNoIdentitySet {
- opts = append(opts, auth.WithUserId(auth.DefaultUserId))
- }
-
- creds, err := auth.List(repo, opts...)
+ creds, err := auth.List(repo, auth.WithTarget(target), auth.WithKind(auth.KindToken))
if err != nil {
return err
}
diff --git a/bridge/github/import_test.go b/bridge/github/import_test.go
index 57bab61e..75310ab3 100644
--- a/bridge/github/import_test.go
+++ b/bridge/github/import_test.go
@@ -140,13 +140,7 @@ func Test_Importer(t *testing.T) {
t.Skip("Env var GITHUB_TOKEN_PRIVATE missing")
}
- err = author.Commit(repo)
- require.NoError(t, err)
-
- err = identity.SetUserIdentity(repo, author)
- require.NoError(t, err)
-
- token := auth.NewToken(author.Id(), envToken, target)
+ token := auth.NewToken(envToken, target)
err = auth.Store(repo, token)
require.NoError(t, err)