Skip to content

Commit

Permalink
Second batch of fixes for API incompatibilities
Browse files Browse the repository at this point in the history
Updates #389
  • Loading branch information
theckman committed Jan 16, 2022
1 parent 77a73c9 commit a5c39af
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 55 deletions.
11 changes: 6 additions & 5 deletions extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import (
// features to be used as part of the incident management process.
type Extension struct {
APIObject
Name string `json:"name"`
EndpointURL string `json:"endpoint_url,omitempty"`
ExtensionObjects []APIObject `json:"extension_objects"`
ExtensionSchema APIObject `json:"extension_schema"`
Config interface{} `json:"config"`
Name string `json:"name"`
EndpointURL string `json:"endpoint_url,omitempty"`
ExtensionObjects []APIObject `json:"extension_objects"`
ExtensionSchema APIObject `json:"extension_schema"`
Config interface{} `json:"config"`
TemporarilyDisabled bool `json:"temporarily_disabled,omitempty"`
}

// ListExtensionResponse represents the single response from the PagerDuty API
Expand Down
24 changes: 10 additions & 14 deletions incident.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ type Incident struct {
AssignedVia string `json:"assigned_via,omitempty"`
Occurrence *Occurrence `json:"occurrence,omitempty"`
IncidentResponders []IncidentResponders `json:"incidents_responders,omitempty"`
ResponderRequests []ResponderRequest `json:"responder_requests,omitempty"`
}

// ListIncidentsResponse is the response structure when calling the ListIncident API endpoint.
Expand Down Expand Up @@ -659,26 +660,21 @@ type ResponderRequestTarget struct {
Responders IncidentResponders `json:"incident_responders"`
}

// ResponderRequestTargets is a wrapper for a ResponderRequestTarget.
type ResponderRequestTargets struct {
Target ResponderRequestTarget `json:"responder_request_target"`
}

// ResponderRequestOptions defines the input options for the Create Responder function.
type ResponderRequestOptions struct {
From string `json:"-"`
Message string `json:"message"`
RequesterID string `json:"requester_id"`
Targets []ResponderRequestTargets `json:"responder_request_targets"`
From string `json:"-"`
Message string `json:"message"`
RequesterID string `json:"requester_id"`
Targets []ResponderRequestTarget `json:"responder_request_targets"`
}

// ResponderRequest contains the API structure for an incident responder request.
type ResponderRequest struct {
Incident Incident `json:"incident"`
Requester User `json:"requester,omitempty"`
RequestedAt string `json:"request_at,omitempty"`
Message string `json:"message,omitempty"`
Targets []ResponderRequestTargets `json:"responder_request_targets"`
Incident Incident `json:"incident"`
Requester User `json:"requester,omitempty"`
RequestedAt string `json:"request_at,omitempty"`
Message string `json:"message,omitempty"`
Targets []ResponderRequestTarget `json:"responder_request_targets"`
}

// ResponderRequest will submit a request to have a responder join an incident.
Expand Down
22 changes: 8 additions & 14 deletions incident_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -808,14 +808,12 @@ func TestIncident_ResponderRequest(t *testing.T) {
},
"message": "Help",
"responder_request_targets": [{
"responder_request_target": {
"id": "PJ25ZYX",
"type": "user_reference",
"incident_responders": {
"state": "pending",
"user": {
"id": "PJ25ZYX"
}
"id": "PJ25ZYX",
"type": "user_reference",
"incident_responders": {
"state": "pending",
"user": {
"id": "PJ25ZYX"
}
}
}]
Expand All @@ -829,9 +827,7 @@ func TestIncident_ResponderRequest(t *testing.T) {
r.ID = "PJ25ZYX"
r.Type = "user_reference"

targets := []ResponderRequestTargets{
ResponderRequestTargets{Target: r},
}
targets := []ResponderRequestTarget{r}

input := ResponderRequestOptions{
From: from,
Expand All @@ -850,9 +846,7 @@ func TestIncident_ResponderRequest(t *testing.T) {
target.Responders.State = "pending"
target.Responders.User.ID = "PJ25ZYX"

targets = []ResponderRequestTargets{
ResponderRequestTargets{Target: target},
}
targets = []ResponderRequestTarget{target}

want := &ResponderRequestResponse{
ResponderRequest: ResponderRequest{
Expand Down
1 change: 1 addition & 0 deletions log_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type ListLogEntriesOptions struct {
Until string `url:"until,omitempty"`
IsOverview bool `url:"is_overview,omitempty"`
Includes []string `url:"include,omitempty,brackets"`
TeamIDs []string `url:"team_ids,omitempty,brackets"`
}

// ListLogEntries lists all of the incident log entries across the entire
Expand Down
14 changes: 7 additions & 7 deletions maintenance_window.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
// MaintenanceWindow is used to temporarily disable one or more services for a set period of time.
type MaintenanceWindow struct {
APIObject
SequenceNumber uint `json:"sequence_number,omitempty"`
StartTime string `json:"start_time"`
EndTime string `json:"end_time"`
Description string `json:"description"`
Services []APIObject `json:"services"`
Teams []APIListObject `json:"teams"`
CreatedBy APIListObject `json:"created_by"`
SequenceNumber uint `json:"sequence_number,omitempty"`
StartTime string `json:"start_time"`
EndTime string `json:"end_time"`
Description string `json:"description"`
Services []APIObject `json:"services"`
Teams []APIObject `json:"teams,omitempty"`
CreatedBy *APIObject `json:"created_by,omitempty"`
}

// ListMaintenanceWindowsResponse is the data structur returned from calling the ListMaintenanceWindows API endpoint.
Expand Down
12 changes: 7 additions & 5 deletions notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import (

// Notification is a message containing the details of the incident.
type Notification struct {
ID string `json:"id"`
Type string
StartedAt string `json:"started_at"`
Address string
User APIObject
ID string `json:"id"`
Type string `json:"type"`
StartedAt string `json:"started_at"`
Address string `json:"address"`
User APIObject `json:"user"`
ConferenceAddress string `json:"conferenceAddress"`
Status string `json:"status"`
}

// ListNotificationOptions is the data structure used when calling the ListNotifications API endpoint.
Expand Down
38 changes: 28 additions & 10 deletions ruleset.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@ type Ruleset struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"`
Self string `json:"self,omitempty"`
RoutingKeys []string `json:"routing_keys,omitempty"`
Team *RulesetObject `json:"team,omitempty"`
Updater *RulesetObject `json:"updater,omitempty"`
CreatedAt string `json:"created_at"`
Creator *RulesetObject `json:"creator,omitempty"`
UpdatedAt string `json:"updated_at"`
Updater *RulesetObject `json:"updater,omitempty"`
Team *RulesetObject `json:"team,omitempty"`
}

// RulesetObject represents a generic object that is common within a ruleset object
type RulesetObject struct {
Type string `json:"type,omitempty"`
ID string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
Self string `json:"self,omitempty"`
}

// RulesetPayload represents payload with a ruleset object
Expand All @@ -40,12 +44,12 @@ type ListRulesetsResponse struct {
// RulesetRule represents a Ruleset rule
type RulesetRule struct {
ID string `json:"id,omitempty"`
Self string `json:"self,omitempty"`
Position *int `json:"position,omitempty"`
Disabled bool `json:"disabled,omitempty"`
Conditions *RuleConditions `json:"conditions,omitempty"`
Actions *RuleActions `json:"actions,omitempty"`
Ruleset *APIObject `json:"ruleset,omitempty"`
Self string `json:"self,omitempty"`
CatchAll bool `json:"catch_all,omitempty"`
TimeFrame *RuleTimeFrame `json:"time_frame,omitempty"`
}
Expand Down Expand Up @@ -81,16 +85,29 @@ type RuleTimeFrame struct {

// ScheduledWeekly represents a time_frame object for scheduling rules weekly
type ScheduledWeekly struct {
Weekdays []int `json:"weekdays,omitempty"`
Timezone string `json:"timezone,omitempty"`
StartTime int `json:"start_time,omitempty"`
Duration int `json:"duration,omitempty"`
// Weekdays is a 0 indexed slice of days, where 0 is Sunday and 6 is
// Saturday, when the window is scheduled for.
Weekdays []int `json:"weekdays,omitempty"`

Timezone string `json:"timezone,omitempty"`

// StartTime is the number of milliseconds into the day at which the window
// starts.
StartTime int `json:"start_time,omitempty"`

// Duration is the window duration in milliseconds.
Duration int `json:"duration,omitempty"`
}

// ActiveBetween represents an active_between object for setting a timeline for rules
type ActiveBetween struct {
// StartTime is in the number of milliseconds into the day at which the
// window starts.
StartTime int `json:"start_time,omitempty"`
EndTime int `json:"end_time,omitempty"`

// EndTime is the number of milliseconds into the day at which the window
// ends.
EndTime int `json:"end_time,omitempty"`
}

// ListRulesetRulesResponse represents a list of rules in a ruleset
Expand Down Expand Up @@ -129,7 +146,8 @@ type RuleActionSuppress struct {

// RuleActionSuspend represents a rule suspend action object
type RuleActionSuspend struct {
Value *bool `json:"value,omitempty"`
// Value specifies for how long to suspend the alert in seconds.
Value int `json:"value,omitempty"`
}

// RuleActionExtraction represents a rule extraction action object
Expand Down

0 comments on commit a5c39af

Please sign in to comment.