Skip to content

Commit

Permalink
Merge pull request #230 from afarbos/master
Browse files Browse the repository at this point in the history
Add FirstTriggerLogEntry and CommonLogEntryField fields and json tags
  • Loading branch information
Scott McAllister committed Jun 24, 2020
2 parents ac15509 + 974579f commit e8ee333
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 43 deletions.
50 changes: 28 additions & 22 deletions incident.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,37 @@ type Assignee struct {
Assignee APIObject `json:"assignee"`
}

// FirstTriggerLogEntry is the first LogEntry
type FirstTriggerLogEntry struct {
CommonLogEntryField
Incident APIObject `json:"incident,omitempty"`
}

// Incident is a normalized, de-duplicated event generated by a PagerDuty integration.
type Incident struct {
APIObject
IncidentNumber uint `json:"incident_number,omitempty"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
PendingActions []PendingAction `json:"pending_actions,omitempty"`
IncidentKey string `json:"incident_key,omitempty"`
Service APIObject `json:"service,omitempty"`
Assignments []Assignment `json:"assignments,omitempty"`
Acknowledgements []Acknowledgement `json:"acknowledgements,omitempty"`
LastStatusChangeAt string `json:"last_status_change_at,omitempty"`
LastStatusChangeBy APIObject `json:"last_status_change_by,omitempty"`
FirstTriggerLogEntry APIObject `json:"first_trigger_log_entry,omitempty"`
EscalationPolicy APIObject `json:"escalation_policy,omitempty"`
Teams []APIObject `json:"teams,omitempty"`
Priority *Priority `json:"priority,omitempty"`
Urgency string `json:"urgency,omitempty"`
Status string `json:"status,omitempty"`
Id string `json:"id,omitempty"`
ResolveReason ResolveReason `json:"resolve_reason,omitempty"`
AlertCounts AlertCounts `json:"alert_counts,omitempty"`
Body IncidentBody `json:"body,omitempty"`
IsMergeable bool `json:"is_mergeable,omitempty"`
IncidentNumber uint `json:"incident_number,omitempty"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
PendingActions []PendingAction `json:"pending_actions,omitempty"`
IncidentKey string `json:"incident_key,omitempty"`
Service APIObject `json:"service,omitempty"`
Assignments []Assignment `json:"assignments,omitempty"`
Acknowledgements []Acknowledgement `json:"acknowledgements,omitempty"`
LastStatusChangeAt string `json:"last_status_change_at,omitempty"`
LastStatusChangeBy APIObject `json:"last_status_change_by,omitempty"`
FirstTriggerLogEntry FirstTriggerLogEntry `json:"first_trigger_log_entry,omitempty"`
EscalationPolicy APIObject `json:"escalation_policy,omitempty"`
Teams []APIObject `json:"teams,omitempty"`
Priority *Priority `json:"priority,omitempty"`
Urgency string `json:"urgency,omitempty"`
Status string `json:"status,omitempty"`
Id string `json:"id,omitempty"`
ResolveReason ResolveReason `json:"resolve_reason,omitempty"`
AlertCounts AlertCounts `json:"alert_counts,omitempty"`
Body IncidentBody `json:"body,omitempty"`
IsMergeable bool `json:"is_mergeable,omitempty"`
}

// ListIncidentsResponse is the response structure when calling the ListIncident API endpoint.
Expand Down
16 changes: 10 additions & 6 deletions incident_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,9 +474,11 @@ func TestIncident_ListLogEntries(t *testing.T) {
APIListObject: listObj,
LogEntries: []LogEntry{
{
APIObject: APIObject{
ID: "1",
Summary: "foo",
CommonLogEntryField: CommonLogEntryField{
APIObject: APIObject{
ID: "1",
Summary: "foo",
},
},
},
},
Expand Down Expand Up @@ -514,9 +516,11 @@ func TestIncident_ListLogEntriesSinceUntil(t *testing.T) {
APIListObject: listObj,
LogEntries: []LogEntry{
{
APIObject: APIObject{
ID: "1",
Summary: "foo",
CommonLogEntryField: CommonLogEntryField{
APIObject: APIObject{
ID: "1",
Summary: "foo",
},
},
},
},
Expand Down
23 changes: 14 additions & 9 deletions log_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,22 @@ type Context struct {
Type string
}

// CommonLogEntryField is the list of shared log entry between Incident and LogEntry
type CommonLogEntryField struct {
APIObject
CreatedAt string `json:"created_at,omitempty"`
Agent Agent `json:"agent,omitempty"`
Channel Channel `json:"channel,omitempty"`
Teams []Team `json:"teams,omitempty"`
Contexts []Context `json:"contexts,omitempty"`
AcknowledgementTimeout int `json:"acknowledgement_timeout"`
EventDetails map[string]string `json:"event_details,omitempty"`
}

// LogEntry is a list of all of the events that happened to an incident.
type LogEntry struct {
APIObject
CreatedAt string `json:"created_at"`
Agent Agent
Channel Channel
Incident Incident
Teams []Team
Contexts []Context
AcknowledgementTimeout int `json:"acknowledgement_timeout"`
EventDetails map[string]string
CommonLogEntryField
Incident Incident
}

// ListLogEntryResponse is the response data when calling the ListLogEntry API endpoint.
Expand Down
16 changes: 10 additions & 6 deletions log_entry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ func TestLogEntry_List(t *testing.T) {
APIListObject: listObj,
LogEntries: []LogEntry{
{
APIObject: APIObject{
ID: "1",
Summary: "foo",
CommonLogEntryField: CommonLogEntryField{
APIObject: APIObject{
ID: "1",
Summary: "foo",
},
},
},
},
Expand All @@ -57,9 +59,11 @@ func TestLogEntry_Get(t *testing.T) {
res, err := client.GetLogEntry(id, opts)

want := &LogEntry{
APIObject: APIObject{
ID: "1",
Summary: "foo",
CommonLogEntryField: CommonLogEntryField{
APIObject: APIObject{
ID: "1",
Summary: "foo",
},
},
}

Expand Down

0 comments on commit e8ee333

Please sign in to comment.