-
Notifications
You must be signed in to change notification settings - Fork 244
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
Add mechanism to list more than 100 incidents #429
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package pagerduty | |
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/google/go-querystring/query" | ||
) | ||
|
@@ -163,6 +164,10 @@ func (c *Client) ListIncidents(o ListIncidentsOptions) (*ListIncidentsResponse, | |
return c.ListIncidentsWithContext(context.Background(), o) | ||
} | ||
|
||
func (c *Client) ListIncidentsPaginated(o ListIncidentsOptions) ([]Incident, error) { | ||
return c.ListIncidentsPaginatedWithContext(context.Background(), o) | ||
} | ||
|
||
// ListIncidentsWithContext lists existing incidents. | ||
func (c *Client) ListIncidentsWithContext(ctx context.Context, o ListIncidentsOptions) (*ListIncidentsResponse, error) { | ||
v, err := query.Values(o) | ||
|
@@ -183,6 +188,37 @@ func (c *Client) ListIncidentsWithContext(ctx context.Context, o ListIncidentsOp | |
return &result, nil | ||
} | ||
|
||
// ListIncidentsPaginated lists existing services processing paginated responses | ||
func (c *Client) ListIncidentsPaginatedWithContext(ctx context.Context, o ListIncidentsOptions) ([]Incident, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this method signature aligns with future plans of the project. The |
||
v, err := query.Values(o) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var incidents []Incident | ||
|
||
responseHandler := func(response *http.Response) (APIListObject, error) { | ||
var result ListIncidentsResponse | ||
if err := c.decodeJSON(response, &result); err != nil { | ||
return APIListObject{}, err | ||
} | ||
|
||
incidents = append(incidents, result.Incidents...) | ||
|
||
return APIListObject{ | ||
More: result.More, | ||
Offset: result.Offset, | ||
Limit: result.Limit, | ||
}, nil | ||
} | ||
|
||
if err := c.pagedGet(ctx, "/incidents?"+v.Encode(), responseHandler); err != nil { | ||
return nil, err | ||
} | ||
|
||
return incidents, nil | ||
} | ||
|
||
// createIncidentResponse is returned from the API when creating a response. | ||
type createIncidentResponse struct { | ||
Incident Incident `json:"incident"` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method should be removed, as we don't want to introduce new methods that don't accept a
context.Contex
.