Repository navigation
Expand file tree
/
Copy pathincident.go
More file actions
63 lines (55 loc) · 2 KB
/
Copy pathincident.go
File metadata and controls
63 lines (55 loc) · 2 KB
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 githubstatus
import (
"slices"
"time"
)
// IncidentList is the response from the incidents.json endpoint.
type IncidentList struct {
Page Page `json:"page"`
Incidents []Incident `json:"incidents"`
}
// Incident is an incident or a scheduled maintenance.
type Incident struct {
ID string `json:"id"`
Name string `json:"name"`
Status IncidentStatus `json:"status"`
Impact Impact `json:"impact"`
Shortlink string `json:"shortlink"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
StartedAt *time.Time `json:"started_at"`
MonitoringAt *time.Time `json:"monitoring_at"`
ResolvedAt *time.Time `json:"resolved_at"`
ScheduledFor *time.Time `json:"scheduled_for"`
ScheduledUntil *time.Time `json:"scheduled_until"`
Updates []IncidentUpdate `json:"incident_updates"`
// Components lists the components affected by the incident, with their
// statuses at the time the incident data was fetched.
Components []Component `json:"components"`
}
// Start returns when the incident started, falling back to when it was
// created if the start time is not set.
func (i Incident) Start() time.Time {
if i.StartedAt != nil {
return *i.StartedAt
}
return i.CreatedAt
}
// LatestUpdate returns the most recently displayed update, if any.
func (i Incident) LatestUpdate() (IncidentUpdate, bool) {
if len(i.Updates) == 0 {
return IncidentUpdate{}, false
}
return slices.MaxFunc(i.Updates, func(a, b IncidentUpdate) int {
return a.DisplayAt.Compare(b.DisplayAt)
}), true
}
// IncidentUpdate is a single update posted to an incident.
type IncidentUpdate struct {
ID string `json:"id"`
Status IncidentStatus `json:"status"`
Body string `json:"body"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DisplayAt time.Time `json:"display_at"`
}