Skip to content
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

Support adding conference bridge when creating or managing incidents #391

Merged
merged 1 commit into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 28 additions & 19 deletions incident.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,15 @@ type ListIncidentsOptions struct {

// ConferenceBridge is a struct for the conference_bridge object on an incident
type ConferenceBridge struct {
// ConferenceNumber is the phone number of the conference call for the
// conference bridge. Phone numbers should be formatted like
// +1 415-555-1212,,,,1234#, where a comma (,) represents a one-second
// wait and pound (#) completes access code input.
ConferenceNumber string `json:"conference_number,omitempty"`
ConferenceURL string `json:"conference_url,omitempty"`

// ConferenceURL is the URL for the conference bridge. This could be a link
// to a video conference or Slack channel.
ConferenceURL string `json:"conference_url,omitempty"`
}

// ListIncidents lists existing incidents.
Expand Down Expand Up @@ -152,28 +159,30 @@ type createIncidentResponse struct {

// CreateIncidentOptions is the structure used when POSTing to the CreateIncident API endpoint.
type CreateIncidentOptions struct {
Type string `json:"type"`
Title string `json:"title"`
Service *APIReference `json:"service"`
Priority *APIReference `json:"priority"`
Urgency string `json:"urgency,omitempty"`
IncidentKey string `json:"incident_key,omitempty"`
Body *APIDetails `json:"body,omitempty"`
EscalationPolicy *APIReference `json:"escalation_policy,omitempty"`
Assignments []Assignee `json:"assignments,omitempty"`
Type string `json:"type"`
Title string `json:"title"`
Service *APIReference `json:"service"`
Priority *APIReference `json:"priority"`
Urgency string `json:"urgency,omitempty"`
IncidentKey string `json:"incident_key,omitempty"`
Body *APIDetails `json:"body,omitempty"`
EscalationPolicy *APIReference `json:"escalation_policy,omitempty"`
Assignments []Assignee `json:"assignments,omitempty"`
ConferenceBridge *ConferenceBridge `json:"conference_bridge,omitempty"`
}

// ManageIncidentsOptions is the structure used when PUTing updates to incidents to the ManageIncidents func
type ManageIncidentsOptions struct {
ID string `json:"id"`
Type string `json:"type"`
Status string `json:"status,omitempty"`
Title string `json:"title,omitempty"`
Priority *APIReference `json:"priority,omitempty"`
Assignments []Assignee `json:"assignments,omitempty"`
EscalationLevel uint `json:"escalation_level,omitempty"`
EscalationPolicy *APIReference `json:"escalation_policy,omitempty"`
Resolution string `json:"resolution,omitempty"`
ID string `json:"id"`
Type string `json:"type"`
Status string `json:"status,omitempty"`
Title string `json:"title,omitempty"`
Priority *APIReference `json:"priority,omitempty"`
Assignments []Assignee `json:"assignments,omitempty"`
EscalationLevel uint `json:"escalation_level,omitempty"`
EscalationPolicy *APIReference `json:"escalation_policy,omitempty"`
Resolution string `json:"resolution,omitempty"`
ConferenceBridge *ConferenceBridge `json:"conference_bridge,omitempty"`
}

// MergeIncidentsOptions is the structure used when merging incidents with MergeIncidents func
Expand Down
84 changes: 84 additions & 0 deletions incident_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,90 @@ func TestIncident_Manage_assignments(t *testing.T) {
testEqual(t, want, res)
}

func TestIncident_Manage_conference_bridge(t *testing.T) {
setup()
defer teardown()

wantFrom := "foo@bar.com"

mux.HandleFunc("/incidents", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")

if gotFrom := r.Header.Get("From"); gotFrom != wantFrom {
t.Errorf("From HTTP header = %q, want %q", gotFrom, wantFrom)
}

body, err := ioutil.ReadAll(r.Body)
if err != nil {
t.Fatal(err)
}

var data map[string][]ManageIncidentsOptions
testErrCheck(t, "json.Unmarshal()", "", json.Unmarshal(body, &data))

if len(data["incidents"]) == 0 {
t.Fatalf("no incidents, expect 1")
}

const (
wantNum = "42"
wantURL = "http://example.org/bridge"
)

inc := data["incidents"][0]

if inc.ConferenceBridge == nil {
t.Fatalf("inc.ConferenceBridge = <nil>")
}

if got := inc.ConferenceBridge.ConferenceNumber; got != wantNum {
t.Fatalf("inc.ConferenceBridge.ConferenceNumber = %q, want %q", got, wantNum)
}

if got := inc.ConferenceBridge.ConferenceURL; got != wantURL {
t.Fatalf("inc.ConferenceBridge.ConferenceNumber = %q, want %q", got, wantURL)
}

_, _ = w.Write([]byte(`{"incidents": [{"title": "foo", "id": "1","conference_bridge":{"conference_number":"42","conference_url":"http://example.org/bridge"}}]}`))
})

client := defaultTestClient(server.URL, "foo")

input := []ManageIncidentsOptions{
{
ID: "1",
Type: "incident",
ConferenceBridge: &ConferenceBridge{
ConferenceNumber: "42",
ConferenceURL: "http://example.org/bridge",
},
},
}

want := &ListIncidentsResponse{
APIListObject: APIListObject{Limit: 0, Offset: 0, More: false, Total: 0},
Incidents: []Incident{
{
APIObject: APIObject{
ID: "1",
},
Title: "foo",
ConferenceBridge: &ConferenceBridge{
ConferenceNumber: "42",
ConferenceURL: "http://example.org/bridge",
},
},
},
}

got, err := client.ManageIncidents(wantFrom, input)
if err != nil {
t.Fatal(err)
}

testEqual(t, want, got)
}

func TestIncident_Manage_esclation_level(t *testing.T) {
setup()
defer teardown()
Expand Down