From d16161bd2100806e77f995dd1501879b0270bc28 Mon Sep 17 00:00:00 2001 From: Kilian Date: Thu, 9 Apr 2020 09:06:31 +0100 Subject: [PATCH 1/4] Create go.yml --- .github/workflows/go.yml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/go.yml diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 00000000..b66c0d71 --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,34 @@ +name: Go + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + + build: + name: Build + runs-on: ubuntu-latest + steps: + + - name: Set up Go 1.13 + uses: actions/setup-go@v1 + with: + go-version: 1.13 + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + + - name: Get dependencies + run: | + go get -v -t -d ./... + if [ -f Gopkg.toml ]; then + curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh + dep ensure + fi + + - name: Build + run: go build -v . From cf724b8430ff6cf63b6fd4518d3a952f5969f787 Mon Sep 17 00:00:00 2001 From: Kilian Date: Thu, 9 Apr 2020 11:37:58 +0100 Subject: [PATCH 2/4] Adding List Incident Alerts Options --- incident.go | 16 ++++++++++++++-- incident_test.go | 8 +++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/incident.go b/incident.go index 75da7e66..2813dcf6 100644 --- a/incident.go +++ b/incident.go @@ -267,9 +267,21 @@ type ListAlertsResponse struct { Alerts []IncidentAlert `json:"alerts,omitempty"` } +// ListIncidentAlertsOptions is the structure used when passing parameters to the ListIncidentAlerts API endpoint. +type ListIncidentAlertsOptions struct { + APIListObject + Statuses []string `url:"statuses,omitempty,brackets"` + SortBy string `url:"sort_by,omitempty"` + Includes []string `url:"include,omitempty,brackets"` +} + // ListIncidentAlerts lists existing alerts for the specified incident. -func (c *Client) ListIncidentAlerts(id string) (*ListAlertsResponse, error) { - resp, err := c.get("/incidents/" + id + "/alerts") +func (c *Client) ListIncidentAlerts(id string, o ListIncidentAlertsOptions) (*ListAlertsResponse, error) { + v, err := query.Values(o) + if err != nil { + return nil, err + } + resp, err := c.get("/incidents/" + id + "/alerts?" + v.Encode()) if err != nil { return nil, err } diff --git a/incident_test.go b/incident_test.go index 4b206caf..67f58cce 100644 --- a/incident_test.go +++ b/incident_test.go @@ -184,7 +184,13 @@ func TestIncident_ListIncidentAlerts(t *testing.T) { var client = &Client{apiEndpoint: server.URL, authToken: "foo", HTTPClient: defaultHTTPClient} id := "1" - res, err := client.ListIncidentAlerts(id) + var alertOpts = ListIncidentAlertsOptions{ + APIListObject: listObj, + Includes: []string{}, + } + + + res, err := client.ListIncidentAlerts(id, alertOpts) want := &ListAlertsResponse{ APIListObject: listObj, From 6420bb57ac194677b709c67f1a5fc6c3521f19aa Mon Sep 17 00:00:00 2001 From: Kilian Date: Thu, 9 Apr 2020 11:42:58 +0100 Subject: [PATCH 3/4] remove github workflow --- .github/workflows/go.yml | 34 ---------------------------------- 1 file changed, 34 deletions(-) delete mode 100644 .github/workflows/go.yml diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml deleted file mode 100644 index b66c0d71..00000000 --- a/.github/workflows/go.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: Go - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - - build: - name: Build - runs-on: ubuntu-latest - steps: - - - name: Set up Go 1.13 - uses: actions/setup-go@v1 - with: - go-version: 1.13 - id: go - - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - - - name: Get dependencies - run: | - go get -v -t -d ./... - if [ -f Gopkg.toml ]; then - curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh - dep ensure - fi - - - name: Build - run: go build -v . From b2c3905d7384a87701a2e366b8be5e006b09aad1 Mon Sep 17 00:00:00 2001 From: Kilian Date: Tue, 28 Apr 2020 11:05:01 +0100 Subject: [PATCH 4/4] create ListIncidentAlertsWithOpts func to ensure backwards compatibility --- incident.go | 7 ++++++- incident_test.go | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/incident.go b/incident.go index 2813dcf6..5fc18c8e 100644 --- a/incident.go +++ b/incident.go @@ -276,7 +276,12 @@ type ListIncidentAlertsOptions struct { } // ListIncidentAlerts lists existing alerts for the specified incident. -func (c *Client) ListIncidentAlerts(id string, o ListIncidentAlertsOptions) (*ListAlertsResponse, error) { +func (c *Client) ListIncidentAlerts(id string) (*ListAlertsResponse, error) { + return c.ListIncidentAlertsWithOpts(id, ListIncidentAlertsOptions{}) +} + +// ListIncidentAlertsWithOpts lists existing alerts for the specified incident. +func (c *Client) ListIncidentAlertsWithOpts(id string, o ListIncidentAlertsOptions) (*ListAlertsResponse, error) { v, err := query.Values(o) if err != nil { return nil, err diff --git a/incident_test.go b/incident_test.go index 67f58cce..b9182690 100644 --- a/incident_test.go +++ b/incident_test.go @@ -184,13 +184,43 @@ func TestIncident_ListIncidentAlerts(t *testing.T) { var client = &Client{apiEndpoint: server.URL, authToken: "foo", HTTPClient: defaultHTTPClient} id := "1" + res, err := client.ListIncidentAlerts(id) + + want := &ListAlertsResponse{ + APIListObject: listObj, + Alerts: []IncidentAlert{ + { + APIObject: APIObject{ + ID: "1", + Summary: "foo", + }, + }, + }, + } + + if err != nil { + t.Fatal(err) + } + testEqual(t, want, res) +} +func TestIncident_ListIncidentAlertsWithOpts(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/incidents/1/alerts", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + w.Write([]byte(`{"alerts": [{"id": "1","summary":"foo"}]}`)) + }) + var listObj = APIListObject{Limit: 0, Offset: 0, More: false, Total: 0} + var client = &Client{apiEndpoint: server.URL, authToken: "foo", HTTPClient: defaultHTTPClient} + id := "1" + var alertOpts = ListIncidentAlertsOptions{ APIListObject: listObj, Includes: []string{}, } - - res, err := client.ListIncidentAlerts(id, alertOpts) + res, err := client.ListIncidentAlertsWithOpts(id, alertOpts) want := &ListAlertsResponse{ APIListObject: listObj,