Repository: PagerDuty/go-pagerduty
Pull request #410 (2022-01-16 05:13:24)

Fix linter issues, update ResponsePlays API before v1.5.0 release


Patch:
diff --git a/incident.go b/incident.go
index 3fcd1e4..f11cc89 100644
--- a/incident.go
+++ b/incident.go
@@ -56,7 +56,7 @@ type Assignee struct {
 	Assignee APIObject `json:"assignee"`
 }
 
-// Occurrence
+// Occurrence is the data around whether this is a reocurring issue.
 type Occurrence struct {
 	Count     uint   `json:"count,omitempty"`
 	Frequency uint   `json:"frequency,omitempty"`
@@ -749,10 +749,10 @@ func (c *Client) ManageIncidentAlerts(ctx context.Context, incidentID, from stri
 
 // IncidentStatusUpdate is a status update for the specified incident.
 type IncidentStatusUpdate struct {
-	ID        string	`json:"id"`
-	Message   string	`json:"message"`
-	CreatedAt string	`json:"created_at"`
-	Sender    APIObject	`json:"sender"`
+	ID        string    `json:"id"`
+	Message   string    `json:"message"`
+	CreatedAt string    `json:"created_at"`
+	Sender    APIObject `json:"sender"`
 }
 
 // CreateIncidentStatusUpdate creates a new status update for the specified incident.
diff --git a/response_play.go b/response_play.go
index b46bacc..3214d6a 100644
--- a/response_play.go
+++ b/response_play.go
@@ -8,6 +8,9 @@ import (
 	"github.com/google/go-querystring/query"
 )
 
+// ResponsePlay represents the API object for a response object:
+//
+// https://developer.pagerduty.com/api-reference/b3A6Mjc0ODE2Ng-create-a-response-play
 type ResponsePlay struct {
 	ID                 string          `json:"id,omitempty"`
 	Type               string          `json:"type,omitempty"`
@@ -23,38 +26,42 @@ type ResponsePlay struct {
 	RespondersMessage  string          `json:"responders_message"`
 	Runnability        *string         `json:"runnability"`
 	ConferenceNumber   *string         `json:"conference_number"`
-	ConferenceUrl      *string         `json:"conference_url"`
+	ConferenceURL      *string         `json:"conference_url"`
 	ConferenceType     *string         `json:"conference_type"`
 }
 
+// ListResponsePlaysResponse represents the list of response plays.
 type ListResponsePlaysResponse struct {
 	ResponsePlays []ResponsePlay `json:"response_plays"`
 }
 
+// ListResponsePlaysOptions are the options for listing response plays.
 type ListResponsePlaysOptions struct {
-	FilterForManualRun bool   `url:"filter_for_manual_run,omitempty"`
-	Query              string `url:"query,omitempty"`
+	// FilterForManualRun limits results to show only response plays that can be
+	// invoked manually.
+	FilterForManualRun bool `url:"filter_for_manual_run,omitempty"`
+
+	Query string `url:"query,omitempty"`
 }
 
 // ListResponsePlays lists existing response plays.
-func (c *Client) ListResponsePlays(ctx context.Context, o ListResponsePlaysOptions) (ListResponsePlaysResponse, error) {
-	var result ListResponsePlaysResponse
-
+func (c *Client) ListResponsePlays(ctx context.Context, o ListResponsePlaysOptions) ([]ResponsePlay, error) {
 	v, err := query.Values(o)
 	if err != nil {
-		return result, err
+		return nil, err
 	}
 
 	resp, err := c.get(ctx, "/response_plays?"+v.Encode())
 	if err != nil {
-		return result, err
+		return nil, err
 	}
 
+	var result ListResponsePlaysResponse
 	if err = c.decodeJSON(resp, &result); err != nil {
-		return result, err
+		return nil, err
 	}
 
-	return result, nil
+	return result.ResponsePlays, nil
 }
 
 // CreateResponsePlay creates a new response play.


Test patch:
diff --git a/incident_test.go b/incident_test.go
index a6a42f3..02e17dd 100644
--- a/incident_test.go
+++ b/incident_test.go
@@ -948,7 +948,7 @@ func TestIncident_CreateIncidentStatusUpdate(t *testing.T) {
 	setup()
 	defer teardown()
 
-	wantId := "1"
+	wantID := "1"
 	wantFrom := "foo@bar.com"
 	wantMessage := "foo"
 
@@ -979,13 +979,13 @@ func TestIncident_CreateIncidentStatusUpdate(t *testing.T) {
 		_, _ = w.Write([]byte(`{"status_update": {"id": "1", "message": "foo", "sender": {"summary": "foo@bar.com", "type": "user_reference"}}}`))
 	})
 	client := defaultTestClient(server.URL, "foo")
-	res, err := client.CreateIncidentStatusUpdate(context.Background(), wantId, wantFrom, wantMessage)
+	res, err := client.CreateIncidentStatusUpdate(context.Background(), wantID, wantFrom, wantMessage)
 	want := IncidentStatusUpdate{
-		ID:      wantId,
+		ID:      wantID,
 		Message: wantMessage,
 		Sender: APIObject{
 			Summary: wantFrom,
-			Type: "user_reference",
+			Type:    "user_reference",
 		},
 	}
 
diff --git a/response_play_test.go b/response_play_test.go
index 1fc6e2c..f25e5ea 100644
--- a/response_play_test.go
+++ b/response_play_test.go
@@ -19,11 +19,9 @@ func TestResponsePlay_List(t *testing.T) {
 	client := defaultTestClient(server.URL, "foo")
 	res, err := client.ListResponsePlays(context.TODO(), ListResponsePlaysOptions{})
 
-	want := ListResponsePlaysResponse{
-		ResponsePlays: []ResponsePlay{
-			{
-				ID: "1",
-			},
+	want := []ResponsePlay{
+		{
+			ID: "1",
 		},
 	}
 
@@ -144,7 +142,6 @@ func TestResponsePlay_Run(t *testing.T) {
 
 	client := defaultTestClient(server.URL, "foo")
 	err := client.RunResponsePlay(context.TODO(), "foo@example.com", "1", "5")
-
 	if err != nil {
 		t.Fatal(err)
 	}