-
Notifications
You must be signed in to change notification settings - Fork 8
/
events_app.go
205 lines (166 loc) · 4.72 KB
/
events_app.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
package scalingo
import (
"fmt"
"strings"
)
type EventNewAppTypeData struct {
GitSource string `json:"git_source"`
}
type EventNewAppType struct {
Event
TypeData EventNewAppTypeData `json:"type_data"`
}
func (ev *EventNewAppType) String() string {
return "the application has been created"
}
type EventEditAppTypeData struct {
ForceHTTPS *bool `json:"force_https"`
}
type EventEditAppType struct {
Event
TypeData EventEditAppTypeData `json:"type_data"`
}
func (ev *EventEditAppType) String() string {
base := "application settings have been updated"
if ev.TypeData.ForceHTTPS != nil {
if *ev.TypeData.ForceHTTPS {
base += ", Force HTTPS has been enabled"
} else {
base += ", Force HTTPS has been disabled"
}
}
return base
}
type EventDeleteAppType struct {
Event
}
func (ev *EventDeleteAppType) String() string {
return "the application has been deleted"
}
type EventRenameAppTypeData struct {
OldName string `json:"old_name"`
NewName string `json:"new_name"`
}
type EventRenameAppType struct {
Event
TypeData EventRenameAppTypeData `json:"type_data"`
}
func (ev *EventRenameAppType) String() string {
return fmt.Sprintf(
"the application has been renamed from '%s' to '%s'",
ev.TypeData.OldName, ev.TypeData.NewName,
)
}
type EventTransferAppTypeData struct {
OldOwner EventUser `json:"old_owner"`
NewOwner EventUser `json:"new_owner"`
}
type EventTransferAppType struct {
Event
TypeData EventTransferAppTypeData `json:"type_data"`
}
func (ev *EventTransferAppType) String() string {
return fmt.Sprintf(
"the application has been transferred to %s (%s)",
ev.TypeData.NewOwner.Username, ev.TypeData.NewOwner.Email,
)
}
type EventRestartTypeData struct {
Scope []string `json:"scope"`
AddonName string `json:"addon_name"`
}
type EventRestartType struct {
Event
TypeData EventRestartTypeData `json:"type_data"`
}
func (ev *EventRestartType) String() string {
if len(ev.TypeData.Scope) != 0 {
return fmt.Sprintf("containers %v began to restart", ev.TypeData.Scope)
}
return "containers began to restart"
}
func (ev *EventRestartType) Who() string {
if ev.TypeData.AddonName != "" {
return fmt.Sprintf("Addon %s", ev.TypeData.AddonName)
}
return ev.Event.Who()
}
type EventStopAppTypeData struct {
Reason string `json:"reason"`
}
type EventStopAppType struct {
Event
TypeData EventStopAppTypeData `json:"type_data"`
}
func (ev *EventStopAppType) String() string {
return fmt.Sprintf("app has been stopped (reason: %s)", ev.TypeData.Reason)
}
func (ev *EventScaleType) String() string {
return fmt.Sprintf(
"containers have been scaled from %s, to %s",
ev.TypeData.containersString(ev.TypeData.PreviousContainers),
ev.TypeData.containersString(ev.TypeData.Containers),
)
}
type EventScaleTypeData struct {
PreviousContainers map[string]string `json:"previous_containers"`
Containers map[string]string `json:"containers"`
}
type EventScaleType struct {
Event
TypeData EventScaleTypeData `json:"type_data"`
}
func (e *EventScaleTypeData) containersString(containers map[string]string) string {
types := []string{}
for name, amountAndSize := range containers {
types = append(types, fmt.Sprintf("%s:%s", name, amountAndSize))
}
return "[" + strings.Join(types, ", ") + "]"
}
type EventCrashTypeData struct {
ContainerType string `json:"container_type"`
CrashLogs string `json:"crash_logs"`
LogsURL string `json:"logs_url"`
}
type EventCrashType struct {
Event
TypeData EventCrashTypeData `json:"type_data"`
}
func (ev *EventCrashType) String() string {
msg := fmt.Sprintf("container '%v' has crashed", ev.TypeData.ContainerType)
if ev.TypeData.CrashLogs != "" {
msg += fmt.Sprintf(" (logs on %s)", ev.TypeData.LogsURL)
}
return msg
}
type EventRepeatedCrashTypeData struct {
ContainerType string `json:"container_type"`
CrashLogs string `json:"crash_logs"`
LogsURL string `json:"logs_url"`
}
type EventRepeatedCrashType struct {
Event
TypeData EventRepeatedCrashTypeData `json:"type_data"`
}
func (ev *EventRepeatedCrashType) String() string {
msg := fmt.Sprintf("container '%v' has crashed repeatedly", ev.TypeData.ContainerType)
if ev.TypeData.CrashLogs != "" {
msg += fmt.Sprintf(" (logs on %s)", ev.TypeData.LogsURL)
}
return msg
}
type EventDeploymentTypeData struct {
DeploymentID string `json:"deployment_id"`
Pusher string `json:"pusher"`
GitRef string `json:"git_ref"`
Status string `json:"status"`
Duration int `json:"duration"`
DeploymentUUID string `json:"deployment_uuid"`
}
type EventDeploymentType struct {
Event
TypeData EventDeploymentTypeData `json:"type_data"`
}
func (ev *EventDeploymentType) String() string {
return fmt.Sprintf("deployment of %s (%s)", ev.TypeData.GitRef, ev.TypeData.Status)
}