/
api.go
72 lines (53 loc) · 1.36 KB
/
api.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
package reporter
import (
"fmt"
"html/template"
"time"
)
type EventResponse struct {
event *Event
ID string
Type string
Instance EventInstanceResp
ExecutionStartedAt string
ExecutionCompletedAt string
Error string
}
type EventInstanceResp struct {
ID string
Group string
Deployment string
AZ string
}
func NewEventResponse(event *Event) EventResponse {
var completedAt string
if (event.ExecutionCompletedAt != time.Time{}) {
completedAt = event.ExecutionCompletedAt.Format(time.RFC3339)
}
return EventResponse{
event: event,
ID: event.ID,
Type: event.Type,
Instance: EventInstanceResp{
ID: event.Instance.ID,
Group: event.Instance.Group,
Deployment: event.Instance.Deployment,
AZ: event.Instance.AZ,
},
ExecutionStartedAt: event.ExecutionStartedAt.Format(time.RFC3339),
ExecutionCompletedAt: completedAt,
Error: event.ErrorStr(),
}
}
func (r EventResponse) IsAction() bool { return r.event.IsAction() }
func (r EventResponse) DescriptionHTML() template.HTML {
content := ""
if len(r.Instance.ID) > 0 {
content = fmt.Sprintf("<span>Instance</span> %s/%s", r.Instance.Group, r.Instance.ID)
content += " <span>Deployment</span> " + r.Instance.Deployment
if len(r.Instance.AZ) > 0 {
content += " <span>AZ</span> " + r.Instance.AZ
}
}
return template.HTML(content)
}