diff options
Diffstat (limited to 'cache/bug_excerpt.go')
-rw-r--r-- | cache/bug_excerpt.go | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/cache/bug_excerpt.go b/cache/bug_excerpt.go index 7a11fa82..fd06e51b 100644 --- a/cache/bug_excerpt.go +++ b/cache/bug_excerpt.go @@ -4,9 +4,15 @@ import ( "encoding/gob" "github.com/MichaelMure/git-bug/bug" + "github.com/MichaelMure/git-bug/identity" "github.com/MichaelMure/git-bug/util/lamport" ) +// Package initialisation used to register the type for (de)serialization +func init() { + gob.Register(BugExcerpt{}) +} + // BugExcerpt hold a subset of the bug values to be able to sort and filter bugs // efficiently without having to read and compile each raw bugs. type BugExcerpt struct { @@ -18,29 +24,52 @@ type BugExcerpt struct { EditUnixTime int64 Status bug.Status - Author bug.Person Labels []bug.Label + // If author is identity.Bare, LegacyAuthor is set + // If author is identity.Identity, AuthorId is set and data is deported + // in a IdentityExcerpt + LegacyAuthor LegacyAuthorExcerpt + AuthorId string + CreateMetadata map[string]string } +// identity.Bare data are directly embedded in the bug excerpt +type LegacyAuthorExcerpt struct { + Name string + Login string +} + func NewBugExcerpt(b bug.Interface, snap *bug.Snapshot) *BugExcerpt { - return &BugExcerpt{ + e := &BugExcerpt{ Id: b.Id(), CreateLamportTime: b.CreateLamportTime(), EditLamportTime: b.EditLamportTime(), CreateUnixTime: b.FirstOp().GetUnixTime(), EditUnixTime: snap.LastEditUnix(), Status: snap.Status, - Author: snap.Author, Labels: snap.Labels, CreateMetadata: b.FirstOp().AllMetadata(), } + + switch snap.Author.(type) { + case *identity.Identity: + e.AuthorId = snap.Author.Id() + case *identity.Bare: + e.LegacyAuthor = LegacyAuthorExcerpt{ + Login: snap.Author.Login(), + Name: snap.Author.Name(), + } + default: + panic("unhandled identity type") + } + + return e } -// Package initialisation used to register the type for (de)serialization -func init() { - gob.Register(BugExcerpt{}) +func (b *BugExcerpt) HumanId() string { + return bug.FormatHumanID(b.Id) } /* |