Repository: PagerDuty/go-pagerduty
Pull request #231 (2020-06-26 00:52:41)

Adding Get Incident Alert and Manage Incident Alert endpoints
Test results for all the incident tests since I also added ConferenceBridge to the Incident object. 

```
=== RUN   TestIncident_List
--- PASS: TestIncident_List (0.00s)
=== RUN   TestIncident_Create
--- PASS: TestIncident_Create (0.00s)
=== RUN   TestIncident_Manage_status
--- PASS: TestIncident_Manage_status (0.00s)
=== RUN   TestIncident_Manage_priority
--- PASS: TestIncident_Manage_priority (0.00s)
=== RUN   TestIncident_Manage_assignments
--- PASS: TestIncident_Manage_assignments (0.00s)
=== RUN   TestIncident_Merge
--- PASS: TestIncident_Merge (0.00s)
=== RUN   TestIncident_Get
--- PASS: TestIncident_Get (0.00s)
=== RUN   TestIncident_ListIncidentNotes
--- PASS: TestIncident_ListIncidentNotes (0.00s)
=== RUN   TestIncident_ListIncidentAlerts
--- PASS: TestIncident_ListIncidentAlerts (0.00s)
=== RUN   TestIncident_ListIncidentAlertsWithOpts
--- PASS: TestIncident_ListIncidentAlertsWithOpts (0.00s)
=== RUN   TestIncident_CreateIncidentNote
--- PASS: TestIncident_CreateIncidentNote (0.00s)
=== RUN   TestIncident_CreateIncidentNoteWithResponse
--- PASS: TestIncident_CreateIncidentNoteWithResponse (0.00s)
=== RUN   TestIncident_SnoozeIncident
--- PASS: TestIncident_SnoozeIncident (0.00s)
=== RUN   TestIncident_SnoozeIncidentWithResponse
--- PASS: TestIncident_SnoozeIncidentWithResponse (0.00s)
=== RUN   TestIncident_ListLogEntries
--- PASS: TestIncident_ListLogEntries (0.00s)
=== RUN   TestIncident_ListLogEntriesSinceUntil
--- PASS: TestIncident_ListLogEntriesSinceUntil (0.00s)
=== RUN   TestIncident_ResponderRequest
--- PASS: TestIncident_ResponderRequest (0.00s)
=== RUN   TestIncident_GetAlert
--- PASS: TestIncident_GetAlert (0.00s)
=== RUN   TestIncident_ManageAlerts
--- PASS: TestIncident_ManageAlerts (0.00s)
```



Patch:
diff --git a/incident.go b/incident.go
index e586ece..7739b08 100644
--- a/incident.go
+++ b/incident.go
@@ -3,6 +3,7 @@ package pagerduty
 import (
 	"encoding/json"
 	"fmt"
+	"net/http"
 
 	"github.com/google/go-querystring/query"
 )
@@ -86,6 +87,7 @@ type Incident struct {
 	AlertCounts          AlertCounts          `json:"alert_counts,omitempty"`
 	Body                 IncidentBody         `json:"body,omitempty"`
 	IsMergeable          bool                 `json:"is_mergeable,omitempty"`
+	ConferenceBridge     *ConferenceBridge    `json:"conference_bridge,omitempty"`
 }
 
 // ListIncidentsResponse is the response structure when calling the ListIncident API endpoint.
@@ -111,6 +113,12 @@ type ListIncidentsOptions struct {
 	Includes    []string `url:"include,omitempty,brackets"`
 }
 
