1package commands
2
3import (
4 "time"
5
6 "github.com/MichaelMure/git-bug/cache"
7 "github.com/MichaelMure/git-bug/entities/identity"
8 "github.com/MichaelMure/git-bug/util/lamport"
9)
10
11type JSONIdentity struct {
12 Id string `json:"id"`
13 HumanId string `json:"human_id"`
14 Name string `json:"name"`
15 Login string `json:"login"`
16}
17
18func NewJSONIdentity(i identity.Interface) JSONIdentity {
19 return JSONIdentity{
20 Id: i.Id().String(),
21 HumanId: i.Id().Human(),
22 Name: i.Name(),
23 Login: i.Login(),
24 }
25}
26
27func NewJSONIdentityFromExcerpt(excerpt *cache.IdentityExcerpt) JSONIdentity {
28 return JSONIdentity{
29 Id: excerpt.Id.String(),
30 HumanId: excerpt.Id.Human(),
31 Name: excerpt.Name,
32 Login: excerpt.Login,
33 }
34}
35
36func NewJSONIdentityFromLegacyExcerpt(excerpt *cache.LegacyAuthorExcerpt) JSONIdentity {
37 return JSONIdentity{
38 Name: excerpt.Name,
39 Login: excerpt.Login,
40 }
41}
42
43type JSONTime struct {
44 Timestamp int64 `json:"timestamp"`
45 Time time.Time `json:"time"`
46 Lamport lamport.Time `json:"lamport,omitempty"`
47}
48
49func NewJSONTime(t time.Time, l lamport.Time) JSONTime {
50 return JSONTime{
51 Timestamp: t.Unix(),
52 Time: t,
53 Lamport: l,
54 }
55}