aboutsummaryrefslogtreecommitdiffstats
path: root/bridge
diff options
context:
space:
mode:
Diffstat (limited to 'bridge')
-rw-r--r--bridge/core/config.go7
-rw-r--r--bridge/github/config.go12
-rw-r--r--bridge/github/export.go9
-rw-r--r--bridge/github/export_test.go22
-rw-r--r--bridge/github/import.go15
-rw-r--r--bridge/github/import_integration_test.go13
-rw-r--r--bridge/github/import_test.go6
-rw-r--r--bridge/gitlab/export.go9
-rw-r--r--bridge/gitlab/export_test.go22
-rw-r--r--bridge/gitlab/import.go11
-rw-r--r--bridge/gitlab/import_test.go6
-rw-r--r--bridge/jira/export.go9
-rw-r--r--bridge/jira/import.go12
-rw-r--r--bridge/launchpad/import.go13
14 files changed, 75 insertions, 91 deletions
diff --git a/bridge/core/config.go b/bridge/core/config.go
index 45f1afa4..ed079eb8 100644
--- a/bridge/core/config.go
+++ b/bridge/core/config.go
@@ -5,12 +5,13 @@ import (
"github.com/MichaelMure/git-bug/cache"
"github.com/MichaelMure/git-bug/entities/identity"
+ "github.com/MichaelMure/git-bug/entity"
)
func FinishConfig(repo *cache.RepoCache, metaKey string, login string) error {
// if no user exist with the given login metadata
- _, err := repo.ResolveIdentityImmutableMetadata(metaKey, login)
- if err != nil && err != identity.ErrIdentityNotExist {
+ _, err := repo.Identities().ResolveIdentityImmutableMetadata(metaKey, login)
+ if err != nil && !entity.IsErrNotFound(err) {
// real error
return err
}
@@ -33,7 +34,7 @@ func FinishConfig(repo *cache.RepoCache, metaKey string, login string) error {
}
// otherwise create a user with that metadata
- i, err := repo.NewIdentityFromGitUserRaw(map[string]string{
+ i, err := repo.Identities().NewFromGitUserRaw(map[string]string{
metaKey: login,
})
if err != nil {
diff --git a/bridge/github/config.go b/bridge/github/config.go
index 6b847394..2f5d1f3b 100644
--- a/bridge/github/config.go
+++ b/bridge/github/config.go
@@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
- "math/rand"
"net/http"
"net/url"
"regexp"
@@ -319,17 +318,6 @@ func pollGithubForAuthorization(deviceCode string, intervalSec int64) (string, e
}
}
-func randomFingerprint() string {
- // Doesn't have to be crypto secure, it's just to avoid token collision
- rand.Seed(time.Now().UnixNano())
- var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
- b := make([]rune, 32)
- for i := range b {
- b[i] = letterRunes[rand.Intn(len(letterRunes))]
- }
- return string(b)
-}
-
func promptTokenOptions(repo repository.RepoKeyring, login, owner, project string) (auth.Credential, error) {
creds, err := auth.List(repo,
auth.WithTarget(target),
diff --git a/bridge/github/export.go b/bridge/github/export.go
index 675ed039..0d340b49 100644
--- a/bridge/github/export.go
+++ b/bridge/github/export.go
@@ -20,7 +20,6 @@ import (
"github.com/MichaelMure/git-bug/cache"
"github.com/MichaelMure/git-bug/entities/bug"
"github.com/MichaelMure/git-bug/entities/common"
- "github.com/MichaelMure/git-bug/entities/identity"
"github.com/MichaelMure/git-bug/entity"
"github.com/MichaelMure/git-bug/entity/dag"
)
@@ -89,8 +88,8 @@ func (ge *githubExporter) cacheAllClient(repo *cache.RepoCache) error {
continue
}
- user, err := repo.ResolveIdentityImmutableMetadata(metaKeyGithubLogin, login)
- if err == identity.ErrIdentityNotExist {
+ user, err := repo.Identities().ResolveIdentityImmutableMetadata(metaKeyGithubLogin, login)
+ if entity.IsErrNotFound(err) {
continue
}
if err != nil {
@@ -160,10 +159,10 @@ func (ge *githubExporter) ExportAll(ctx context.Context, repo *cache.RepoCache,
allIdentitiesIds = append(allIdentitiesIds, id)
}
- allBugsIds := repo.AllBugsIds()
+ allBugsIds := repo.Bugs().AllIds()
for _, id := range allBugsIds {
- b, err := repo.ResolveBug(id)
+ b, err := repo.Bugs().Resolve(id)
if err != nil {
out <- core.NewExportError(errors.Wrap(err, "can't load bug"), id)
return
diff --git a/bridge/github/export_test.go b/bridge/github/export_test.go
index b7511a3d..e06457d4 100644
--- a/bridge/github/export_test.go
+++ b/bridge/github/export_test.go
@@ -34,18 +34,18 @@ type testCase struct {
func testCases(t *testing.T, repo *cache.RepoCache) []*testCase {
// simple bug
- simpleBug, _, err := repo.NewBug("simple bug", "new bug")
+ simpleBug, _, err := repo.Bugs().New("simple bug", "new bug")
require.NoError(t, err)
// bug with comments
- bugWithComments, _, err := repo.NewBug("bug with comments", "new bug")
+ bugWithComments, _, err := repo.Bugs().New("bug with comments", "new bug")
require.NoError(t, err)
_, _, err = bugWithComments.AddComment("new comment")
require.NoError(t, err)
// bug with label changes
- bugLabelChange, _, err := repo.NewBug("bug label change", "new bug")
+ bugLabelChange, _, err := repo.Bugs().New("bug label change", "new bug")
require.NoError(t, err)
_, _, err = bugLabelChange.ChangeLabels([]string{"bug"}, nil)
@@ -64,7 +64,7 @@ func testCases(t *testing.T, repo *cache.RepoCache) []*testCase {
require.NoError(t, err)
// bug with comments editions
- bugWithCommentEditions, createOp, err := repo.NewBug("bug with comments editions", "new bug")
+ bugWithCommentEditions, createOp, err := repo.Bugs().New("bug with comments editions", "new bug")
require.NoError(t, err)
_, err = bugWithCommentEditions.EditComment(
@@ -78,7 +78,7 @@ func testCases(t *testing.T, repo *cache.RepoCache) []*testCase {
require.NoError(t, err)
// bug status changed
- bugStatusChanged, _, err := repo.NewBug("bug status changed", "new bug")
+ bugStatusChanged, _, err := repo.Bugs().New("bug status changed", "new bug")
require.NoError(t, err)
_, err = bugStatusChanged.Close()
@@ -88,7 +88,7 @@ func testCases(t *testing.T, repo *cache.RepoCache) []*testCase {
require.NoError(t, err)
// bug title changed
- bugTitleEdited, _, err := repo.NewBug("bug title edited", "new bug")
+ bugTitleEdited, _, err := repo.Bugs().New("bug title edited", "new bug")
require.NoError(t, err)
_, err = bugTitleEdited.SetTitle("bug title edited again")
@@ -141,12 +141,12 @@ func TestGithubPushPull(t *testing.T) {
// create repo backend
repo := repository.CreateGoGitTestRepo(t, false)
- backend, err := cache.NewRepoCache(repo)
+ backend, err := cache.NewRepoCacheNoEvents(repo)
require.NoError(t, err)
// set author identity
login := "identity-test"
- author, err := backend.NewIdentity("test identity", "test@test.org")
+ author, err := backend.Identities().New("test identity", "test@test.org")
require.NoError(t, err)
author.SetMetadata(metaKeyGithubLogin, login)
err = author.Commit()
@@ -224,7 +224,7 @@ func TestGithubPushPull(t *testing.T) {
repoTwo := repository.CreateGoGitTestRepo(t, false)
// create a second backend
- backendTwo, err := cache.NewRepoCache(repoTwo)
+ backendTwo, err := cache.NewRepoCacheNoEvents(repoTwo)
require.NoError(t, err)
importer := &githubImporter{}
@@ -243,7 +243,7 @@ func TestGithubPushPull(t *testing.T) {
require.NoError(t, result.Err)
}
- require.Len(t, backendTwo.AllBugsIds(), len(tests))
+ require.Len(t, backendTwo.Bugs().AllIds(), len(tests))
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
@@ -268,7 +268,7 @@ func TestGithubPushPull(t *testing.T) {
require.True(t, ok)
// retrieve bug from backendTwo
- importedBug, err := backendTwo.ResolveBugCreateMetadata(metaKeyGithubId, bugGithubID)
+ importedBug, err := backendTwo.Bugs().ResolveBugCreateMetadata(metaKeyGithubId, bugGithubID)
require.NoError(t, err)
// verify bug have same number of original operations
diff --git a/bridge/github/import.go b/bridge/github/import.go
index 7ccac3fb..4a51d117 100644
--- a/bridge/github/import.go
+++ b/bridge/github/import.go
@@ -10,7 +10,6 @@ import (
"github.com/MichaelMure/git-bug/bridge/core"
"github.com/MichaelMure/git-bug/bridge/core/auth"
"github.com/MichaelMure/git-bug/cache"
- "github.com/MichaelMure/git-bug/entities/bug"
"github.com/MichaelMure/git-bug/entity"
"github.com/MichaelMure/git-bug/util/text"
)
@@ -183,14 +182,14 @@ func (gi *githubImporter) ensureIssue(ctx context.Context, repo *cache.RepoCache
}
// resolve bug
- b, err := repo.ResolveBugMatcher(func(excerpt *cache.BugExcerpt) bool {
+ b, err := repo.Bugs().ResolveMatcher(func(excerpt *cache.BugExcerpt) bool {
return excerpt.CreateMetadata[metaKeyGithubUrl] == issue.Url.String() &&
excerpt.CreateMetadata[metaKeyGithubId] == parseId(issue.Id)
})
if err == nil {
return b, nil
}
- if err != bug.ErrBugNotExist {
+ if !entity.IsErrNotFound(err) {
return nil, err
}
@@ -213,7 +212,7 @@ func (gi *githubImporter) ensureIssue(ctx context.Context, repo *cache.RepoCache
}
// create bug
- b, _, err = repo.NewBugRaw(
+ b, _, err = repo.Bugs().NewRaw(
author,
issue.CreatedAt.Unix(),
text.CleanupOneLine(title), // TODO: this is the *current* title, not the original one
@@ -498,7 +497,7 @@ func (gi *githubImporter) ensurePerson(ctx context.Context, repo *cache.RepoCach
}
// Look first in the cache
- i, err := repo.ResolveIdentityImmutableMetadata(metaKeyGithubLogin, string(actor.Login))
+ i, err := repo.Identities().ResolveIdentityImmutableMetadata(metaKeyGithubLogin, string(actor.Login))
if err == nil {
return i, nil
}
@@ -531,7 +530,7 @@ func (gi *githubImporter) ensurePerson(ctx context.Context, repo *cache.RepoCach
name = string(actor.Login)
}
- i, err = repo.NewIdentityRaw(
+ i, err = repo.Identities().NewRaw(
name,
email,
string(actor.Login),
@@ -553,7 +552,7 @@ func (gi *githubImporter) ensurePerson(ctx context.Context, repo *cache.RepoCach
func (gi *githubImporter) getGhost(ctx context.Context, repo *cache.RepoCache) (*cache.IdentityCache, error) {
loginName := "ghost"
// Look first in the cache
- i, err := repo.ResolveIdentityImmutableMetadata(metaKeyGithubLogin, loginName)
+ i, err := repo.Identities().ResolveIdentityImmutableMetadata(metaKeyGithubLogin, loginName)
if err == nil {
return i, nil
}
@@ -568,7 +567,7 @@ func (gi *githubImporter) getGhost(ctx context.Context, repo *cache.RepoCache) (
if user.Name != nil {
userName = string(*user.Name)
}
- return repo.NewIdentityRaw(
+ return repo.Identities().NewRaw(
userName,
"",
string(user.Login),
diff --git a/bridge/github/import_integration_test.go b/bridge/github/import_integration_test.go
index 50cbd5c8..8c411d8d 100644
--- a/bridge/github/import_integration_test.go
+++ b/bridge/github/import_integration_test.go
@@ -34,8 +34,9 @@ func TestGithubImporterIntegration(t *testing.T) {
// arrange
repo := repository.CreateGoGitTestRepo(t, false)
- backend, err := cache.NewRepoCache(repo)
+ backend, err := cache.NewRepoCacheNoEvents(repo)
require.NoError(t, err)
+
defer backend.Close()
interrupt.RegisterCleaner(backend.Close)
require.NoError(t, err)
@@ -48,17 +49,17 @@ func TestGithubImporterIntegration(t *testing.T) {
for e := range events {
require.NoError(t, e.Err)
}
- require.Len(t, backend.AllBugsIds(), 5)
- require.Len(t, backend.AllIdentityIds(), 2)
+ require.Len(t, backend.Bugs().AllIds(), 5)
+ require.Len(t, backend.Identities().AllIds(), 2)
- b1, err := backend.ResolveBugCreateMetadata(metaKeyGithubUrl, "https://github.com/marcus/to-himself/issues/1")
+ b1, err := backend.Bugs().ResolveBugCreateMetadata(metaKeyGithubUrl, "https://github.com/marcus/to-himself/issues/1")
require.NoError(t, err)
ops1 := b1.Snapshot().Operations
require.Equal(t, "marcus", ops1[0].Author().Name())
require.Equal(t, "title 1", ops1[0].(*bug.CreateOperation).Title)
require.Equal(t, "body text 1", ops1[0].(*bug.CreateOperation).Message)
- b3, err := backend.ResolveBugCreateMetadata(metaKeyGithubUrl, "https://github.com/marcus/to-himself/issues/3")
+ b3, err := backend.Bugs().ResolveBugCreateMetadata(metaKeyGithubUrl, "https://github.com/marcus/to-himself/issues/3")
require.NoError(t, err)
ops3 := b3.Snapshot().Operations
require.Equal(t, "issue 3 comment 1", ops3[1].(*bug.AddCommentOperation).Message)
@@ -66,7 +67,7 @@ func TestGithubImporterIntegration(t *testing.T) {
require.Equal(t, []bug.Label{"bug"}, ops3[3].(*bug.LabelChangeOperation).Added)
require.Equal(t, "title 3, edit 1", ops3[4].(*bug.SetTitleOperation).Title)
- b4, err := backend.ResolveBugCreateMetadata(metaKeyGithubUrl, "https://github.com/marcus/to-himself/issues/4")
+ b4, err := backend.Bugs().ResolveBugCreateMetadata(metaKeyGithubUrl, "https://github.com/marcus/to-himself/issues/4")
require.NoError(t, err)
ops4 := b4.Snapshot().Operations
require.Equal(t, "edited", ops4[1].(*bug.EditCommentOperation).Message)
diff --git a/bridge/github/import_test.go b/bridge/github/import_test.go
index 5575de98..5fafcce1 100644
--- a/bridge/github/import_test.go
+++ b/bridge/github/import_test.go
@@ -28,7 +28,7 @@ func TestGithubImporter(t *testing.T) {
repo := repository.CreateGoGitTestRepo(t, false)
- backend, err := cache.NewRepoCache(repo)
+ backend, err := cache.NewRepoCacheNoEvents(repo)
require.NoError(t, err)
defer backend.Close()
@@ -171,11 +171,11 @@ func TestGithubImporter(t *testing.T) {
fmt.Printf("test repository imported in %f seconds\n", time.Since(start).Seconds())
- require.Len(t, backend.AllBugsIds(), len(tests))
+ require.Len(t, backend.Bugs().AllIds(), len(tests))
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
- b, err := backend.ResolveBugCreateMetadata(metaKeyGithubUrl, tt.url)
+ b, err := backend.Bugs().ResolveBugCreateMetadata(metaKeyGithubUrl, tt.url)
require.NoError(t, err)
ops := b.Snapshot().Operations
diff --git a/bridge/gitlab/export.go b/bridge/gitlab/export.go
index 83465428..b3a02447 100644
--- a/bridge/gitlab/export.go
+++ b/bridge/gitlab/export.go
@@ -15,7 +15,6 @@ import (
"github.com/MichaelMure/git-bug/cache"
"github.com/MichaelMure/git-bug/entities/bug"
"github.com/MichaelMure/git-bug/entities/common"
- "github.com/MichaelMure/git-bug/entities/identity"
"github.com/MichaelMure/git-bug/entity"
"github.com/MichaelMure/git-bug/entity/dag"
)
@@ -74,8 +73,8 @@ func (ge *gitlabExporter) cacheAllClient(repo *cache.RepoCache, baseURL string)
continue
}
- user, err := repo.ResolveIdentityImmutableMetadata(metaKeyGitlabLogin, login)
- if err == identity.ErrIdentityNotExist {
+ user, err := repo.Identities().ResolveIdentityImmutableMetadata(metaKeyGitlabLogin, login)
+ if entity.IsErrNotFound(err) {
continue
}
if err != nil {
@@ -116,14 +115,14 @@ func (ge *gitlabExporter) ExportAll(ctx context.Context, repo *cache.RepoCache,
allIdentitiesIds = append(allIdentitiesIds, id)
}
- allBugsIds := repo.AllBugsIds()
+ allBugsIds := repo.Bugs().AllIds()
for _, id := range allBugsIds {
select {
case <-ctx.Done():
return
default:
- b, err := repo.ResolveBug(id)
+ b, err := repo.Bugs().Resolve(id)
if err != nil {
out <- core.NewExportError(err, id)
return
diff --git a/bridge/gitlab/export_test.go b/bridge/gitlab/export_test.go
index 47d5a9b1..7c826822 100644
--- a/bridge/gitlab/export_test.go
+++ b/bridge/gitlab/export_test.go
@@ -37,18 +37,18 @@ type testCase struct {
func testCases(t *testing.T, repo *cache.RepoCache) []*testCase {
// simple bug
- simpleBug, _, err := repo.NewBug("simple bug", "new bug")
+ simpleBug, _, err := repo.Bugs().New("simple bug", "new bug")
require.NoError(t, err)
// bug with comments
- bugWithComments, _, err := repo.NewBug("bug with comments", "new bug")
+ bugWithComments, _, err := repo.Bugs().New("bug with comments", "new bug")
require.NoError(t, err)
_, _, err = bugWithComments.AddComment("new comment")
require.NoError(t, err)
// bug with label changes
- bugLabelChange, _, err := repo.NewBug("bug label change", "new bug")
+ bugLabelChange, _, err := repo.Bugs().New("bug label change", "new bug")
require.NoError(t, err)
_, _, err = bugLabelChange.ChangeLabels([]string{"bug"}, nil)
@@ -61,7 +61,7 @@ func testCases(t *testing.T, repo *cache.RepoCache) []*testCase {
require.NoError(t, err)
// bug with comments editions
- bugWithCommentEditions, createOp, err := repo.NewBug("bug with comments editions", "new bug")
+ bugWithCommentEditions, createOp, err := repo.Bugs().New("bug with comments editions", "new bug")
require.NoError(t, err)
_, err = bugWithCommentEditions.EditComment(
@@ -75,7 +75,7 @@ func testCases(t *testing.T, repo *cache.RepoCache) []*testCase {
require.NoError(t, err)
// bug status changed
- bugStatusChanged, _, err := repo.NewBug("bug status changed", "new bug")
+ bugStatusChanged, _, err := repo.Bugs().New("bug status changed", "new bug")
require.NoError(t, err)
_, err = bugStatusChanged.Close()
@@ -85,7 +85,7 @@ func testCases(t *testing.T, repo *cache.RepoCache) []*testCase {
require.NoError(t, err)
// bug title changed
- bugTitleEdited, _, err := repo.NewBug("bug title edited", "new bug")
+ bugTitleEdited, _, err := repo.Bugs().New("bug title edited", "new bug")
require.NoError(t, err)
_, err = bugTitleEdited.SetTitle("bug title edited again")
@@ -147,12 +147,12 @@ func TestGitlabPushPull(t *testing.T) {
// create repo backend
repo := repository.CreateGoGitTestRepo(t, false)
- backend, err := cache.NewRepoCache(repo)
+ backend, err := cache.NewRepoCacheNoEvents(repo)
require.NoError(t, err)
// set author identity
login := "test-identity"
- author, err := backend.NewIdentity("test identity", "test@test.org")
+ author, err := backend.Identities().New("test identity", "test@test.org")
require.NoError(t, err)
author.SetMetadata(metaKeyGitlabLogin, login)
err = author.Commit()
@@ -220,7 +220,7 @@ func TestGitlabPushPull(t *testing.T) {
repoTwo := repository.CreateGoGitTestRepo(t, false)
// create a second backend
- backendTwo, err := cache.NewRepoCache(repoTwo)
+ backendTwo, err := cache.NewRepoCacheNoEvents(repoTwo)
require.NoError(t, err)
importer := &gitlabImporter{}
@@ -239,7 +239,7 @@ func TestGitlabPushPull(t *testing.T) {
require.NoError(t, result.Err)
}
- require.Len(t, backendTwo.AllBugsIds(), len(tests))
+ require.Len(t, backendTwo.Bugs().AllIds(), len(tests))
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
@@ -264,7 +264,7 @@ func TestGitlabPushPull(t *testing.T) {
require.True(t, ok)
// retrieve bug from backendTwo
- importedBug, err := backendTwo.ResolveBugCreateMetadata(metaKeyGitlabId, bugGitlabID)
+ importedBug, err := backendTwo.Bugs().ResolveBugCreateMetadata(metaKeyGitlabId, bugGitlabID)
require.NoError(t, err)
// verify bug have same number of original operations
diff --git a/bridge/gitlab/import.go b/bridge/gitlab/import.go
index c7909c8f..5947fb60 100644
--- a/bridge/gitlab/import.go
+++ b/bridge/gitlab/import.go
@@ -11,7 +11,6 @@ import (
"github.com/MichaelMure/git-bug/bridge/core"
"github.com/MichaelMure/git-bug/bridge/core/auth"
"github.com/MichaelMure/git-bug/cache"
- "github.com/MichaelMure/git-bug/entities/bug"
"github.com/MichaelMure/git-bug/entity"
"github.com/MichaelMure/git-bug/util/text"
)
@@ -109,7 +108,7 @@ func (gi *gitlabImporter) ensureIssue(repo *cache.RepoCache, issue *gitlab.Issue
}
// resolve bug
- b, err := repo.ResolveBugMatcher(func(excerpt *cache.BugExcerpt) bool {
+ b, err := repo.Bugs().ResolveMatcher(func(excerpt *cache.BugExcerpt) bool {
return excerpt.CreateMetadata[core.MetaKeyOrigin] == target &&
excerpt.CreateMetadata[metaKeyGitlabId] == fmt.Sprintf("%d", issue.IID) &&
excerpt.CreateMetadata[metaKeyGitlabBaseUrl] == gi.conf[confKeyGitlabBaseUrl] &&
@@ -118,12 +117,12 @@ func (gi *gitlabImporter) ensureIssue(repo *cache.RepoCache, issue *gitlab.Issue
if err == nil {
return b, nil
}
- if err != bug.ErrBugNotExist {
+ if !entity.IsErrNotFound(err) {
return nil, err
}
// if bug was never imported, create bug
- b, _, err = repo.NewBugRaw(
+ b, _, err = repo.Bugs().NewRaw(
author,
issue.CreatedAt.Unix(),
text.CleanupOneLine(issue.Title),
@@ -338,7 +337,7 @@ func (gi *gitlabImporter) ensureIssueEvent(repo *cache.RepoCache, b *cache.BugCa
func (gi *gitlabImporter) ensurePerson(repo *cache.RepoCache, id int) (*cache.IdentityCache, error) {
// Look first in the cache
- i, err := repo.ResolveIdentityImmutableMetadata(metaKeyGitlabId, strconv.Itoa(id))
+ i, err := repo.Identities().ResolveIdentityImmutableMetadata(metaKeyGitlabId, strconv.Itoa(id))
if err == nil {
return i, nil
}
@@ -351,7 +350,7 @@ func (gi *gitlabImporter) ensurePerson(repo *cache.RepoCache, id int) (*cache.Id
return nil, err
}
- i, err = repo.NewIdentityRaw(
+ i, err = repo.Identities().NewRaw(
user.Name,
user.PublicEmail,
user.Username,
diff --git a/bridge/gitlab/import_test.go b/bridge/gitlab/import_test.go
index d98da4ef..bed93a80 100644
--- a/bridge/gitlab/import_test.go
+++ b/bridge/gitlab/import_test.go
@@ -33,7 +33,7 @@ func TestGitlabImport(t *testing.T) {
repo := repository.CreateGoGitTestRepo(t, false)
- backend, err := cache.NewRepoCache(repo)
+ backend, err := cache.NewRepoCacheNoEvents(repo)
require.NoError(t, err)
defer backend.Close()
@@ -126,11 +126,11 @@ func TestGitlabImport(t *testing.T) {
fmt.Printf("test repository imported in %f seconds\n", time.Since(start).Seconds())
- require.Len(t, backend.AllBugsIds(), len(tests))
+ require.Len(t, backend.Bugs().AllIds(), len(tests))
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
- b, err := backend.ResolveBugCreateMetadata(metaKeyGitlabUrl, tt.url)
+ b, err := backend.Bugs().ResolveBugCreateMetadata(metaKeyGitlabUrl, tt.url)
require.NoError(t, err)
ops := b.Snapshot().Operations
diff --git a/bridge/jira/export.go b/bridge/jira/export.go
index 8587a55d..95f9e28c 100644
--- a/bridge/jira/export.go
+++ b/bridge/jira/export.go
@@ -14,7 +14,6 @@ import (
"github.com/MichaelMure/git-bug/bridge/core/auth"
"github.com/MichaelMure/git-bug/cache"
"github.com/MichaelMure/git-bug/entities/bug"
- "github.com/MichaelMure/git-bug/entities/identity"
"github.com/MichaelMure/git-bug/entity"
"github.com/MichaelMure/git-bug/entity/dag"
)
@@ -102,8 +101,8 @@ func (je *jiraExporter) cacheAllClient(ctx context.Context, repo *cache.RepoCach
continue
}
- user, err := repo.ResolveIdentityImmutableMetadata(metaKeyJiraLogin, login)
- if err == identity.ErrIdentityNotExist {
+ user, err := repo.Identities().ResolveIdentityImmutableMetadata(metaKeyJiraLogin, login)
+ if entity.IsErrNotFound(err) {
continue
}
if err != nil {
@@ -146,10 +145,10 @@ func (je *jiraExporter) ExportAll(ctx context.Context, repo *cache.RepoCache, si
allIdentitiesIds = append(allIdentitiesIds, id)
}
- allBugsIds := repo.AllBugsIds()
+ allBugsIds := repo.Bugs().AllIds()
for _, id := range allBugsIds {
- b, err := repo.ResolveBug(id)
+ b, err := repo.Bugs().Resolve(id)
if err != nil {
out <- core.NewExportError(errors.Wrap(err, "can't load bug"), id)
return
diff --git a/bridge/jira/import.go b/bridge/jira/import.go
index ff9fbb7a..d8a5f8dd 100644
--- a/bridge/jira/import.go
+++ b/bridge/jira/import.go
@@ -184,7 +184,7 @@ func (ji *jiraImporter) ImportAll(ctx context.Context, repo *cache.RepoCache, si
// Create a bug.Person from a JIRA user
func (ji *jiraImporter) ensurePerson(repo *cache.RepoCache, user User) (*cache.IdentityCache, error) {
// Look first in the cache
- i, err := repo.ResolveIdentityImmutableMetadata(
+ i, err := repo.Identities().ResolveIdentityImmutableMetadata(
metaKeyJiraUser, string(user.Key))
if err == nil {
return i, nil
@@ -193,7 +193,7 @@ func (ji *jiraImporter) ensurePerson(repo *cache.RepoCache, user User) (*cache.I
return nil, err
}
- i, err = repo.NewIdentityRaw(
+ i, err = repo.Identities().NewRaw(
user.DisplayName,
user.EmailAddress,
user.Key,
@@ -219,7 +219,7 @@ func (ji *jiraImporter) ensureIssue(repo *cache.RepoCache, issue Issue) (*cache.
return nil, err
}
- b, err := repo.ResolveBugMatcher(func(excerpt *cache.BugExcerpt) bool {
+ b, err := repo.Bugs().ResolveMatcher(func(excerpt *cache.BugExcerpt) bool {
if _, ok := excerpt.CreateMetadata[metaKeyJiraBaseUrl]; ok &&
excerpt.CreateMetadata[metaKeyJiraBaseUrl] != ji.conf[confKeyBaseUrl] {
return false
@@ -229,12 +229,12 @@ func (ji *jiraImporter) ensureIssue(repo *cache.RepoCache, issue Issue) (*cache.
excerpt.CreateMetadata[metaKeyJiraId] == issue.ID &&
excerpt.CreateMetadata[metaKeyJiraProject] == ji.conf[confKeyProject]
})
- if err != nil && err != bug.ErrBugNotExist {
+ if err != nil && !entity.IsErrNotFound(err) {
return nil, err
}
- if err == bug.ErrBugNotExist {
- b, _, err = repo.NewBugRaw(
+ if entity.IsErrNotFound(err) {
+ b, _, err = repo.Bugs().NewRaw(
author,
issue.Fields.Created.Unix(),
text.CleanupOneLine(issue.Fields.Summary),
diff --git a/bridge/launchpad/import.go b/bridge/launchpad/import.go
index f81e3582..6a20217c 100644
--- a/bridge/launchpad/import.go
+++ b/bridge/launchpad/import.go
@@ -7,7 +7,6 @@ import (
"github.com/MichaelMure/git-bug/bridge/core"
"github.com/MichaelMure/git-bug/cache"
- "github.com/MichaelMure/git-bug/entities/bug"
"github.com/MichaelMure/git-bug/entity"
"github.com/MichaelMure/git-bug/util/text"
)
@@ -23,7 +22,7 @@ func (li *launchpadImporter) Init(_ context.Context, repo *cache.RepoCache, conf
func (li *launchpadImporter) ensurePerson(repo *cache.RepoCache, owner LPPerson) (*cache.IdentityCache, error) {
// Look first in the cache
- i, err := repo.ResolveIdentityImmutableMetadata(metaKeyLaunchpadLogin, owner.Login)
+ i, err := repo.Identities().ResolveIdentityImmutableMetadata(metaKeyLaunchpadLogin, owner.Login)
if err == nil {
return i, nil
}
@@ -31,7 +30,7 @@ func (li *launchpadImporter) ensurePerson(repo *cache.RepoCache, owner LPPerson)
return nil, err
}
- return repo.NewIdentityRaw(
+ return repo.Identities().NewRaw(
owner.Name,
"",
owner.Login,
@@ -64,11 +63,11 @@ func (li *launchpadImporter) ImportAll(ctx context.Context, repo *cache.RepoCach
return
default:
lpBugID := fmt.Sprintf("%d", lpBug.ID)
- b, err := repo.ResolveBugMatcher(func(excerpt *cache.BugExcerpt) bool {
+ b, err := repo.Bugs().ResolveMatcher(func(excerpt *cache.BugExcerpt) bool {
return excerpt.CreateMetadata[core.MetaKeyOrigin] == target &&
excerpt.CreateMetadata[metaKeyLaunchpadID] == lpBugID
})
- if err != nil && err != bug.ErrBugNotExist {
+ if err != nil && !entity.IsErrNotFound(err) {
out <- core.NewImportError(err, entity.Id(lpBugID))
return
}
@@ -79,9 +78,9 @@ func (li *launchpadImporter) ImportAll(ctx context.Context, repo *cache.RepoCach
return
}
- if err == bug.ErrBugNotExist {
+ if entity.IsErrNotFound(err) {
createdAt, _ := time.Parse(time.RFC3339, lpBug.CreatedAt)
- b, _, err = repo.NewBugRaw(
+ b, _, err = repo.Bugs().NewRaw(
owner,
createdAt.Unix(),
text.CleanupOneLine(lpBug.Title),