Skip to content

Commit

Permalink
Merge pull request #194 from PagerDuty/prs-04feb2020
Browse files Browse the repository at this point in the history
Community Contributions -- 05 Feb 2020
  • Loading branch information
Scott McAllister authored Feb 5, 2020
2 parents 65bf90f + ed75df8 commit 48adf81
Show file tree
Hide file tree
Showing 10 changed files with 602 additions and 22 deletions.
98 changes: 94 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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:**

Expand All @@ -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))
Expand Down Expand Up @@ -86,4 +176,4 @@



\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
23 changes: 16 additions & 7 deletions escalation_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions event.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
85 changes: 85 additions & 0 deletions extension.go
Original file line number Diff line number Diff line change
@@ -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
}
70 changes: 70 additions & 0 deletions extension_schema.go
Original file line number Diff line number Diff line change
@@ -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
}
Loading

0 comments on commit 48adf81

Please sign in to comment.