diff --git a/incident.go b/incident.go index 4bf79c92..a01c4641 100644 --- a/incident.go +++ b/incident.go @@ -632,15 +632,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 } diff --git a/incident_test.go b/incident_test.go index 24e77972..aba9f6f3 100644 --- a/incident_test.go +++ b/incident_test.go @@ -1,6 +1,7 @@ package pagerduty import ( + "context" "encoding/json" "io/ioutil" "net/http" @@ -708,12 +709,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"}]}`)) }) @@ -730,7 +736,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{