+// ConferenceBridge is a struct for the conference_bridge object on an incident
+type ConferenceBridge struct {
+	ConferenceNumber string `json:"conference_number,omitempty"`
+	ConferenceURL    string `json:"conference_url,omitempty"`
+}
+
 // ListIncidents lists existing incidents.
 func (c *Client) ListIncidents(o ListIncidentsOptions) (*ListIncidentsResponse, error) {
 	v, err := query.Values(o)
@@ -269,6 +277,16 @@ type IncidentAlert struct {
 	Integration APIObject              `json:"integration,omitempty"`
 }
 
+// IncidentAlertResponse is the response of a sincle incident alert
+type IncidentAlertResponse struct {
+	IncidentAlert *IncidentAlert `json:"alert,omitempty"`
+}
+
+// IncidentAlertList is the generic structure of a list of alerts
+type IncidentAlertList struct {
+	Alerts []IncidentAlert `json:"alerts,omitempty"`
+}
+
 // ListAlertsResponse is the response structure when calling the ListAlert API endpoint.
 type ListAlertsResponse struct {
 	APIListObject
@@ -392,21 +410,6 @@ func (c *Client) ListIncidentLogEntries(id string, o ListIncidentLogEntriesOptio
 	return &result, c.decodeJSON(resp, &result)
 }
 
-// Alert is a list of all of the alerts that happened to an incident.
-type Alert struct {
-	APIObject
-	Service   APIObject `json:"service,omitempty"`
-	CreatedAt string    `json:"created_at,omitempty"`
-	Status    string    `json:"status,omitempty"`
-	AlertKey  string    `json:"alert_key,omitempty"`
-	Incident  APIObject `json:"incident,omitempty"`
-}
-
-type ListAlertResponse struct {
-	APIListObject
-	Alerts []Alert `json:"alerts,omitempty"`
-}
-
 // IncidentResponders contains details about responders to an incident.
 type IncidentResponders struct {
 	State       string    `json:"state"`
@@ -466,4 +469,28 @@ func (c *Client) ResponderRequest(id string, o ResponderRequestOptions) (*Respon
 	return result, err
 }
 
-/* TODO: Manage Alerts, Get Alert, Create Status Updates */
+// GetIncidentAlert
+func (c *Client) GetIncidentAlert(incidentID, alertID string) (*IncidentAlertResponse, *http.Response, error) {
+	resp, err := c.get("/incidents/" + incidentID + "/alerts/" + alertID)
+	if err != nil {
+		return nil, nil, err
+	}
+
+	result := &IncidentAlertResponse{}
+	err = json.NewDecoder(resp.Body).Decode(result)
+	return result, resp, err
+}
+
+// ManageIncidentAlerts
+func (c *Client) ManageIncidentAlerts(incidentID string, alerts *IncidentAlertList) (*ListAlertsResponse, *http.Response, error) {
+	headers := make(map[string]string)
+
+	resp, err := c.put("/incidents/"+incidentID+"/alerts/", alerts, &headers)
+	if err != nil {
+		return nil, nil, err
+	}
+	var result ListAlertsResponse
+	return &result, resp, c.decodeJSON(resp, &result)
+}
+
+/* TODO: Create Status Updates */


Test patch:
diff --git a/incident_test.go b/incident_test.go
index a4f6af3..3748c94 100644
--- a/incident_test.go
+++ b/incident_test.go
@@ -601,3 +601,71 @@ func TestIncident_ResponderRequest(t *testing.T) {
 	}
 	testEqual(t, want, res)
 }
+
+func TestIncident_GetAlert(t *testing.T) {
+	setup()
+	defer teardown()
+
+	mux.HandleFunc("/incidents/1/alerts/1", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "GET")
+		w.Write([]byte(`{"alert": {"id": "1"}}`))
+	})
+
+	var client = &Client{apiEndpoint: server.URL, authToken: "foo", HTTPClient: defaultHTTPClient}
+
+	incidentID := "1"
+	alertID := "1"
+	res, _, err := client.GetIncidentAlert(incidentID, alertID)
+
+	want := &IncidentAlertResponse{
+		IncidentAlert: &IncidentAlert{
+			APIObject: APIObject{
+				ID: "1",
+			},
+		},
+	}
+
+	if err != nil {
+		t.Fatal(err)
+	}
+	testEqual(t, want, res)
+}
+func TestIncident_ManageAlerts(t *testing.T) {
+	setup()
+	defer teardown()
+
+	mux.HandleFunc("/incidents/1/alerts/", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "PUT")
+		w.Write([]byte(`{"alerts": [{"id": "1"}]}`))
+	})
+
+	var client = &Client{apiEndpoint: server.URL, authToken: "foo", HTTPClient: defaultHTTPClient}
+
+	incidentID := "1"
+
+	input := &IncidentAlertList{
+		Alerts: []IncidentAlert{
+			{
+				APIObject: APIObject{
+					ID: "1",
+				},
+			},
+		},
+	}
+	res, _, err := client.ManageIncidentAlerts(incidentID, input)
+
+	want := &ListAlertsResponse{
+		Alerts: []IncidentAlert{
+			{
+				APIObject: APIObject{
+					ID: "1",
+				},
+			},
+		},
+	}
+
+	if err != nil {
+		t.Fatal(err)
+	}
+	testEqual(t, want, res)
+}