1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
package cmdjson
import (
"github.com/git-bug/git-bug/cache"
"github.com/git-bug/git-bug/entities/bug"
"github.com/git-bug/git-bug/entities/common"
)
type BugSnapshot struct {
Id string `json:"id"`
HumanId string `json:"human_id"`
CreateTime Time `json:"create_time"`
EditTime Time `json:"edit_time"`
Status string `json:"status"`
Labels []common.Label `json:"labels"`
Title string `json:"title"`
Author Identity `json:"author"`
Actors []Identity `json:"actors"`
Participants []Identity `json:"participants"`
Comments []BugComment `json:"comments"`
}
func NewBugSnapshot(snap *bug.Snapshot) BugSnapshot {
jsonBug := BugSnapshot{
Id: snap.Id().String(),
HumanId: snap.Id().Human(),
CreateTime: NewTime(snap.CreateTime, 0),
EditTime: NewTime(snap.EditTime(), 0),
Status: snap.Status.String(),
Labels: snap.Labels,
Title: snap.Title,
Author: NewIdentity(snap.Author),
}
jsonBug.Actors = make([]Identity, len(snap.Actors))
for i, element := range snap.Actors {
jsonBug.Actors[i] = NewIdentity(element)
}
jsonBug.Participants = make([]Identity, len(snap.Participants))
for i, element := range snap.Participants {
jsonBug.Participants[i] = NewIdentity(element)
}
jsonBug.Comments = make([]BugComment, len(snap.Comments))
for i, comment := range snap.Comments {
jsonBug.Comments[i] = NewBugComment(comment)
}
return jsonBug
}
type BugComment struct {
Id string `json:"id"`
HumanId string `json:"human_id"`
Author Identity `json:"author"`
Message string `json:"message"`
}
func NewBugComment(comment bug.Comment) BugComment {
return BugComment{
Id: comment.CombinedId().String(),
HumanId: comment.CombinedId().Human(),
Author: NewIdentity(comment.Author),
Message: comment.Message,
}
}
type BugExcerpt struct {
Id string `json:"id"`
HumanId string `json:"human_id"`
CreateTime Time `json:"create_time"`
EditTime Time `json:"edit_time"`
Status string `json:"status"`
Labels []common.Label `json:"labels"`
Title string `json:"title"`
Actors []Identity `json:"actors"`
Participants []Identity `json:"participants"`
Author Identity `json:"author"`
Comments int `json:"comments"`
Metadata map[string]string `json:"metadata"`
}
func NewBugExcerpt(backend *cache.RepoCache, excerpt *cache.BugExcerpt) (BugExcerpt, error) {
jsonBug := BugExcerpt{
Id: excerpt.Id().String(),
HumanId: excerpt.Id().Human(),
CreateTime: NewTime(excerpt.CreateTime(), excerpt.CreateLamportTime),
EditTime: NewTime(excerpt.EditTime(), excerpt.EditLamportTime),
Status: excerpt.Status.String(),
Labels: excerpt.Labels,
Title: excerpt.Title,
Comments: excerpt.LenComments,
Metadata: excerpt.CreateMetadata,
}
author, err := backend.Identities().ResolveExcerpt(excerpt.AuthorId)
if err != nil {
return BugExcerpt{}, err
}
jsonBug.Author = NewIdentityFromExcerpt(author)
jsonBug.Actors = make([]Identity, len(excerpt.Actors))
for i, element := range excerpt.Actors {
actor, err := backend.Identities().ResolveExcerpt(element)
if err != nil {
return BugExcerpt{}, err
}
jsonBug.Actors[i] = NewIdentityFromExcerpt(actor)
}
jsonBug.Participants = make([]Identity, len(excerpt.Participants))
for i, element := range excerpt.Participants {
participant, err := backend.Identities().ResolveExcerpt(element)
if err != nil {
return BugExcerpt{}, err
}
jsonBug.Participants[i] = NewIdentityFromExcerpt(participant)
}
return jsonBug, nil
}
|