aboutsummaryrefslogtreecommitdiffstats
path: root/cache/bug_excerpt.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-02-18 23:16:47 +0100
committerMichael Muré <batolettre@gmail.com>2019-03-01 22:40:26 +0100
commit54f9838f0ab22ce5285f21cdd117ad81c737d822 (patch)
treef6439599dec013d8f30620b5a534a1ebdb8f7388 /cache/bug_excerpt.go
parent947ea63522610bd16c32cf70812c129eda9bbb02 (diff)
downloadgit-bug-54f9838f0ab22ce5285f21cdd117ad81c737d822.tar.gz
identity: working identity cache
Diffstat (limited to 'cache/bug_excerpt.go')
-rw-r--r--cache/bug_excerpt.go35
1 files changed, 30 insertions, 5 deletions
diff --git a/cache/bug_excerpt.go b/cache/bug_excerpt.go
index d3645322..e39c8310 100644
--- a/cache/bug_excerpt.go
+++ b/cache/bug_excerpt.go
@@ -4,6 +4,7 @@ import (
"encoding/gob"
"github.com/MichaelMure/git-bug/bug"
+ "github.com/MichaelMure/git-bug/identity"
"github.com/MichaelMure/git-bug/util/lamport"
)
@@ -17,25 +18,49 @@ type BugExcerpt struct {
CreateUnixTime int64
EditUnixTime int64
- Status bug.Status
- AuthorId string
- Labels []bug.Label
+ Status bug.Status
+ 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,
- AuthorId: snap.Author.Id(),
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