Skip to content

Commit 0228609

Browse files
committed
Add the incident roles stream
This data appears on the incident already - but if you wanted to just query what roles you had you'd want that in a separate table potentially. It's tiny and easy so here it is.
1 parent a245a47 commit 0228609

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

model/incident_role_v2.go

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package model
2+
3+
import "github.com/incident-io/singer-tap/client"
4+
5+
type incidentRoleV2 struct{}
6+
7+
var IncidentRoleV2 incidentRoleV2
8+
9+
// Actually identical to V1 but hey
10+
func (incidentRoleV2) Schema() Property {
11+
return Property{
12+
Types: []string{"object"},
13+
Properties: map[string]Property{
14+
"id": {
15+
Types: []string{"string"},
16+
},
17+
"name": {
18+
Types: []string{"string"},
19+
},
20+
"description": {
21+
Types: []string{"string"},
22+
},
23+
"instructions": {
24+
Types: []string{"string"},
25+
},
26+
"required": {
27+
Types: []string{"boolean"},
28+
},
29+
"role_type": {
30+
Types: []string{"string"},
31+
},
32+
"short_form": {
33+
Types: []string{"string"},
34+
},
35+
"created_at": DateTime.Schema(),
36+
"updated_at": DateTime.Schema(),
37+
},
38+
}
39+
}
40+
41+
func (incidentRoleV2) Serialize(input client.IncidentRoleV2) map[string]any {
42+
// Just flat convert everything into a map[string]any
43+
return DumpToMap(input)
44+
}

tap/stream_incident_roles.go

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package tap
2+
3+
import (
4+
"context"
5+
6+
kitlog "github.com/go-kit/log"
7+
"github.com/incident-io/singer-tap/client"
8+
"github.com/incident-io/singer-tap/model"
9+
"github.com/pkg/errors"
10+
)
11+
12+
func init() {
13+
register(&StreamIncidentRoles{})
14+
}
15+
16+
type StreamIncidentRoles struct {
17+
}
18+
19+
func (s *StreamIncidentRoles) Output() *Output {
20+
return &Output{
21+
Type: OutputTypeSchema,
22+
Stream: "incident_roles",
23+
Schema: &model.Schema{
24+
HasAdditionalProperties: false,
25+
Type: []string{"object"},
26+
Properties: model.IncidentRoleV2.Schema().Properties,
27+
},
28+
KeyProperties: []string{"id"},
29+
BookmarkProperties: []string{},
30+
}
31+
}
32+
33+
func (s *StreamIncidentRoles) GetRecords(ctx context.Context, logger kitlog.Logger, cl *client.ClientWithResponses) ([]map[string]any, error) {
34+
var (
35+
results = []map[string]any{}
36+
)
37+
38+
response, err := cl.IncidentRolesV2ListWithResponse(ctx)
39+
if err != nil {
40+
return nil, errors.Wrap(err, "listing incidents for actions stream")
41+
}
42+
43+
for _, element := range response.JSON200.IncidentRoles {
44+
results = append(results, model.IncidentRoleV2.Serialize(element))
45+
}
46+
47+
return results, nil
48+
}

0 commit comments

Comments
 (0)