Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List incident alerts #214

Merged
merged 4 commits into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion incident.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,26 @@ type ListAlertsResponse struct {
Alerts []IncidentAlert `json:"alerts,omitempty"`
}

// ListIncidentAlertsOptions is the structure used when passing parameters to the ListIncidentAlerts API endpoint.
type ListIncidentAlertsOptions struct {
APIListObject
Statuses []string `url:"statuses,omitempty,brackets"`
SortBy string `url:"sort_by,omitempty"`
Includes []string `url:"include,omitempty,brackets"`
}

// ListIncidentAlerts lists existing alerts for the specified incident.
func (c *Client) ListIncidentAlerts(id string) (*ListAlertsResponse, error) {
resp, err := c.get("/incidents/" + id + "/alerts")
return c.ListIncidentAlertsWithOpts(id, ListIncidentAlertsOptions{})
}

// ListIncidentAlertsWithOpts lists existing alerts for the specified incident.
func (c *Client) ListIncidentAlertsWithOpts(id string, o ListIncidentAlertsOptions) (*ListAlertsResponse, error) {
v, err := query.Values(o)
if err != nil {
return nil, err
}
resp, err := c.get("/incidents/" + id + "/alerts?" + v.Encode())
if err != nil {
return nil, err
}
Expand Down
36 changes: 36 additions & 0 deletions incident_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,42 @@ func TestIncident_ListIncidentAlerts(t *testing.T) {
}
testEqual(t, want, res)
}
func TestIncident_ListIncidentAlertsWithOpts(t *testing.T) {
setup()
defer teardown()

mux.HandleFunc("/incidents/1/alerts", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
w.Write([]byte(`{"alerts": [{"id": "1","summary":"foo"}]}`))
})
var listObj = APIListObject{Limit: 0, Offset: 0, More: false, Total: 0}
var client = &Client{apiEndpoint: server.URL, authToken: "foo", HTTPClient: defaultHTTPClient}
id := "1"

var alertOpts = ListIncidentAlertsOptions{
APIListObject: listObj,
Includes: []string{},
}

res, err := client.ListIncidentAlertsWithOpts(id, alertOpts)

want := &ListAlertsResponse{
APIListObject: listObj,
Alerts: []IncidentAlert{
{
APIObject: APIObject{
ID: "1",
Summary: "foo",
},
},
},
}

if err != nil {
t.Fatal(err)
}
testEqual(t, want, res)
}

// CreateIncidentNote
func TestIncident_CreateIncidentNote(t *testing.T) {
Expand Down