From cb8001f21274406fd3c62803cef4088e17477984 Mon Sep 17 00:00:00 2001 From: Yousuf Ashparie Date: Mon, 14 Jan 2019 18:14:54 -0500 Subject: [PATCH 1/9] return http code with errors --- event.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/event.go b/event.go index e3519710..e162fd53 100644 --- a/event.go +++ b/event.go @@ -26,6 +26,7 @@ type EventResponse struct { Status string `json:"status"` Message string `json:"message"` IncidentKey string `json:"incident_key"` + HttpStatus int } // CreateEvent sends PagerDuty an event to trigger, acknowledge, or resolve a @@ -48,11 +49,11 @@ func CreateEventWithHTTPClient(e Event, client HTTPClient) (*EventResponse, erro req.Header.Set("Content-Type", "application/json") resp, err := client.Do(req) if err != nil { - return nil, err + return &EventResponse{HttpStatus: resp.StatusCode}, err } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - return nil, fmt.Errorf("HTTP Status Code: %d", resp.StatusCode) + return &EventResponse{HttpStatus: resp.StatusCode}, fmt.Errorf("HTTP Status Code: %d", resp.StatusCode) } var eventResponse EventResponse if err := json.NewDecoder(resp.Body).Decode(&eventResponse); err != nil { From 1ea50439c7c41c9a7c5898823a42ff80ec83b2d1 Mon Sep 17 00:00:00 2001 From: Tim Little Date: Mon, 23 Sep 2019 16:38:22 +0100 Subject: [PATCH 2/9] Add CRUD funcs for ContactMethods --- user.go | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/user.go b/user.go index 62e15579..6d08e7fd 100644 --- a/user.go +++ b/user.go @@ -66,7 +66,7 @@ type ListUsersOptions struct { Includes []string `url:"include,omitempty,brackets"` } -// ListContactMethodResponse is the data structure returned from calling the GetUserContactMethod API endpoint. +// ListContactMethodsResponse is the data structure returned from calling the GetUserContactMethod API endpoint. type ListContactMethodsResponse struct { APIListObject ContactMethods []ContactMethod `json:"contact_methods"` @@ -139,9 +139,9 @@ func getUserFromResponse(c *Client, resp *http.Response, err error) (*User, erro return &t, nil } -// ListUserContactMethod fetches contact methods of the existing user. -func (c *Client) ListUserContactMethods(userId string) (*ListContactMethodsResponse, error) { - resp, err := c.get("/users/" + userId + "/contact_methods") +// ListUserContactMethods fetches contact methods of the existing user. +func (c *Client) ListUserContactMethods(userID string) (*ListContactMethodsResponse, error) { + resp, err := c.get("/users/" + userID + "/contact_methods") if err != nil { return nil, err } @@ -149,9 +149,31 @@ func (c *Client) ListUserContactMethods(userId string) (*ListContactMethodsRespo return &result, c.decodeJSON(resp, &result) } -// GetContactMethod gets details about a contact method. -func (c *Client) GetUserContactMethod(userID, id string) (*ContactMethod, error) { - resp, err := c.get("/users/" + userID + "/contact_methods/" + id) +// GetUserContactMethod gets details about a contact method. +func (c *Client) GetUserContactMethod(userID, contactMethodID string) (*ContactMethod, error) { + resp, err := c.get("/users/" + userID + "/contact_methods/" + contactMethodID) + return getContactMethodFromResponse(c, resp, err) +} + +// DeleteUserContactMethod deletes a user. +func (c *Client) DeleteUserContactMethod(userID, contactMethodID string) error { + _, err := c.delete("/users/" + userID + "/contact_methods/" + contactMethodID) + return err +} + +// CreateUserContactMethod creates a new contact method for user. +func (c *Client) CreateUserContactMethod(userID string, cm ContactMethod) (*ContactMethod, error) { + data := make(map[string]ContactMethod) + data["contact_method"] = cm + resp, err := c.post("/users/"+userID+"/contact_methods", data, nil) + return getContactMethodFromResponse(c, resp, err) +} + +// UpdateUserContactMethod updates an existing user. +func (c *Client) UpdateUserContactMethod(userID string, cm ContactMethod) (*ContactMethod, error) { + v := make(map[string]ContactMethod) + v["contact_method"] = cm + resp, err := c.put("/users/"+userID+"/contact_methods/"+cm.ID, v, nil) return getContactMethodFromResponse(c, resp, err) } From 4f049ea79e5977a1d80564370fe0c812e87044d3 Mon Sep 17 00:00:00 2001 From: Edward Wilde Date: Sun, 20 Oct 2019 19:52:07 +0100 Subject: [PATCH 3/9] Adds oncall to escalation policy --- escalation_policy.go | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/escalation_policy.go b/escalation_policy.go index 74befc66..bf249db6 100644 --- a/escalation_policy.go +++ b/escalation_policy.go @@ -21,13 +21,22 @@ type EscalationRule struct { // EscalationPolicy is a collection of escalation rules. type EscalationPolicy struct { APIObject - Name string `json:"name,omitempty"` - EscalationRules []EscalationRule `json:"escalation_rules,omitempty"` - Services []APIObject `json:"services,omitempty"` - NumLoops uint `json:"num_loops,omitempty"` - Teams []APIReference `json:"teams"` - Description string `json:"description,omitempty"` - RepeatEnabled bool `json:"repeat_enabled,omitempty"` + Name string `json:"name,omitempty"` + EscalationRules []EscalationRule `json:"escalation_rules,omitempty"` + Services []APIObject `json:"services,omitempty"` + NumLoops uint `json:"num_loops,omitempty"` + Teams []APIReference `json:"teams"` + OnCall []EscalationPolicyOnCall `json:"on_call"` + Description string `json:"description,omitempty"` + RepeatEnabled bool `json:"repeat_enabled,omitempty"` +} + +// +type EscalationPolicyOnCall struct { + Level uint `json:"level"` + Start string `json:"start,omitempty"` + End string `json:"end,omitempty"` + User User `json:"user,omitempty"` } // ListEscalationPoliciesResponse is the data structure returned from calling the ListEscalationPolicies API endpoint. From df2103785a79da426f0ef985aa84188478fbcbbd Mon Sep 17 00:00:00 2001 From: Thomas O'Neill Date: Mon, 6 Jan 2020 11:41:19 -0500 Subject: [PATCH 4/9] Added AlertGrouping and AlertGroupingTimeout to Service --- service.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/service.go b/service.go index c30994e7..675077bb 100644 --- a/service.go +++ b/service.go @@ -72,6 +72,8 @@ type Service struct { SupportHours *SupportHours `json:"support_hours,omitempty"` ScheduledActions []ScheduledAction `json:"scheduled_actions,omitempty"` AlertCreation string `json:"alert_creation,omitempty"` + AlertGrouping string `json:"alert_grouping,omitempty"` + AlertGroupingTimeout *uint `json:"alert_grouping_timeout,omitempty"` } // ListServiceOptions is the data structure used when calling the ListServices API endpoint. From 76aaa2d87a1ed3761b59f8235a8865f18c11c41a Mon Sep 17 00:00:00 2001 From: Alexander Hellbom Date: Tue, 4 Feb 2020 20:01:24 +0100 Subject: [PATCH 5/9] Add support for extension schemas --- extension_schema.go | 70 ++++++++++++++++++++++++++++++++++++ extension_schema_test.go | 78 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+) create mode 100644 extension_schema.go create mode 100644 extension_schema_test.go diff --git a/extension_schema.go b/extension_schema.go new file mode 100644 index 00000000..eeee2dd0 --- /dev/null +++ b/extension_schema.go @@ -0,0 +1,70 @@ +package pagerduty + +import ( + "fmt" + "net/http" + + "github.com/google/go-querystring/query" +) + +type ExtensionSchema struct { + APIObject + IconURL string `json:"icon_url"` + LogoURL string `json:"logo_url"` + Label string `json:"label"` + Key string `json:"key"` + Description string `json:"description"` + GuideURL string `json:"guide_url"` + SendTypes []string `json:"send_types"` + URL string `json:"url"` +} + +type ListExtensionSchemaResponse struct { + APIListObject + ExtensionSchemas []ExtensionSchema `json:"extension_schemas"` +} + +type ListExtensionSchemaOptions struct { + APIListObject + Query string `url:"query,omitempty"` +} + +func (c *Client) ListExtensionSchemas(o ListExtensionSchemaOptions) (*ListExtensionSchemaResponse, error) { + v, err := query.Values(o) + if err != nil { + return nil, err + } + + resp, err := c.get("/extension_schemas?" + v.Encode()) + if err != nil { + return nil, err + } + + var result ListExtensionSchemaResponse + + return &result, c.decodeJSON(resp, &result) +} + +func (c *Client) GetExtensionSchema(id string) (*ExtensionSchema, error) { + resp, err := c.get("/extension_schemas/" + id) + return getExtensionSchemaFromResponse(c, resp, err) +} + +func getExtensionSchemaFromResponse(c *Client, resp *http.Response, err error) (*ExtensionSchema, error) { + if err != nil { + return nil, err + } + + var target map[string]ExtensionSchema + if dErr := c.decodeJSON(resp, &target); dErr != nil { + return nil, fmt.Errorf("Could not decode JSON response: %v", dErr) + } + + rootNode := "extension_schema" + t, nodeOK := target[rootNode] + if !nodeOK { + return nil, fmt.Errorf("JSON response does not have %s field", rootNode) + } + + return &t, nil +} diff --git a/extension_schema_test.go b/extension_schema_test.go new file mode 100644 index 00000000..8374f0de --- /dev/null +++ b/extension_schema_test.go @@ -0,0 +1,78 @@ +package pagerduty + +import ( + "net/http" + "testing" +) + +func TestExtensionSchema_List(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/extension_schemas", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + w.Write([]byte(`{"extension_schemas":[{"id":"1","summary":"foo","send_types":["trigger", "acknowledge", "resolve"]}]}`)) + + }) + + var listObj = APIListObject{Limit: 0, Offset: 0, More: false, Total: 0} + var client = &Client{apiEndpoint: server.URL, authToken: "foo", HTTPClient: defaultHTTPClient} + var opts = ListExtensionSchemaOptions{ + APIListObject: listObj, + Query: "foo", + } + + res, err := client.ListExtensionSchemas(opts) + + want := &ListExtensionSchemaResponse{ + APIListObject: listObj, + ExtensionSchemas: []ExtensionSchema{ + { + APIObject: APIObject{ + ID: "1", + Summary: "foo", + }, + SendTypes: []string{ + "trigger", + "acknowledge", + "resolve", + }, + }, + }, + } + + if err != nil { + t.Fatal(err) + } + testEqual(t, want, res) +} + +func TestExtensionSchema_Get(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/extension_schemas/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + w.Write([]byte(`{"extension_schema": {"name": "foo", "id": "1", "send_types": ["trigger", "acknowledge", "resolve"]}}`)) + }) + + var client = &Client{apiEndpoint: server.URL, authToken: "foo", HTTPClient: defaultHTTPClient} + + res, err := client.GetExtensionSchema("1") + + want := &ExtensionSchema{ + APIObject: APIObject{ + ID: "1", + }, + SendTypes: []string{ + "trigger", + "acknowledge", + "resolve", + }, + } + + if err != nil { + t.Fatal(err) + } + testEqual(t, want, res) +} From aa9a4ec6125f973f8b9d447ac44a5154cf233c4f Mon Sep 17 00:00:00 2001 From: Alexander Hellbom Date: Tue, 4 Feb 2020 20:01:32 +0100 Subject: [PATCH 6/9] Add support for extensions --- extension.go | 85 ++++++++++++++++++++++++++ extension_test.go | 150 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 235 insertions(+) create mode 100644 extension.go create mode 100644 extension_test.go diff --git a/extension.go b/extension.go new file mode 100644 index 00000000..3e6722b8 --- /dev/null +++ b/extension.go @@ -0,0 +1,85 @@ +package pagerduty + +import ( + "fmt" + "net/http" + + "github.com/google/go-querystring/query" +) + +type Extension struct { + APIObject + Name string `json:"name"` + EndpointURL string `json:"endpoint_url"` + ExtensionObjects []APIObject `json:"extension_objects"` + ExtensionSchema APIObject `json:"extension_schema"` + Config interface{} `json:"config"` +} + +type ListExtensionResponse struct { + APIListObject + Extensions []Extension `json:"extensions"` +} + +type ListExtensionOptions struct { + APIListObject + ExtensionObjectID string `url:"extension_object_id,omitempty"` + ExtensionSchemaID string `url:"extension_schema_id,omitempty"` + Query string `url:"query,omitempty"` +} + +func (c *Client) ListExtensions(o ListExtensionOptions) (*ListExtensionResponse, error) { + v, err := query.Values(o) + if err != nil { + return nil, err + } + + resp, err := c.get("/extensions?" + v.Encode()) + if err != nil { + return nil, err + } + + var result ListExtensionResponse + + return &result, c.decodeJSON(resp, &result) +} + +func (c *Client) CreateExtension(e *Extension) (*Extension, error) { + resp, err := c.post("/extensions", e, nil) + return getExtensionFromResponse(c, resp, err) +} + +func (c *Client) DeleteExtension(id string) error { + _, err := c.delete("/extensions/" + id) + return err +} + +func (c *Client) GetExtension(id string) (*Extension, error) { + resp, err := c.get("/extensions/" + id) + return getExtensionFromResponse(c, resp, err) +} + +func (c *Client) UpdateExtension(id string, e *Extension) (*Extension, error) { + resp, err := c.put("/extensions/"+id, e, nil) + return getExtensionFromResponse(c, resp, err) +} + +func getExtensionFromResponse(c *Client, resp *http.Response, err error) (*Extension, error) { + if err != nil { + return nil, err + } + + var target map[string]Extension + if dErr := c.decodeJSON(resp, &target); dErr != nil { + return nil, fmt.Errorf("Could not decode JSON response: %v", dErr) + } + + rootNode := "extension" + + t, nodeOK := target[rootNode] + if !nodeOK { + return nil, fmt.Errorf("JSON response does not have %s field", rootNode) + } + + return &t, nil +} diff --git a/extension_test.go b/extension_test.go new file mode 100644 index 00000000..f4ed438b --- /dev/null +++ b/extension_test.go @@ -0,0 +1,150 @@ +package pagerduty + +import ( + "net/http" + "testing" +) + +func TestExtension_List(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/extensions", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + w.Write([]byte(`{"extensions":[{"id":"1","summary":"foo","config": {"restrict": "any"}, "extension_objects":[{"id":"foo","summary":"foo"}]}]}`)) + + }) + + var listObj = APIListObject{Limit: 0, Offset: 0, More: false, Total: 0} + var client = &Client{apiEndpoint: server.URL, authToken: "foo", HTTPClient: defaultHTTPClient} + var opts = ListExtensionOptions{ + APIListObject: listObj, + Query: "foo", + } + + res, err := client.ListExtensions(opts) + + want := &ListExtensionResponse{ + APIListObject: listObj, + Extensions: []Extension{ + { + APIObject: APIObject{ + ID: "1", + Summary: "foo", + }, + Config: map[string]interface{}{ + "restrict": "any", + }, + ExtensionObjects: []APIObject{ + { + ID: "foo", + Summary: "foo", + }, + }, + }, + }, + } + + if err != nil { + t.Fatal(err) + } + testEqual(t, want, res) +} + +func TestExtension_Create(t *testing.T) { + setup() + defer teardown() + + input := &Extension{Name: "foo"} + + mux.HandleFunc("/extensions", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "POST") + w.Write([]byte(`{"extension": {"name": "foo", "id": "1"}}`)) + }) + + var client = &Client{apiEndpoint: server.URL, authToken: "foo", HTTPClient: defaultHTTPClient} + + res, err := client.CreateExtension(input) + + want := &Extension{ + Name: "foo", + APIObject: APIObject{ + ID: "1", + }, + } + + if err != nil { + t.Fatal(err) + } + testEqual(t, want, res) +} + +func TestExtension_Delete(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/extensions/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "DELETE") + w.WriteHeader(http.StatusNoContent) + }) + + var client = &Client{apiEndpoint: server.URL, authToken: "foo", HTTPClient: defaultHTTPClient} + + if err := client.DeleteExtension("1"); err != nil { + t.Fatal(err) + } +} + +func TestExtension_Get(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/extensions/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + w.Write([]byte(`{"extension": {"name": "foo", "id": "1"}}`)) + }) + + var client = &Client{apiEndpoint: server.URL, authToken: "foo", HTTPClient: defaultHTTPClient} + + res, err := client.GetExtension("1") + + want := &Extension{ + Name: "foo", + APIObject: APIObject{ + ID: "1", + }, + } + + if err != nil { + t.Fatal(err) + } + testEqual(t, want, res) +} + +func TestExtension_Update(t *testing.T) { + setup() + defer teardown() + + input := &Extension{Name: "foo"} + + mux.HandleFunc("/extensions/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "PUT") + w.Write([]byte(`{"extension": {"name": "foo", "id": "1"}}`)) + }) + + var client = &Client{apiEndpoint: server.URL, authToken: "foo", HTTPClient: defaultHTTPClient} + + res, err := client.UpdateExtension("1", input) + + want := &Extension{ + Name: "foo", + APIObject: APIObject{ + ID: "1", + }, + } + + if err != nil { + t.Fatal(err) + } + testEqual(t, want, res) +} From 3ab1bb0c723f2c3c01fc60af26b6a1e88ac5077f Mon Sep 17 00:00:00 2001 From: Scott McAllister Date: Tue, 4 Feb 2020 16:42:58 -0800 Subject: [PATCH 7/9] updating Changelog --- CHANGELOG.md | 98 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 94 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5936ccc3..fee79783 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,103 @@ -# Change Log +# Changelog + +## [1.1.0](https://github.com/PagerDuty/go-pagerduty/tree/1.1.0) (2020-02-03) + +[Full Changelog](https://github.com/PagerDuty/go-pagerduty/compare/1.0.4...1.1.0) + +**Closed issues:** + +- listOverrides result in JSON unmarshall failure [\#180](https://github.com/PagerDuty/go-pagerduty/issues/180) +- How to create incident via command pd? [\#171](https://github.com/PagerDuty/go-pagerduty/issues/171) +- Poorly documented, library code broken, please step it up. [\#170](https://github.com/PagerDuty/go-pagerduty/issues/170) +- failed to create an incident [\#165](https://github.com/PagerDuty/go-pagerduty/issues/165) +- I need create incident function, Can we release the latest master? [\#163](https://github.com/PagerDuty/go-pagerduty/issues/163) +- Update logrus imports to github.com/sirupsen/logrus [\#160](https://github.com/PagerDuty/go-pagerduty/issues/160) +- build error cannot find package [\#144](https://github.com/PagerDuty/go-pagerduty/issues/144) +- Missing ListIncidentAlerts [\#141](https://github.com/PagerDuty/go-pagerduty/issues/141) +- ListIncidentsOptions Example [\#139](https://github.com/PagerDuty/go-pagerduty/issues/139) +- Support for V2 Event Management in the CLI [\#136](https://github.com/PagerDuty/go-pagerduty/issues/136) +- Custom connection settings [\#110](https://github.com/PagerDuty/go-pagerduty/issues/110) +- Missing the "From" parameter in Create note on an incident function [\#107](https://github.com/PagerDuty/go-pagerduty/issues/107) +- Support V2 events [\#83](https://github.com/PagerDuty/go-pagerduty/issues/83) +- Support Event Transformer Code? [\#67](https://github.com/PagerDuty/go-pagerduty/issues/67) +- Fix help flag behavior [\#18](https://github.com/PagerDuty/go-pagerduty/issues/18) + +**Merged pull requests:** + +- Tests [\#190](https://github.com/PagerDuty/go-pagerduty/pull/190) ([stmcallister](https://github.com/stmcallister)) +- Modify ListOverrides and add ListOverridesResponse [\#185](https://github.com/PagerDuty/go-pagerduty/pull/185) ([dstevensio](https://github.com/dstevensio)) +- client: allow overriding the api endpoint [\#173](https://github.com/PagerDuty/go-pagerduty/pull/173) ([heimweh](https://github.com/heimweh)) +- Change makefiles and readme [\#172](https://github.com/PagerDuty/go-pagerduty/pull/172) ([dineshba](https://github.com/dineshba)) +- Use Go modules [\#168](https://github.com/PagerDuty/go-pagerduty/pull/168) ([nbutton23](https://github.com/nbutton23)) +- escalation\_policy: support clearing teams from an existing escalation policy [\#167](https://github.com/PagerDuty/go-pagerduty/pull/167) ([heimweh](https://github.com/heimweh)) +- Correct JSON payload format for CreateIncident call [\#166](https://github.com/PagerDuty/go-pagerduty/pull/166) ([joepurdy](https://github.com/joepurdy)) +- Use pointer to Priority so don't send an empty priority for incident [\#164](https://github.com/PagerDuty/go-pagerduty/pull/164) ([atomicules](https://github.com/atomicules)) +- Update README.md [\#158](https://github.com/PagerDuty/go-pagerduty/pull/158) ([jonhyman](https://github.com/jonhyman)) +- Fixed typo [\#155](https://github.com/PagerDuty/go-pagerduty/pull/155) ([uthark](https://github.com/uthark)) +- Support Links in V2Event [\#154](https://github.com/PagerDuty/go-pagerduty/pull/154) ([alindeman](https://github.com/alindeman)) +- Add supported fields to POST /incident request. [\#151](https://github.com/PagerDuty/go-pagerduty/pull/151) ([archydragon](https://github.com/archydragon)) +- Consolidated community contributions [\#150](https://github.com/PagerDuty/go-pagerduty/pull/150) ([dobs](https://github.com/dobs)) +- Incident alerts [\#143](https://github.com/PagerDuty/go-pagerduty/pull/143) ([soullivaneuh](https://github.com/soullivaneuh)) +- Incident alerts [\#142](https://github.com/PagerDuty/go-pagerduty/pull/142) ([soullivaneuh](https://github.com/soullivaneuh)) +- Remove useless else from README [\#140](https://github.com/PagerDuty/go-pagerduty/pull/140) ([soullivaneuh](https://github.com/soullivaneuh)) +- Add V2 Event Management to the CLI [\#138](https://github.com/PagerDuty/go-pagerduty/pull/138) ([philnielsen](https://github.com/philnielsen)) +- Fix incident struct to behave as API expects [\#137](https://github.com/PagerDuty/go-pagerduty/pull/137) ([DennyLoko](https://github.com/DennyLoko)) +- Add ListContactMethods and GetContactMethod [\#132](https://github.com/PagerDuty/go-pagerduty/pull/132) ([amencarini](https://github.com/amencarini)) +- Adding fields for incident id and priority [\#131](https://github.com/PagerDuty/go-pagerduty/pull/131) ([davidgibbons](https://github.com/davidgibbons)) +- Add src to cd $GOPATH instruction [\#130](https://github.com/PagerDuty/go-pagerduty/pull/130) ([ryanhall07](https://github.com/ryanhall07)) +- CreateIncident takes CreateIncidentOptions param [\#127](https://github.com/PagerDuty/go-pagerduty/pull/127) ([wdhnl](https://github.com/wdhnl)) +- update CreateMaintenanceWindow [\#126](https://github.com/PagerDuty/go-pagerduty/pull/126) ([wdhnl](https://github.com/wdhnl)) +- Add instructions for actually being able to install the CLI [\#123](https://github.com/PagerDuty/go-pagerduty/pull/123) ([whithajess](https://github.com/whithajess)) +- Create Incident, List Priorities, and headers in POST method support [\#122](https://github.com/PagerDuty/go-pagerduty/pull/122) ([ldelossa](https://github.com/ldelossa)) +- Allow package consumers to provide their own HTTP client [\#121](https://github.com/PagerDuty/go-pagerduty/pull/121) ([theckman](https://github.com/theckman)) +- Add MergeIncidents \(using Incident\) [\#114](https://github.com/PagerDuty/go-pagerduty/pull/114) ([atomicules](https://github.com/atomicules)) +- Updated incident.go to reflect current api documentation [\#113](https://github.com/PagerDuty/go-pagerduty/pull/113) ([averstappen](https://github.com/averstappen)) +- Try out CircleCI. [\#109](https://github.com/PagerDuty/go-pagerduty/pull/109) ([felicianotech](https://github.com/felicianotech)) +- Added From parameter to createNote function [\#108](https://github.com/PagerDuty/go-pagerduty/pull/108) ([Nnoromuche](https://github.com/Nnoromuche)) +- Get a list of alerts for a given incident id. [\#106](https://github.com/PagerDuty/go-pagerduty/pull/106) ([pushkar-engagio](https://github.com/pushkar-engagio)) +- Add oncall details [\#104](https://github.com/PagerDuty/go-pagerduty/pull/104) ([luqasn](https://github.com/luqasn)) +- Add support for v2 ManageEvent api call [\#103](https://github.com/PagerDuty/go-pagerduty/pull/103) ([luqasn](https://github.com/luqasn)) +- Reformatted Apache 2.0 license [\#99](https://github.com/PagerDuty/go-pagerduty/pull/99) ([joshdk](https://github.com/joshdk)) +- Add ability to list a user's contact methods [\#97](https://github.com/PagerDuty/go-pagerduty/pull/97) ([facundoagriel](https://github.com/facundoagriel)) +- Added json fields to structs [\#93](https://github.com/PagerDuty/go-pagerduty/pull/93) ([bradleyrobinson](https://github.com/bradleyrobinson)) +- Get user's contact methods [\#91](https://github.com/PagerDuty/go-pagerduty/pull/91) ([wvdeutekom](https://github.com/wvdeutekom)) +- Fix pagination for ListOnCalls [\#90](https://github.com/PagerDuty/go-pagerduty/pull/90) ([IainCole](https://github.com/IainCole)) +- Fixed spelling, entires-\>entries [\#78](https://github.com/PagerDuty/go-pagerduty/pull/78) ([lowesoftware](https://github.com/lowesoftware)) +- Updating incident.go [\#75](https://github.com/PagerDuty/go-pagerduty/pull/75) ([domudall](https://github.com/domudall)) +- Adding new fields to Vendor [\#74](https://github.com/PagerDuty/go-pagerduty/pull/74) ([domudall](https://github.com/domudall)) +- Vendor CLI [\#73](https://github.com/PagerDuty/go-pagerduty/pull/73) ([domudall](https://github.com/domudall)) +- Fixing structs within user.go [\#72](https://github.com/PagerDuty/go-pagerduty/pull/72) ([domudall](https://github.com/domudall)) + +## [1.0.4](https://github.com/PagerDuty/go-pagerduty/tree/1.0.4) (2018-05-28) + +[Full Changelog](https://github.com/PagerDuty/go-pagerduty/compare/1.0.3...1.0.4) + +## [1.0.3](https://github.com/PagerDuty/go-pagerduty/tree/1.0.3) (2018-05-28) + +[Full Changelog](https://github.com/PagerDuty/go-pagerduty/compare/1.0.2...1.0.3) + +## [1.0.2](https://github.com/PagerDuty/go-pagerduty/tree/1.0.2) (2018-05-28) + +[Full Changelog](https://github.com/PagerDuty/go-pagerduty/compare/1.0.1...1.0.2) + +**Merged pull requests:** + +- Add gorleaser to release [\#118](https://github.com/PagerDuty/go-pagerduty/pull/118) ([mattstratton](https://github.com/mattstratton)) + +## [1.0.1](https://github.com/PagerDuty/go-pagerduty/tree/1.0.1) (2018-05-28) + +[Full Changelog](https://github.com/PagerDuty/go-pagerduty/compare/1.0.0...1.0.1) ## [1.0.0](https://github.com/PagerDuty/go-pagerduty/tree/1.0.0) (2018-05-28) + +[Full Changelog](https://github.com/PagerDuty/go-pagerduty/compare/d080263da74613ba3ac237baaf09f5f169b00d72...1.0.0) + **Fixed bugs:** - Escalation Policy's repeat\_enabled Is Ignored [\#57](https://github.com/PagerDuty/go-pagerduty/issues/57) - Problems running freshly built pd utility [\#39](https://github.com/PagerDuty/go-pagerduty/issues/39) - Manage Incident gives error [\#32](https://github.com/PagerDuty/go-pagerduty/issues/32) -- Added missing slash to delete integration method url [\#59](https://github.com/PagerDuty/go-pagerduty/pull/59) ([jescochu](https://github.com/jescochu)) +- Added missing slash to delete integration method url [\#59](https://github.com/PagerDuty/go-pagerduty/pull/59) ([reybard](https://github.com/reybard)) **Closed issues:** @@ -25,7 +116,6 @@ **Merged pull requests:** -- Fix pagination for ListOnCalls [\#90](https://github.com/PagerDuty/go-pagerduty/pull/90) ([IainCole](https://github.com/IainCole)) - Revert "Fix inconsistency with some REST Options objects passed by reference …" [\#88](https://github.com/PagerDuty/go-pagerduty/pull/88) ([mimato](https://github.com/mimato)) - Adding travis config, fixup Makefile [\#87](https://github.com/PagerDuty/go-pagerduty/pull/87) ([mimato](https://github.com/mimato)) - Fixed invalid JSON descriptor for FirstTriggerLogEntry [\#86](https://github.com/PagerDuty/go-pagerduty/pull/86) ([mwisniewski0](https://github.com/mwisniewski0)) @@ -86,4 +176,4 @@ -\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)* \ No newline at end of file +\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)* From 234a90e3211a4945fe09b32e9f565b791bbab0fb Mon Sep 17 00:00:00 2001 From: Scott McAllister Date: Wed, 5 Feb 2020 11:30:09 -0800 Subject: [PATCH 8/9] adding tests to new user_contact_methods functions --- user.go | 2 +- user_test.go | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 76 insertions(+), 3 deletions(-) diff --git a/user.go b/user.go index 6d08e7fd..d7097f39 100644 --- a/user.go +++ b/user.go @@ -165,7 +165,7 @@ func (c *Client) DeleteUserContactMethod(userID, contactMethodID string) error { func (c *Client) CreateUserContactMethod(userID string, cm ContactMethod) (*ContactMethod, error) { data := make(map[string]ContactMethod) data["contact_method"] = cm - resp, err := c.post("/users/"+userID+"/contact_methods", data, nil) + resp, err := c.post("/users/"+userID+"/contact_methods/", data, nil) return getContactMethodFromResponse(c, resp, err) } diff --git a/user_test.go b/user_test.go index fb5454b4..0ef9f919 100644 --- a/user_test.go +++ b/user_test.go @@ -208,6 +208,79 @@ func TestUser_GetContactMethod(t *testing.T) { testEqual(t, want, res) } -// TODO: Create user ContactMethod +// Create user ContactMethod +func TestUser_CreateContactMethod(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/users/1/contact_methods/", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "POST") + w.Write([]byte(`{"contact_method": {"id": "1", "type": "email_contact_method"}}`)) + }) + + var client = &Client{apiEndpoint: server.URL, authToken: "foo", HTTPClient: defaultHTTPClient} + userID := "1" + contactMethod := ContactMethod{ + Type: "email_contact_method", + } + res, err := client.CreateUserContactMethod(userID, contactMethod) -// TODO: Delete User Contactmethod + want := &ContactMethod{ + ID: "1", + Type: "email_contact_method", + } + + if err != nil { + t.Fatal(err) + } + testEqual(t, want, res) +} + +// Delete User Contactmethod +func TestUser_DeleteContactMethod(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/users/1/contact_methods/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "DELETE") + }) + + var client = &Client{apiEndpoint: server.URL, authToken: "foo", HTTPClient: defaultHTTPClient} + userID := "1" + contactMethodID := "1" + + err := client.DeleteUserContactMethod(userID, contactMethodID) + + if err != nil { + t.Fatal(err) + } +} + +// Update User ContactMethod +func TestUser_UpdateContactMethod(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/users/1/contact_methods/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "PUT") + w.Write([]byte(`{"contact_method": {"id": "1", "type": "email_contact_method"}}`)) + }) + + var client = &Client{apiEndpoint: server.URL, authToken: "foo", HTTPClient: defaultHTTPClient} + userID := "1" + contactMethod := ContactMethod{ + ID: "1", + Type: "email_contact_method", + } + res, err := client.UpdateUserContactMethod(userID, contactMethod) + + want := &ContactMethod{ + ID: "1", + Type: "email_contact_method", + } + + if err != nil { + t.Fatal(err) + } + testEqual(t, want, res) +} From d03a7ea446f987cf44a29fe830b25133697c69d0 Mon Sep 17 00:00:00 2001 From: Scott McAllister Date: Wed, 5 Feb 2020 11:44:51 -0800 Subject: [PATCH 9/9] my bad. this was actually the consistant way --- user.go | 2 +- user_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/user.go b/user.go index d7097f39..6d08e7fd 100644 --- a/user.go +++ b/user.go @@ -165,7 +165,7 @@ func (c *Client) DeleteUserContactMethod(userID, contactMethodID string) error { func (c *Client) CreateUserContactMethod(userID string, cm ContactMethod) (*ContactMethod, error) { data := make(map[string]ContactMethod) data["contact_method"] = cm - resp, err := c.post("/users/"+userID+"/contact_methods/", data, nil) + resp, err := c.post("/users/"+userID+"/contact_methods", data, nil) return getContactMethodFromResponse(c, resp, err) } diff --git a/user_test.go b/user_test.go index 0ef9f919..fc5fe71a 100644 --- a/user_test.go +++ b/user_test.go @@ -213,7 +213,7 @@ func TestUser_CreateContactMethod(t *testing.T) { setup() defer teardown() - mux.HandleFunc("/users/1/contact_methods/", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/users/1/contact_methods", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "POST") w.Write([]byte(`{"contact_method": {"id": "1", "type": "email_contact_method"}}`)) })