Skip to content

Commit

Permalink
Merge pull request #380 from PagerDuty/from_incident_alerts
Browse files Browse the repository at this point in the history
Add missing required parameter to ManageIncidentAlerts
  • Loading branch information
theckman committed Nov 10, 2021
2 parents f430a2d + 52e8c50 commit 7f42680
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
13 changes: 5 additions & 8 deletions incident.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,15 +633,12 @@ func (c *Client) GetIncidentAlertWithContext(ctx context.Context, incidentID, al
}

// ManageIncidentAlerts allows you to manage the alerts of an incident.
//
// Deprecated: Use ManageIncidentAlertsWithContext instead.
func (c *Client) ManageIncidentAlerts(incidentID string, alerts *IncidentAlertList) (*ListAlertsResponse, error) {
return c.ManageIncidentAlertsWithContext(context.Background(), incidentID, alerts)
}
func (c *Client) ManageIncidentAlerts(ctx context.Context, incidentID, from string, alerts *IncidentAlertList) (*ListAlertsResponse, error) {
h := map[string]string{
"From": from,
}

// ManageIncidentAlertsWithContext allows you to manage the alerts of an incident.
func (c *Client) ManageIncidentAlertsWithContext(ctx context.Context, incidentID string, alerts *IncidentAlertList) (*ListAlertsResponse, error) {
resp, err := c.put(ctx, "/incidents/"+incidentID+"/alerts/", alerts, nil)
resp, err := c.put(ctx, "/incidents/"+incidentID+"/alerts/", alerts, h)
if err != nil {
return nil, err
}
Expand Down
10 changes: 8 additions & 2 deletions incident_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pagerduty

import (
"context"
"encoding/json"
"io/ioutil"
"net/http"
Expand Down Expand Up @@ -744,12 +745,17 @@ func TestIncident_GetAlert(t *testing.T) {
testEqual(t, want, res)
}

func TestIncident_ManageAlerts(t *testing.T) {
func TestIncident_ManageIncidentAlerts(t *testing.T) {
setup()
defer teardown()

from := "pagerduty@example.com"

mux.HandleFunc("/incidents/1/alerts/", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
if hdr := r.Header.Get("From"); hdr != "pagerduty@example.com" {
t.Errorf("From header = %q, want %q", hdr, from)
}
_, _ = w.Write([]byte(`{"alerts": [{"id": "1"}]}`))
})

Expand All @@ -766,7 +772,7 @@ func TestIncident_ManageAlerts(t *testing.T) {
},
},
}
res, err := client.ManageIncidentAlerts(incidentID, input)
res, err := client.ManageIncidentAlerts(context.Background(), incidentID, from, input)

want := &ListAlertsResponse{
Alerts: []IncidentAlert{
Expand Down

0 comments on commit 7f42680

Please sign in to comment.