diff options
Diffstat (limited to 'bug')
-rw-r--r-- | bug/bug.go | 9 | ||||
-rw-r--r-- | bug/identity.go | 27 | ||||
-rw-r--r-- | bug/operation_iterator_test.go | 13 |
3 files changed, 49 insertions, 0 deletions
@@ -6,6 +6,8 @@ import ( "fmt" "strings" + "github.com/MichaelMure/git-bug/identity" + "github.com/MichaelMure/git-bug/repository" "github.com/MichaelMure/git-bug/util/git" "github.com/MichaelMure/git-bug/util/lamport" @@ -217,6 +219,13 @@ func readBug(repo repository.ClockedRepo, ref string) (*Bug, error) { bug.packs = append(bug.packs, *opp) } + // Make sure that the identities are properly loaded + resolver := identity.NewSimpleResolver(repo) + err = bug.EnsureIdentities(resolver) + if err != nil { + return nil, err + } + return &bug, nil } diff --git a/bug/identity.go b/bug/identity.go new file mode 100644 index 00000000..2eb2bcaf --- /dev/null +++ b/bug/identity.go @@ -0,0 +1,27 @@ +package bug + +import ( + "github.com/MichaelMure/git-bug/identity" +) + +// EnsureIdentities walk the graph of operations and make sure that all Identity +// are properly loaded. That is, it replace all the IdentityStub with the full +// Identity, loaded through a Resolver. +func (bug *Bug) EnsureIdentities(resolver identity.Resolver) error { + it := NewOperationIterator(bug) + + for it.Next() { + op := it.Value() + base := op.base() + + if stub, ok := base.Author.(*identity.IdentityStub); ok { + i, err := resolver.ResolveIdentity(stub.Id()) + if err != nil { + return err + } + + base.Author = i + } + } + return nil +} diff --git a/bug/operation_iterator_test.go b/bug/operation_iterator_test.go index e1aa8911..a41120e2 100644 --- a/bug/operation_iterator_test.go +++ b/bug/operation_iterator_test.go @@ -20,6 +20,19 @@ var ( labelChangeOp = NewLabelChangeOperation(rene, unix, []Label{"added"}, []Label{"removed"}) ) +func ExampleOperationIterator() { + b := NewBug() + + // add operations + + it := NewOperationIterator(b) + + for it.Next() { + // do something with each operations + _ = it.Value() + } +} + func TestOpIterator(t *testing.T) { mockRepo := repository.NewMockRepoForTest() |