aboutsummaryrefslogtreecommitdiffstats
path: root/bridge
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2021-04-09 13:01:14 +0200
committerMichael Muré <batolettre@gmail.com>2021-04-09 13:01:14 +0200
commit1520f678f7a2bc6e01d9b01df5ce49f2f46be7d7 (patch)
treef6d71c1f29cf06ccab9e4ae434b19ab17caa4385 /bridge
parent0fd570171d171aa574d7f01d6033a9c01d668465 (diff)
parentbc5f618eba812859bf87ce2c31b278bd518d4555 (diff)
downloadgit-bug-1520f678f7a2bc6e01d9b01df5ce49f2f46be7d7.tar.gz
Merge remote-tracking branch 'origin/master' into dev-gh-bridge
Diffstat (limited to 'bridge')
-rw-r--r--bridge/core/auth/credential.go6
-rw-r--r--bridge/core/auth/credential_test.go4
-rw-r--r--bridge/github/export.go2
-rw-r--r--bridge/github/export_test.go2
-rw-r--r--bridge/github/import.go2
-rw-r--r--bridge/github/import_test.go63
-rw-r--r--bridge/gitlab/export.go2
-rw-r--r--bridge/gitlab/export_test.go2
-rw-r--r--bridge/gitlab/import.go1
-rw-r--r--bridge/gitlab/import_test.go71
-rw-r--r--bridge/jira/export.go2
-rw-r--r--bridge/jira/import.go1
-rw-r--r--bridge/launchpad/import.go1
13 files changed, 78 insertions, 81 deletions
diff --git a/bridge/core/auth/credential.go b/bridge/core/auth/credential.go
index 2327a6fc..20343c9c 100644
--- a/bridge/core/auth/credential.go
+++ b/bridge/core/auth/credential.go
@@ -3,12 +3,13 @@ package auth
import (
"encoding/base64"
"encoding/json"
- "errors"
"fmt"
"strconv"
"strings"
"time"
+ "github.com/pkg/errors"
+
"github.com/MichaelMure/git-bug/entity"
"github.com/MichaelMure/git-bug/repository"
)
@@ -159,7 +160,8 @@ func List(repo repository.RepoKeyring, opts ...ListOption) ([]Credential, error)
item, err := repo.Keyring().Get(key)
if err != nil {
- return nil, err
+ // skip unreadable items, nothing much we can do for them anyway
+ continue
}
cred, err := decode(item)
diff --git a/bridge/core/auth/credential_test.go b/bridge/core/auth/credential_test.go
index 60c631d7..8bb25835 100644
--- a/bridge/core/auth/credential_test.go
+++ b/bridge/core/auth/credential_test.go
@@ -11,7 +11,7 @@ import (
)
func TestCredential(t *testing.T) {
- repo := repository.NewMockRepoForTest()
+ repo := repository.NewMockRepo()
storeToken := func(val string, target string) *Token {
token := NewToken(target, val)
@@ -102,7 +102,7 @@ func sameIds(t *testing.T, a []Credential, b []Credential) {
}
func testCredentialSerial(t *testing.T, original Credential) Credential {
- repo := repository.NewMockRepoForTest()
+ repo := repository.NewMockRepo()
original.SetMetadata("test", "value")
diff --git a/bridge/github/export.go b/bridge/github/export.go
index 57b52ee0..1a59fbb3 100644
--- a/bridge/github/export.go
+++ b/bridge/github/export.go
@@ -294,7 +294,7 @@ func (ge *githubExporter) exportBug(ctx context.Context, b *cache.BugCache, out
continue
}
- opAuthor := op.GetAuthor()
+ opAuthor := op.Author()
client, err := ge.getClientForIdentity(opAuthor.Id())
if err != nil {
continue
diff --git a/bridge/github/export_test.go b/bridge/github/export_test.go
index 5b9a3495..b7a36bcf 100644
--- a/bridge/github/export_test.go
+++ b/bridge/github/export_test.go
@@ -126,7 +126,7 @@ func testCases(t *testing.T, repo *cache.RepoCache) []*testCase {
}
}
-func TestPushPull(t *testing.T) {
+func TestGithubPushPull(t *testing.T) {
// repo owner
envUser := os.Getenv("GITHUB_TEST_USER")
diff --git a/bridge/github/import.go b/bridge/github/import.go
index e89f34c4..47be6374 100644
--- a/bridge/github/import.go
+++ b/bridge/github/import.go
@@ -543,6 +543,7 @@ func (gi *githubImporter) ensurePerson(ctx context.Context, repo *cache.RepoCach
email,
string(actor.Login),
string(actor.AvatarUrl),
+ nil,
map[string]string{
metaKeyGithubLogin: string(actor.Login),
},
@@ -576,6 +577,7 @@ func (gi *githubImporter) getGhost(ctx context.Context, repo *cache.RepoCache) (
"",
string(user.Login),
string(user.AvatarUrl),
+ nil,
map[string]string{
metaKeyGithubLogin: string(user.Login),
},
diff --git a/bridge/github/import_test.go b/bridge/github/import_test.go
index 2295806f..324d5421 100644
--- a/bridge/github/import_test.go
+++ b/bridge/github/import_test.go
@@ -7,7 +7,6 @@ import (
"testing"
"time"
- "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/MichaelMure/git-bug/bridge/core"
@@ -19,8 +18,23 @@ import (
"github.com/MichaelMure/git-bug/util/interrupt"
)
-func Test_Importer(t *testing.T) {
- author := identity.NewIdentity("Michael Muré", "batolettre@gmail.com")
+func TestGithubImporter(t *testing.T) {
+ envToken := os.Getenv("GITHUB_TOKEN_PRIVATE")
+ if envToken == "" {
+ t.Skip("Env var GITHUB_TOKEN_PRIVATE missing")
+ }
+
+ repo := repository.CreateGoGitTestRepo(false)
+ defer repository.CleanupTestRepos(repo)
+
+ backend, err := cache.NewRepoCache(repo)
+ require.NoError(t, err)
+
+ defer backend.Close()
+ interrupt.RegisterCleaner(backend.Close)
+
+ author, err := identity.NewIdentity(repo, "Michael Muré", "batolettre@gmail.com")
+ require.NoError(t, err)
tests := []struct {
name string
@@ -127,20 +141,6 @@ func Test_Importer(t *testing.T) {
},
}
- repo := repository.CreateGoGitTestRepo(false)
- defer repository.CleanupTestRepos(repo)
-
- backend, err := cache.NewRepoCache(repo)
- require.NoError(t, err)
-
- defer backend.Close()
- interrupt.RegisterCleaner(backend.Close)
-
- envToken := os.Getenv("GITHUB_TOKEN_PRIVATE")
- if envToken == "" {
- t.Skip("Env var GITHUB_TOKEN_PRIVATE missing")
- }
-
login := "test-identity"
author.SetMetadata(metaKeyGithubLogin, login)
@@ -178,33 +178,28 @@ func Test_Importer(t *testing.T) {
require.NoError(t, err)
ops := b.Snapshot().Operations
- assert.Len(t, tt.bug.Operations, len(b.Snapshot().Operations))
+ require.Len(t, tt.bug.Operations, len(b.Snapshot().Operations))
for i, op := range tt.bug.Operations {
require.IsType(t, ops[i], op)
+ require.Equal(t, op.Author().Name(), ops[i].Author().Name())
- switch op.(type) {
+ switch op := op.(type) {
case *bug.CreateOperation:
- assert.Equal(t, op.(*bug.CreateOperation).Title, ops[i].(*bug.CreateOperation).Title)
- assert.Equal(t, op.(*bug.CreateOperation).Message, ops[i].(*bug.CreateOperation).Message)
- assert.Equal(t, op.(*bug.CreateOperation).Author.Name(), ops[i].(*bug.CreateOperation).Author.Name())
+ require.Equal(t, op.Title, ops[i].(*bug.CreateOperation).Title)
+ require.Equal(t, op.Message, ops[i].(*bug.CreateOperation).Message)
case *bug.SetStatusOperation:
- assert.Equal(t, op.(*bug.SetStatusOperation).Status, ops[i].(*bug.SetStatusOperation).Status)
- assert.Equal(t, op.(*bug.SetStatusOperation).Author.Name(), ops[i].(*bug.SetStatusOperation).Author.Name())
+ require.Equal(t, op.Status, ops[i].(*bug.SetStatusOperation).Status)
case *bug.SetTitleOperation:
- assert.Equal(t, op.(*bug.SetTitleOperation).Was, ops[i].(*bug.SetTitleOperation).Was)
- assert.Equal(t, op.(*bug.SetTitleOperation).Title, ops[i].(*bug.SetTitleOperation).Title)
- assert.Equal(t, op.(*bug.SetTitleOperation).Author.Name(), ops[i].(*bug.SetTitleOperation).Author.Name())
+ require.Equal(t, op.Was, ops[i].(*bug.SetTitleOperation).Was)
+ require.Equal(t, op.Title, ops[i].(*bug.SetTitleOperation).Title)
case *bug.LabelChangeOperation:
- assert.ElementsMatch(t, op.(*bug.LabelChangeOperation).Added, ops[i].(*bug.LabelChangeOperation).Added)
- assert.ElementsMatch(t, op.(*bug.LabelChangeOperation).Removed, ops[i].(*bug.LabelChangeOperation).Removed)
- assert.Equal(t, op.(*bug.LabelChangeOperation).Author.Name(), ops[i].(*bug.LabelChangeOperation).Author.Name())
+ require.ElementsMatch(t, op.Added, ops[i].(*bug.LabelChangeOperation).Added)
+ require.ElementsMatch(t, op.Removed, ops[i].(*bug.LabelChangeOperation).Removed)
case *bug.AddCommentOperation:
- assert.Equal(t, op.(*bug.AddCommentOperation).Message, ops[i].(*bug.AddCommentOperation).Message)
- assert.Equal(t, op.(*bug.AddCommentOperation).Author.Name(), ops[i].(*bug.AddCommentOperation).Author.Name())
+ require.Equal(t, op.Message, ops[i].(*bug.AddCommentOperation).Message)
case *bug.EditCommentOperation:
- assert.Equal(t, op.(*bug.EditCommentOperation).Message, ops[i].(*bug.EditCommentOperation).Message)
- assert.Equal(t, op.(*bug.EditCommentOperation).Author.Name(), ops[i].(*bug.EditCommentOperation).Author.Name())
+ require.Equal(t, op.Message, ops[i].(*bug.EditCommentOperation).Message)
default:
panic("unknown operation type")
diff --git a/bridge/gitlab/export.go b/bridge/gitlab/export.go
index c3aa6202..9c3864ec 100644
--- a/bridge/gitlab/export.go
+++ b/bridge/gitlab/export.go
@@ -267,7 +267,7 @@ func (ge *gitlabExporter) exportBug(ctx context.Context, b *cache.BugCache, out
continue
}
- opAuthor := op.GetAuthor()
+ opAuthor := op.Author()
client, err := ge.getIdentityClient(opAuthor.Id())
if err != nil {
continue
diff --git a/bridge/gitlab/export_test.go b/bridge/gitlab/export_test.go
index 58f3d63c..88b0d44e 100644
--- a/bridge/gitlab/export_test.go
+++ b/bridge/gitlab/export_test.go
@@ -134,7 +134,7 @@ func testCases(t *testing.T, repo *cache.RepoCache) []*testCase {
}
}
-func TestPushPull(t *testing.T) {
+func TestGitlabPushPull(t *testing.T) {
// token must have 'repo' and 'delete_repo' scopes
envToken := os.Getenv("GITLAB_API_TOKEN")
if envToken == "" {
diff --git a/bridge/gitlab/import.go b/bridge/gitlab/import.go
index 93c6a1a9..7dc99056 100644
--- a/bridge/gitlab/import.go
+++ b/bridge/gitlab/import.go
@@ -403,6 +403,7 @@ func (gi *gitlabImporter) ensurePerson(repo *cache.RepoCache, id int) (*cache.Id
user.PublicEmail,
user.Username,
user.AvatarURL,
+ nil,
map[string]string{
// because Gitlab
metaKeyGitlabId: strconv.Itoa(id),
diff --git a/bridge/gitlab/import_test.go b/bridge/gitlab/import_test.go
index db550f08..1405e43b 100644
--- a/bridge/gitlab/import_test.go
+++ b/bridge/gitlab/import_test.go
@@ -7,7 +7,6 @@ import (
"testing"
"time"
- "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/MichaelMure/git-bug/bridge/core"
@@ -19,8 +18,28 @@ import (
"github.com/MichaelMure/git-bug/util/interrupt"
)
-func TestImport(t *testing.T) {
- author := identity.NewIdentity("Amine Hilaly", "hilalyamine@gmail.com")
+func TestGitlabImport(t *testing.T) {
+ envToken := os.Getenv("GITLAB_API_TOKEN")
+ if envToken == "" {
+ t.Skip("Env var GITLAB_API_TOKEN missing")
+ }
+
+ projectID := os.Getenv("GITLAB_PROJECT_ID")
+ if projectID == "" {
+ t.Skip("Env var GITLAB_PROJECT_ID missing")
+ }
+
+ repo := repository.CreateGoGitTestRepo(false)
+ defer repository.CleanupTestRepos(repo)
+
+ backend, err := cache.NewRepoCache(repo)
+ require.NoError(t, err)
+
+ defer backend.Close()
+ interrupt.RegisterCleaner(backend.Close)
+
+ author, err := identity.NewIdentity(repo, "Amine Hilaly", "hilalyamine@gmail.com")
+ require.NoError(t, err)
tests := []struct {
name string
@@ -76,25 +95,6 @@ func TestImport(t *testing.T) {
},
}
- repo := repository.CreateGoGitTestRepo(false)
- defer repository.CleanupTestRepos(repo)
-
- backend, err := cache.NewRepoCache(repo)
- require.NoError(t, err)
-
- defer backend.Close()
- interrupt.RegisterCleaner(backend.Close)
-
- envToken := os.Getenv("GITLAB_API_TOKEN")
- if envToken == "" {
- t.Skip("Env var GITLAB_API_TOKEN missing")
- }
-
- projectID := os.Getenv("GITLAB_PROJECT_ID")
- if projectID == "" {
- t.Skip("Env var GITLAB_PROJECT_ID missing")
- }
-
login := "test-identity"
author.SetMetadata(metaKeyGitlabLogin, login)
@@ -138,29 +138,24 @@ func TestImport(t *testing.T) {
for i, op := range tt.bug.Operations {
require.IsType(t, ops[i], op)
+ require.Equal(t, op.Author().Name(), ops[i].Author().Name())
- switch op.(type) {
+ switch op := op.(type) {
case *bug.CreateOperation:
- assert.Equal(t, op.(*bug.CreateOperation).Title, ops[i].(*bug.CreateOperation).Title)
- assert.Equal(t, op.(*bug.CreateOperation).Message, ops[i].(*bug.CreateOperation).Message)
- assert.Equal(t, op.(*bug.CreateOperation).Author.Name(), ops[i].(*bug.CreateOperation).Author.Name())
+ require.Equal(t, op.Title, ops[i].(*bug.CreateOperation).Title)
+ require.Equal(t, op.Message, ops[i].(*bug.CreateOperation).Message)
case *bug.SetStatusOperation:
- assert.Equal(t, op.(*bug.SetStatusOperation).Status, ops[i].(*bug.SetStatusOperation).Status)
- assert.Equal(t, op.(*bug.SetStatusOperation).Author.Name(), ops[i].(*bug.SetStatusOperation).Author.Name())
+ require.Equal(t, op.Status, ops[i].(*bug.SetStatusOperation).Status)
case *bug.SetTitleOperation:
- assert.Equal(t, op.(*bug.SetTitleOperation).Was, ops[i].(*bug.SetTitleOperation).Was)
- assert.Equal(t, op.(*bug.SetTitleOperation).Title, ops[i].(*bug.SetTitleOperation).Title)
- assert.Equal(t, op.(*bug.SetTitleOperation).Author.Name(), ops[i].(*bug.SetTitleOperation).Author.Name())
+ require.Equal(t, op.Was, ops[i].(*bug.SetTitleOperation).Was)
+ require.Equal(t, op.Title, ops[i].(*bug.SetTitleOperation).Title)
case *bug.LabelChangeOperation:
- assert.ElementsMatch(t, op.(*bug.LabelChangeOperation).Added, ops[i].(*bug.LabelChangeOperation).Added)
- assert.ElementsMatch(t, op.(*bug.LabelChangeOperation).Removed, ops[i].(*bug.LabelChangeOperation).Removed)
- assert.Equal(t, op.(*bug.LabelChangeOperation).Author.Name(), ops[i].(*bug.LabelChangeOperation).Author.Name())
+ require.ElementsMatch(t, op.Added, ops[i].(*bug.LabelChangeOperation).Added)
+ require.ElementsMatch(t, op.Removed, ops[i].(*bug.LabelChangeOperation).Removed)
case *bug.AddCommentOperation:
- assert.Equal(t, op.(*bug.AddCommentOperation).Message, ops[i].(*bug.AddCommentOperation).Message)
- assert.Equal(t, op.(*bug.AddCommentOperation).Author.Name(), ops[i].(*bug.AddCommentOperation).Author.Name())
+ require.Equal(t, op.Message, ops[i].(*bug.AddCommentOperation).Message)
case *bug.EditCommentOperation:
- assert.Equal(t, op.(*bug.EditCommentOperation).Message, ops[i].(*bug.EditCommentOperation).Message)
- assert.Equal(t, op.(*bug.EditCommentOperation).Author.Name(), ops[i].(*bug.EditCommentOperation).Author.Name())
+ require.Equal(t, op.Message, ops[i].(*bug.EditCommentOperation).Message)
default:
panic("unknown operation type")
diff --git a/bridge/jira/export.go b/bridge/jira/export.go
index e6167966..34f41d09 100644
--- a/bridge/jira/export.go
+++ b/bridge/jira/export.go
@@ -309,7 +309,7 @@ func (je *jiraExporter) exportBug(ctx context.Context, b *cache.BugCache, out ch
continue
}
- opAuthor := op.GetAuthor()
+ opAuthor := op.Author()
client, err := je.getClientForIdentity(opAuthor.Id())
if err != nil {
out <- core.NewExportError(
diff --git a/bridge/jira/import.go b/bridge/jira/import.go
index 54c4ca35..f9daadd8 100644
--- a/bridge/jira/import.go
+++ b/bridge/jira/import.go
@@ -198,6 +198,7 @@ func (ji *jiraImporter) ensurePerson(repo *cache.RepoCache, user User) (*cache.I
user.EmailAddress,
user.Key,
"",
+ nil,
map[string]string{
metaKeyJiraUser: user.Key,
},
diff --git a/bridge/launchpad/import.go b/bridge/launchpad/import.go
index ce50828b..6b5667ba 100644
--- a/bridge/launchpad/import.go
+++ b/bridge/launchpad/import.go
@@ -35,6 +35,7 @@ func (li *launchpadImporter) ensurePerson(repo *cache.RepoCache, owner LPPerson)
"",
owner.Login,
"",
+ nil,
map[string]string{
metaKeyLaunchpadLogin: owner.Login,
},