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

Remove returned *http.Response from incident-related methods #357

Merged
merged 1 commit into from
Nov 6, 2021
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
31 changes: 10 additions & 21 deletions incident.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package pagerduty
import (
"context"
"fmt"
"net/http"

"github.com/google/go-querystring/query"
)
Expand Down Expand Up @@ -613,55 +612,45 @@ func (c *Client) ResponderRequestWithContext(ctx context.Context, id string, o R
// GetIncidentAlert gets the alert that triggered the incident.
//
// Deprecated: Use GetIncidentAlertWithContext instead.
func (c *Client) GetIncidentAlert(incidentID, alertID string) (*IncidentAlertResponse, *http.Response, error) {
return c.getIncidentAlertWithContext(context.Background(), incidentID, alertID)
func (c *Client) GetIncidentAlert(incidentID, alertID string) (*IncidentAlertResponse, error) {
return c.GetIncidentAlertWithContext(context.Background(), incidentID, alertID)
}

// GetIncidentAlertWithContext gets the alert that triggered the incident.
func (c *Client) GetIncidentAlertWithContext(ctx context.Context, incidentID, alertID string) (*IncidentAlertResponse, error) {
iar, _, err := c.getIncidentAlertWithContext(context.Background(), incidentID, alertID)
return iar, err
}

func (c *Client) getIncidentAlertWithContext(ctx context.Context, incidentID, alertID string) (*IncidentAlertResponse, *http.Response, error) {
resp, err := c.get(ctx, "/incidents/"+incidentID+"/alerts/"+alertID)
if err != nil {
return nil, nil, err
return nil, err
}

var result IncidentAlertResponse
if err = c.decodeJSON(resp, &result); err != nil {
return nil, nil, err
return nil, err
}

return &result, resp, nil
return &result, nil
}

// ManageIncidentAlerts allows you to manage the alerts of an incident.
//
// Deprecated: Use ManageIncidentAlertsWithContext instead.
func (c *Client) ManageIncidentAlerts(incidentID string, alerts *IncidentAlertList) (*ListAlertsResponse, *http.Response, error) {
return c.manageIncidentAlertsWithContext(context.Background(), incidentID, alerts)
func (c *Client) ManageIncidentAlerts(incidentID string, alerts *IncidentAlertList) (*ListAlertsResponse, error) {
return c.ManageIncidentAlertsWithContext(context.Background(), incidentID, alerts)
}

// ManageIncidentAlertsWithContext allows you to manage the alerts of an incident.
func (c *Client) ManageIncidentAlertsWithContext(ctx context.Context, incidentID string, alerts *IncidentAlertList) (*ListAlertsResponse, error) {
lar, _, err := c.manageIncidentAlertsWithContext(context.Background(), incidentID, alerts)
return lar, err
}

func (c *Client) manageIncidentAlertsWithContext(ctx context.Context, incidentID string, alerts *IncidentAlertList) (*ListAlertsResponse, *http.Response, error) {
resp, err := c.put(ctx, "/incidents/"+incidentID+"/alerts/", alerts, nil)
if err != nil {
return nil, nil, err
return nil, err
}

var result ListAlertsResponse
if err = c.decodeJSON(resp, &result); err != nil {
return nil, nil, err
return nil, err
}

return &result, resp, nil
return &result, nil
}

/* TODO: Create Status Updates */
4 changes: 2 additions & 2 deletions incident_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ func TestIncident_GetAlert(t *testing.T) {

incidentID := "1"
alertID := "1"
res, _, err := client.GetIncidentAlert(incidentID, alertID)
res, err := client.GetIncidentAlert(incidentID, alertID)

want := &IncidentAlertResponse{
IncidentAlert: &IncidentAlert{
Expand Down Expand Up @@ -657,7 +657,7 @@ func TestIncident_ManageAlerts(t *testing.T) {
},
},
}
res, _, err := client.ManageIncidentAlerts(incidentID, input)
res, err := client.ManageIncidentAlerts(incidentID, input)

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