-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathticketcomments.go
63 lines (53 loc) · 1.34 KB
/
ticketcomments.go
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
package tracker
type TicketComments []TicketComment
type TicketComment map[string]interface{}
// GetLast
// Return last comment
func (t TicketComments) GetLast() TicketComment {
countComments := len(t)
if countComments == 0 {
return TicketComment{}
}
return t[len(t)-1]
}
// CreatedBy
// Get comment author
func (t TicketComment) CreatedBy() BasicUser {
if createdBy, ok := t["createdBy"].(map[string]interface{}); ok {
return BasicUser{
Self: toString(createdBy["self"]),
ID: toString(createdBy["id"]),
Display: toString(createdBy["display"]),
}
}
return BasicUser{}
}
// Text
// Get comment text
func (t TicketComment) Text() string {
return t.GetField("text")
}
// Summonees
// Get comment author
func (t TicketComment) Summonees() BasicUsers {
if summonees, ok := t["summonees"].([]interface{}); ok {
users := make(BasicUsers, len(summonees))
for i := range summonees {
users[i] = BasicUser{
Self: toString(summonees[i].(map[string]interface{})["self"]),
ID: toString(summonees[i].(map[string]interface{})["id"]),
Display: toString(summonees[i].(map[string]interface{})["display"]),
}
}
return users
}
return BasicUsers{}
}
// GetField
// Get any custom ticket field
func (t TicketComment) GetField(field string) string {
if key, ok := t[field]; ok {
return toString(key)
}
return ""
}