-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathticket.go
102 lines (88 loc) · 2.07 KB
/
ticket.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
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
package tracker
type Ticket map[string]interface{}
// CreatedBy
// Get ticket author
func (t Ticket) 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{}
}
// Assignee
// Get ticket assignee
func (t Ticket) Assignee() BasicUser {
if assignee, ok := t["assignee"].(map[string]interface{}); ok {
return BasicUser{
Self: toString(assignee["self"]),
ID: toString(assignee["id"]),
Display: toString(assignee["display"]),
}
}
return BasicUser{}
}
// Followers
// Get ticket followers
func (t Ticket) Followers() BasicUsers {
if followers, ok := t["followers"].([]interface{}); ok {
users := make(BasicUsers, len(followers))
for i := range followers {
users[i] = BasicUser{
Self: toString(followers[i].(map[string]interface{})["self"]),
ID: toString(followers[i].(map[string]interface{})["id"]),
Display: toString(followers[i].(map[string]interface{})["display"]),
}
}
return users
}
return BasicUsers{}
}
// Summary
// Get ticket summary
func (t Ticket) Summary() string {
return t.GetField("summary")
}
// Key
// Get ticket key
func (t Ticket) Key() string {
return t.GetField("key")
}
// Description
// Get ticket description
func (t Ticket) Description() string {
return t.GetField("description")
}
// Status
// Get ticket status
func (t Ticket) Status() string {
if status, ok := t["status"].(map[string]interface{}); ok {
if display, ok := status["display"]; ok {
return toString(display)
}
}
return ""
}
// SlackMessageID
// Get ticket custom field slack message id
func (t Ticket) SlackMessageID() string {
return t.GetField("slackMessageID")
}
// GetField
// Get any custom ticket field
func (t Ticket) GetField(field string) string {
if key, ok := t[field]; ok {
return toString(key)
}
return ""
}
func toString(v interface{}) string {
switch v.(type) {
case string:
return v.(string)
default:
return ""
}
}