From 612a29b031c0f2914d8b283b99bf187f20182fa9 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Wed, 7 Aug 2019 19:14:12 +0200 Subject: fix everything following the hash-->id change --- bridge/github/export.go | 59 ++++++++++++-------------------------------- bridge/github/export_test.go | 10 ++------ bridge/github/import.go | 35 +++++++++----------------- bridge/gitlab/import.go | 23 +++++++++-------- 4 files changed, 40 insertions(+), 87 deletions(-) (limited to 'bridge') diff --git a/bridge/github/export.go b/bridge/github/export.go index b4351bdb..21f75cb4 100644 --- a/bridge/github/export.go +++ b/bridge/github/export.go @@ -17,7 +17,6 @@ import ( "github.com/MichaelMure/git-bug/bridge/core" "github.com/MichaelMure/git-bug/bug" "github.com/MichaelMure/git-bug/cache" - "github.com/MichaelMure/git-bug/util/git" ) var ( @@ -144,7 +143,6 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time, out chan var bugGithubID string var bugGithubURL string - var bugCreationHash string // Special case: // if a user try to export a bug that is not already exported to Github (or imported @@ -209,15 +207,8 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time, out chan out <- core.NewExportBug(b.Id()) - hash, err := createOp.Hash() - if err != nil { - err := errors.Wrap(err, "comment hash") - out <- core.NewExportError(err, b.Id()) - return - } - // mark bug creation operation as exported - if err := markOperationAsExported(b, hash, id, url); err != nil { + if err := markOperationAsExported(b, createOp.ID(), id, url); err != nil { err := errors.Wrap(err, "marking operation as exported") out <- core.NewExportError(err, b.Id()) return @@ -235,17 +226,8 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time, out chan bugGithubURL = url } - // get createOp hash - hash, err := createOp.Hash() - if err != nil { - out <- core.NewExportError(err, b.Id()) - return - } - - bugCreationHash = hash.String() - // cache operation github id - ge.cachedOperationIDs[bugCreationHash] = bugGithubID + ge.cachedOperationIDs[createOp.ID()] = bugGithubID for _, op := range snapshot.Operations[1:] { // ignore SetMetadata operations @@ -253,26 +235,18 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time, out chan continue } - // get operation hash - hash, err := op.Hash() - if err != nil { - err := errors.Wrap(err, "operation hash") - out <- core.NewExportError(err, b.Id()) - return - } - // ignore operations already existing in github (due to import or export) // cache the ID of already exported or imported issues and events from Github if id, ok := op.GetMetadata(keyGithubId); ok { - ge.cachedOperationIDs[hash.String()] = id - out <- core.NewExportNothing(hash.String(), "already exported operation") + ge.cachedOperationIDs[op.ID()] = id + out <- core.NewExportNothing(op.ID(), "already exported operation") continue } opAuthor := op.GetAuthor() client, err := ge.getIdentityClient(opAuthor.Id()) if err != nil { - out <- core.NewExportNothing(hash.String(), "missing operation author token") + out <- core.NewExportNothing(op.ID(), "missing operation author token") continue } @@ -289,18 +263,17 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time, out chan return } - out <- core.NewExportComment(hash.String()) + out <- core.NewExportComment(op.ID()) // cache comment id - ge.cachedOperationIDs[hash.String()] = id + ge.cachedOperationIDs[op.ID()] = id case *bug.EditCommentOperation: opr := op.(*bug.EditCommentOperation) - targetHash := opr.Target.String() // Since github doesn't consider the issue body as a comment - if targetHash == bugCreationHash { + if opr.Target == createOp.ID() { // case bug creation operation: we need to edit the Github issue if err := updateGithubIssueBody(client, bugGithubID, opr.Message); err != nil { @@ -309,7 +282,7 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time, out chan return } - out <- core.NewExportCommentEdition(hash.String()) + out <- core.NewExportCommentEdition(op.ID()) id = bugGithubID url = bugGithubURL @@ -317,7 +290,7 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time, out chan } else { // case comment edition operation: we need to edit the Github comment - commentID, ok := ge.cachedOperationIDs[targetHash] + commentID, ok := ge.cachedOperationIDs[opr.ID()] if !ok { panic("unexpected error: comment id not found") } @@ -329,7 +302,7 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time, out chan return } - out <- core.NewExportCommentEdition(hash.String()) + out <- core.NewExportCommentEdition(op.ID()) // use comment id/url instead of issue id/url id = eid @@ -344,7 +317,7 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time, out chan return } - out <- core.NewExportStatusChange(hash.String()) + out <- core.NewExportStatusChange(op.ID()) id = bugGithubID url = bugGithubURL @@ -357,7 +330,7 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time, out chan return } - out <- core.NewExportTitleEdition(hash.String()) + out <- core.NewExportTitleEdition(op.ID()) id = bugGithubID url = bugGithubURL @@ -370,7 +343,7 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time, out chan return } - out <- core.NewExportLabelChange(hash.String()) + out <- core.NewExportLabelChange(op.ID()) id = bugGithubID url = bugGithubURL @@ -380,7 +353,7 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time, out chan } // mark operation as exported - if err := markOperationAsExported(b, hash, id, url); err != nil { + if err := markOperationAsExported(b, op.ID(), id, url); err != nil { err := errors.Wrap(err, "marking operation as exported") out <- core.NewExportError(err, b.Id()) return @@ -438,7 +411,7 @@ func getRepositoryNodeID(owner, project, token string) (string, error) { return aux.NodeID, nil } -func markOperationAsExported(b *cache.BugCache, target git.Hash, githubID, githubURL string) error { +func markOperationAsExported(b *cache.BugCache, target string, githubID, githubURL string) error { _, err := b.SetMetadata( target, map[string]string{ diff --git a/bridge/github/export_test.go b/bridge/github/export_test.go index 80660e77..ac18fea5 100644 --- a/bridge/github/export_test.go +++ b/bridge/github/export_test.go @@ -58,19 +58,13 @@ func testCases(t *testing.T, repo *cache.RepoCache, identity *cache.IdentityCach bugWithCommentEditions, createOp, err := repo.NewBug("bug with comments editions", "new bug") require.NoError(t, err) - createOpHash, err := createOp.Hash() - require.NoError(t, err) - - _, err = bugWithCommentEditions.EditComment(createOpHash, "first comment edited") + _, err = bugWithCommentEditions.EditComment(createOp.ID(), "first comment edited") require.NoError(t, err) commentOp, err := bugWithCommentEditions.AddComment("first comment") require.NoError(t, err) - commentOpHash, err := commentOp.Hash() - require.NoError(t, err) - - _, err = bugWithCommentEditions.EditComment(commentOpHash, "first comment edited") + _, err = bugWithCommentEditions.EditComment(commentOp.ID(), "first comment edited") require.NoError(t, err) // bug status changed diff --git a/bridge/github/import.go b/bridge/github/import.go index c162d70e..56b50c81 100644 --- a/bridge/github/import.go +++ b/bridge/github/import.go @@ -11,7 +11,6 @@ import ( "github.com/MichaelMure/git-bug/bug" "github.com/MichaelMure/git-bug/cache" "github.com/MichaelMure/git-bug/identity" - "github.com/MichaelMure/git-bug/util/git" "github.com/MichaelMure/git-bug/util/text" ) @@ -93,7 +92,7 @@ func (gi *githubImporter) ensureIssue(repo *cache.RepoCache, issue issueTimeline } // get issue edits - issueEdits := []userContentEdit{} + var issueEdits []userContentEdit for gi.iterator.NextIssueEdit() { issueEdits = append(issueEdits, gi.iterator.IssueEditValue()) } @@ -307,15 +306,14 @@ func (gi *githubImporter) ensureTimelineComment(repo *cache.RepoCache, b *cache. return err } - var target git.Hash - target, err = b.ResolveOperationWithMetadata(keyGithubId, parseId(item.Id)) + targetOpID, err := b.ResolveOperationWithMetadata(keyGithubId, parseId(item.Id)) if err != nil && err != cache.ErrNoMatchingOp { // real error return err } + // if no edits are given we create the comment if len(edits) == 0 { - // if comment doesn't exist if err == cache.ErrNoMatchingOp { cleanText, err := text.Cleanup(string(item.Body)) @@ -324,7 +322,7 @@ func (gi *githubImporter) ensureTimelineComment(repo *cache.RepoCache, b *cache. } // add comment operation - op, err := b.AddCommentRaw( + _, err = b.AddCommentRaw( author, item.CreatedAt.Unix(), cleanText, @@ -334,19 +332,11 @@ func (gi *githubImporter) ensureTimelineComment(repo *cache.RepoCache, b *cache. keyGithubUrl: parseId(item.Url.String()), }, ) - if err != nil { - return err - } - - // set hash - target, err = op.Hash() - if err != nil { - return err - } + return err } } else { for i, edit := range edits { - if i == 0 && target != "" { + if i == 0 && targetOpID != "" { // The first edit in the github result is the comment creation itself, we already have that continue } @@ -358,7 +348,7 @@ func (gi *githubImporter) ensureTimelineComment(repo *cache.RepoCache, b *cache. } // create comment when target is empty - if target == "" { + if targetOpID == "" { cleanText, err := text.Cleanup(string(*edit.Diff)) if err != nil { return err @@ -378,16 +368,13 @@ func (gi *githubImporter) ensureTimelineComment(repo *cache.RepoCache, b *cache. return err } - // set hash - target, err = op.Hash() - if err != nil { - return err - } + // set target for the nexr edit now that the comment is created + targetOpID = op.ID() continue } - err = gi.ensureCommentEdit(repo, b, target, edit) + err = gi.ensureCommentEdit(repo, b, targetOpID, edit) if err != nil { return err } @@ -396,7 +383,7 @@ func (gi *githubImporter) ensureTimelineComment(repo *cache.RepoCache, b *cache. return nil } -func (gi *githubImporter) ensureCommentEdit(repo *cache.RepoCache, b *cache.BugCache, target git.Hash, edit userContentEdit) error { +func (gi *githubImporter) ensureCommentEdit(repo *cache.RepoCache, b *cache.BugCache, target string, edit userContentEdit) error { _, err := b.ResolveOperationWithMetadata(keyGithubId, parseId(edit.Id)) if err == nil { // already imported diff --git a/bridge/gitlab/import.go b/bridge/gitlab/import.go index dbedfda8..8b389357 100644 --- a/bridge/gitlab/import.go +++ b/bridge/gitlab/import.go @@ -11,7 +11,6 @@ import ( "github.com/MichaelMure/git-bug/bug" "github.com/MichaelMure/git-bug/cache" "github.com/MichaelMure/git-bug/identity" - "github.com/MichaelMure/git-bug/util/git" "github.com/MichaelMure/git-bug/util/text" ) @@ -130,10 +129,10 @@ func (gi *gitlabImporter) ensureIssue(repo *cache.RepoCache, issue *gitlab.Issue } func (gi *gitlabImporter) ensureNote(repo *cache.RepoCache, b *cache.BugCache, note *gitlab.Note) error { - id := parseID(note.ID) + gitlabID := parseID(note.ID) - hash, errResolve := b.ResolveOperationWithMetadata(keyGitlabId, id) - if errResolve != nil && errResolve != cache.ErrNoMatchingOp { + id, errResolve := b.ResolveOperationWithMetadata(keyGitlabId, gitlabID) + if errResolve != cache.ErrNoMatchingOp { return errResolve } @@ -154,7 +153,7 @@ func (gi *gitlabImporter) ensureNote(repo *cache.RepoCache, b *cache.BugCache, n author, note.CreatedAt.Unix(), map[string]string{ - keyGitlabId: id, + keyGitlabId: gitlabID, }, ) return err @@ -168,7 +167,7 @@ func (gi *gitlabImporter) ensureNote(repo *cache.RepoCache, b *cache.BugCache, n author, note.CreatedAt.Unix(), map[string]string{ - keyGitlabId: id, + keyGitlabId: gitlabID, }, ) return err @@ -185,10 +184,10 @@ func (gi *gitlabImporter) ensureNote(repo *cache.RepoCache, b *cache.BugCache, n _, err = b.EditCommentRaw( author, note.UpdatedAt.Unix(), - git.Hash(firstComment.Id()), + firstComment.Id(), issue.Description, map[string]string{ - keyGitlabId: id, + keyGitlabId: gitlabID, }, ) @@ -211,7 +210,7 @@ func (gi *gitlabImporter) ensureNote(repo *cache.RepoCache, b *cache.BugCache, n cleanText, nil, map[string]string{ - keyGitlabId: id, + keyGitlabId: gitlabID, }, ) @@ -221,7 +220,7 @@ func (gi *gitlabImporter) ensureNote(repo *cache.RepoCache, b *cache.BugCache, n // if comment was already exported // search for last comment update - comment, err := b.Snapshot().SearchComment(hash) + comment, err := b.Snapshot().SearchComment(id) if err != nil { return err } @@ -232,7 +231,7 @@ func (gi *gitlabImporter) ensureNote(repo *cache.RepoCache, b *cache.BugCache, n _, err = b.EditCommentRaw( author, note.UpdatedAt.Unix(), - git.Hash(comment.Id()), + comment.Id(), cleanText, nil, ) @@ -253,7 +252,7 @@ func (gi *gitlabImporter) ensureNote(repo *cache.RepoCache, b *cache.BugCache, n note.CreatedAt.Unix(), body, map[string]string{ - keyGitlabId: id, + keyGitlabId: gitlabID, }, ) -- cgit From a0dfc202117e31e01d2d6ec701a41292df35d35d Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Thu, 8 Aug 2019 18:59:37 +0200 Subject: github: fix bad refactor --- bridge/github/export.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bridge') diff --git a/bridge/github/export.go b/bridge/github/export.go index 21f75cb4..0d2b1e61 100644 --- a/bridge/github/export.go +++ b/bridge/github/export.go @@ -290,7 +290,7 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time, out chan } else { // case comment edition operation: we need to edit the Github comment - commentID, ok := ge.cachedOperationIDs[opr.ID()] + commentID, ok := ge.cachedOperationIDs[opr.Target] if !ok { panic("unexpected error: comment id not found") } -- cgit From 99b5c58d43137bd9f6503788a55484327b0c531f Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Mon, 12 Aug 2019 16:12:14 +0200 Subject: finish the refactoring for the dedicated identifier type --- bridge/core/export.go | 28 +++++++++++++----------- bridge/github/export.go | 51 ++++++++++++++++++++++---------------------- bridge/github/export_test.go | 4 ++-- bridge/github/import.go | 10 ++++----- bridge/gitlab/import.go | 4 ++-- bridge/launchpad/import.go | 7 +++--- 6 files changed, 55 insertions(+), 49 deletions(-) (limited to 'bridge') diff --git a/bridge/core/export.go b/bridge/core/export.go index 2bcf0087..09566b62 100644 --- a/bridge/core/export.go +++ b/bridge/core/export.go @@ -1,6 +1,10 @@ package core -import "fmt" +import ( + "fmt" + + "github.com/MichaelMure/git-bug/entity" +) type ExportEvent int @@ -21,7 +25,7 @@ const ( type ExportResult struct { Err error Event ExportEvent - ID string + ID entity.Id Reason string } @@ -46,14 +50,14 @@ func (er ExportResult) String() string { } } -func NewExportError(err error, reason string) ExportResult { +func NewExportError(err error, id entity.Id) ExportResult { return ExportResult{ - Err: err, - Reason: reason, + ID: id, + Err: err, } } -func NewExportNothing(id string, reason string) ExportResult { +func NewExportNothing(id entity.Id, reason string) ExportResult { return ExportResult{ ID: id, Reason: reason, @@ -61,42 +65,42 @@ func NewExportNothing(id string, reason string) ExportResult { } } -func NewExportBug(id string) ExportResult { +func NewExportBug(id entity.Id) ExportResult { return ExportResult{ ID: id, Event: ExportEventBug, } } -func NewExportComment(id string) ExportResult { +func NewExportComment(id entity.Id) ExportResult { return ExportResult{ ID: id, Event: ExportEventComment, } } -func NewExportCommentEdition(id string) ExportResult { +func NewExportCommentEdition(id entity.Id) ExportResult { return ExportResult{ ID: id, Event: ExportEventCommentEdition, } } -func NewExportStatusChange(id string) ExportResult { +func NewExportStatusChange(id entity.Id) ExportResult { return ExportResult{ ID: id, Event: ExportEventStatusChange, } } -func NewExportLabelChange(id string) ExportResult { +func NewExportLabelChange(id entity.Id) ExportResult { return ExportResult{ ID: id, Event: ExportEventLabelChange, } } -func NewExportTitleEdition(id string) ExportResult { +func NewExportTitleEdition(id entity.Id) ExportResult { return ExportResult{ ID: id, Event: ExportEventTitleEdition, diff --git a/bridge/github/export.go b/bridge/github/export.go index 0d2b1e61..34c88310 100644 --- a/bridge/github/export.go +++ b/bridge/github/export.go @@ -17,6 +17,7 @@ import ( "github.com/MichaelMure/git-bug/bridge/core" "github.com/MichaelMure/git-bug/bug" "github.com/MichaelMure/git-bug/cache" + "github.com/MichaelMure/git-bug/entity" ) var ( @@ -28,17 +29,17 @@ type githubExporter struct { conf core.Configuration // cache identities clients - identityClient map[string]*githubv4.Client + identityClient map[entity.Id]*githubv4.Client // map identities with their tokens - identityToken map[string]string + identityToken map[entity.Id]string // github repository ID repositoryID string // cache identifiers used to speed up exporting operations // cleared for each bug - cachedOperationIDs map[string]string + cachedOperationIDs map[entity.Id]string // cache labels used to speed up exporting labels events cachedLabels map[string]string @@ -48,16 +49,16 @@ type githubExporter struct { func (ge *githubExporter) Init(conf core.Configuration) error { ge.conf = conf //TODO: initialize with multiple tokens - ge.identityToken = make(map[string]string) - ge.identityClient = make(map[string]*githubv4.Client) - ge.cachedOperationIDs = make(map[string]string) + ge.identityToken = make(map[entity.Id]string) + ge.identityClient = make(map[entity.Id]*githubv4.Client) + ge.cachedOperationIDs = make(map[entity.Id]string) ge.cachedLabels = make(map[string]string) return nil } // getIdentityClient return a githubv4 API client configured with the access token of the given identity. // if no client were found it will initialize it from the known tokens map and cache it for next use -func (ge *githubExporter) getIdentityClient(id string) (*githubv4.Client, error) { +func (ge *githubExporter) getIdentityClient(id entity.Id) (*githubv4.Client, error) { client, ok := ge.identityClient[id] if ok { return client, nil @@ -102,7 +103,7 @@ func (ge *githubExporter) ExportAll(repo *cache.RepoCache, since time.Time) (<-c go func() { defer close(out) - var allIdentitiesIds []string + var allIdentitiesIds []entity.Id for id := range ge.identityToken { allIdentitiesIds = append(allIdentitiesIds, id) } @@ -112,7 +113,7 @@ func (ge *githubExporter) ExportAll(repo *cache.RepoCache, since time.Time) (<-c for _, id := range allBugsIds { b, err := repo.ResolveBug(id) if err != nil { - out <- core.NewExportError(err, id) + out <- core.NewExportError(errors.Wrap(err, "can't load bug"), id) return } @@ -165,7 +166,7 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time, out chan githubURL, ok := snapshot.GetCreateMetadata(keyGithubUrl) if !ok { // if we find github ID, github URL must be found too - err := fmt.Errorf("expected to find github issue URL") + err := fmt.Errorf("incomplete Github metadata: expected to find issue URL") out <- core.NewExportError(err, b.Id()) } @@ -208,7 +209,7 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time, out chan out <- core.NewExportBug(b.Id()) // mark bug creation operation as exported - if err := markOperationAsExported(b, createOp.ID(), id, url); err != nil { + if err := markOperationAsExported(b, createOp.Id(), id, url); err != nil { err := errors.Wrap(err, "marking operation as exported") out <- core.NewExportError(err, b.Id()) return @@ -227,7 +228,7 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time, out chan } // cache operation github id - ge.cachedOperationIDs[createOp.ID()] = bugGithubID + ge.cachedOperationIDs[createOp.Id()] = bugGithubID for _, op := range snapshot.Operations[1:] { // ignore SetMetadata operations @@ -238,15 +239,15 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time, out chan // ignore operations already existing in github (due to import or export) // cache the ID of already exported or imported issues and events from Github if id, ok := op.GetMetadata(keyGithubId); ok { - ge.cachedOperationIDs[op.ID()] = id - out <- core.NewExportNothing(op.ID(), "already exported operation") + ge.cachedOperationIDs[op.Id()] = id + out <- core.NewExportNothing(op.Id(), "already exported operation") continue } opAuthor := op.GetAuthor() client, err := ge.getIdentityClient(opAuthor.Id()) if err != nil { - out <- core.NewExportNothing(op.ID(), "missing operation author token") + out <- core.NewExportNothing(op.Id(), "missing operation author token") continue } @@ -263,17 +264,17 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time, out chan return } - out <- core.NewExportComment(op.ID()) + out <- core.NewExportComment(op.Id()) // cache comment id - ge.cachedOperationIDs[op.ID()] = id + ge.cachedOperationIDs[op.Id()] = id case *bug.EditCommentOperation: opr := op.(*bug.EditCommentOperation) // Since github doesn't consider the issue body as a comment - if opr.Target == createOp.ID() { + if opr.Target == createOp.Id() { // case bug creation operation: we need to edit the Github issue if err := updateGithubIssueBody(client, bugGithubID, opr.Message); err != nil { @@ -282,7 +283,7 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time, out chan return } - out <- core.NewExportCommentEdition(op.ID()) + out <- core.NewExportCommentEdition(op.Id()) id = bugGithubID url = bugGithubURL @@ -302,7 +303,7 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time, out chan return } - out <- core.NewExportCommentEdition(op.ID()) + out <- core.NewExportCommentEdition(op.Id()) // use comment id/url instead of issue id/url id = eid @@ -317,7 +318,7 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time, out chan return } - out <- core.NewExportStatusChange(op.ID()) + out <- core.NewExportStatusChange(op.Id()) id = bugGithubID url = bugGithubURL @@ -330,7 +331,7 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time, out chan return } - out <- core.NewExportTitleEdition(op.ID()) + out <- core.NewExportTitleEdition(op.Id()) id = bugGithubID url = bugGithubURL @@ -343,7 +344,7 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time, out chan return } - out <- core.NewExportLabelChange(op.ID()) + out <- core.NewExportLabelChange(op.Id()) id = bugGithubID url = bugGithubURL @@ -353,7 +354,7 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time, out chan } // mark operation as exported - if err := markOperationAsExported(b, op.ID(), id, url); err != nil { + if err := markOperationAsExported(b, op.Id(), id, url); err != nil { err := errors.Wrap(err, "marking operation as exported") out <- core.NewExportError(err, b.Id()) return @@ -411,7 +412,7 @@ func getRepositoryNodeID(owner, project, token string) (string, error) { return aux.NodeID, nil } -func markOperationAsExported(b *cache.BugCache, target string, githubID, githubURL string) error { +func markOperationAsExported(b *cache.BugCache, target entity.Id, githubID, githubURL string) error { _, err := b.SetMetadata( target, map[string]string{ diff --git a/bridge/github/export_test.go b/bridge/github/export_test.go index ac18fea5..107fe63b 100644 --- a/bridge/github/export_test.go +++ b/bridge/github/export_test.go @@ -58,13 +58,13 @@ func testCases(t *testing.T, repo *cache.RepoCache, identity *cache.IdentityCach bugWithCommentEditions, createOp, err := repo.NewBug("bug with comments editions", "new bug") require.NoError(t, err) - _, err = bugWithCommentEditions.EditComment(createOp.ID(), "first comment edited") + _, err = bugWithCommentEditions.EditComment(createOp.Id(), "first comment edited") require.NoError(t, err) commentOp, err := bugWithCommentEditions.AddComment("first comment") require.NoError(t, err) - _, err = bugWithCommentEditions.EditComment(commentOp.ID(), "first comment edited") + _, err = bugWithCommentEditions.EditComment(commentOp.Id(), "first comment edited") require.NoError(t, err) // bug status changed diff --git a/bridge/github/import.go b/bridge/github/import.go index 56b50c81..dcaf2d05 100644 --- a/bridge/github/import.go +++ b/bridge/github/import.go @@ -10,7 +10,7 @@ import ( "github.com/MichaelMure/git-bug/bridge/core" "github.com/MichaelMure/git-bug/bug" "github.com/MichaelMure/git-bug/cache" - "github.com/MichaelMure/git-bug/identity" + "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/util/text" ) @@ -369,7 +369,7 @@ func (gi *githubImporter) ensureTimelineComment(repo *cache.RepoCache, b *cache. } // set target for the nexr edit now that the comment is created - targetOpID = op.ID() + targetOpID = op.Id() continue } @@ -383,7 +383,7 @@ func (gi *githubImporter) ensureTimelineComment(repo *cache.RepoCache, b *cache. return nil } -func (gi *githubImporter) ensureCommentEdit(repo *cache.RepoCache, b *cache.BugCache, target string, edit userContentEdit) error { +func (gi *githubImporter) ensureCommentEdit(repo *cache.RepoCache, b *cache.BugCache, target entity.Id, edit userContentEdit) error { _, err := b.ResolveOperationWithMetadata(keyGithubId, parseId(edit.Id)) if err == nil { // already imported @@ -445,7 +445,7 @@ func (gi *githubImporter) ensurePerson(repo *cache.RepoCache, actor *actor) (*ca if err == nil { return i, nil } - if _, ok := err.(identity.ErrMultipleMatch); ok { + if _, ok := err.(entity.ErrMultipleMatch); ok { return nil, err } @@ -488,7 +488,7 @@ func (gi *githubImporter) getGhost(repo *cache.RepoCache) (*cache.IdentityCache, if err == nil { return i, nil } - if _, ok := err.(identity.ErrMultipleMatch); ok { + if _, ok := err.(entity.ErrMultipleMatch); ok { return nil, err } diff --git a/bridge/gitlab/import.go b/bridge/gitlab/import.go index 8b389357..08e4c6eb 100644 --- a/bridge/gitlab/import.go +++ b/bridge/gitlab/import.go @@ -10,7 +10,7 @@ import ( "github.com/MichaelMure/git-bug/bridge/core" "github.com/MichaelMure/git-bug/bug" "github.com/MichaelMure/git-bug/cache" - "github.com/MichaelMure/git-bug/identity" + "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/util/text" ) @@ -324,7 +324,7 @@ func (gi *gitlabImporter) ensurePerson(repo *cache.RepoCache, id int) (*cache.Id if err == nil { return i, nil } - if _, ok := err.(identity.ErrMultipleMatch); ok { + if _, ok := err.(entity.ErrMultipleMatch); ok { return nil, err } diff --git a/bridge/launchpad/import.go b/bridge/launchpad/import.go index 63101d9c..7ef11416 100644 --- a/bridge/launchpad/import.go +++ b/bridge/launchpad/import.go @@ -4,11 +4,12 @@ import ( "fmt" "time" + "github.com/pkg/errors" + "github.com/MichaelMure/git-bug/bridge/core" "github.com/MichaelMure/git-bug/bug" "github.com/MichaelMure/git-bug/cache" - "github.com/MichaelMure/git-bug/identity" - "github.com/pkg/errors" + "github.com/MichaelMure/git-bug/entity" ) type launchpadImporter struct { @@ -29,7 +30,7 @@ func (li *launchpadImporter) ensurePerson(repo *cache.RepoCache, owner LPPerson) if err == nil { return i, nil } - if _, ok := err.(identity.ErrMultipleMatch); ok { + if _, ok := err.(entity.ErrMultipleMatch); ok { return nil, err } -- cgit From c809d37152ea87a66fc281730042dcb4299a8263 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Tue, 13 Aug 2019 16:02:13 +0200 Subject: more hash-->id fixes --- bridge/gitlab/import.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bridge') diff --git a/bridge/gitlab/import.go b/bridge/gitlab/import.go index 08e4c6eb..f65aba6a 100644 --- a/bridge/gitlab/import.go +++ b/bridge/gitlab/import.go @@ -132,7 +132,7 @@ func (gi *gitlabImporter) ensureNote(repo *cache.RepoCache, b *cache.BugCache, n gitlabID := parseID(note.ID) id, errResolve := b.ResolveOperationWithMetadata(keyGitlabId, gitlabID) - if errResolve != cache.ErrNoMatchingOp { + if errResolve != nil && errResolve != cache.ErrNoMatchingOp { return errResolve } -- cgit