Skip to content

Commit 184aee3

Browse files
committed
Add the actions stream and required model
This one is pretty simple, no pagination and we just list all of them for an organisation. Nothing deprecated or odd in the fields either.
1 parent a39fc89 commit 184aee3

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

model/action_v2.go

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package model
2+
3+
import "github.com/incident-io/singer-tap/client"
4+
5+
type actionV2 struct{}
6+
7+
var ActionV2 actionV2
8+
9+
func (actionV2) Schema() Property {
10+
return Property{
11+
Types: []string{"object"},
12+
Properties: map[string]Property{
13+
"id": {
14+
Types: []string{"string"},
15+
},
16+
"incident_id": {
17+
Types: []string{"string"},
18+
},
19+
"status": {
20+
Types: []string{"string"},
21+
},
22+
"description": {
23+
Types: []string{"string"},
24+
},
25+
"assignee": Optional(UserV1.Schema()),
26+
"completed_at": DateTime.Schema(),
27+
"created_at": DateTime.Schema(),
28+
"updated_at": DateTime.Schema(),
29+
},
30+
}
31+
}
32+
33+
func (actionV2) Serialize(input client.ActionV2) map[string]any {
34+
var assignee map[string]any
35+
if input.Assignee != nil {
36+
assignee = UserV1.Serialize(*input.Assignee)
37+
}
38+
39+
return map[string]any{
40+
"id": input.Id,
41+
"incident_id": input.IncidentId,
42+
"status": input.Status,
43+
"description": input.Description,
44+
"assignee": assignee,
45+
"completed_at": input.CompletedAt,
46+
"created_at": input.CreatedAt,
47+
"updated_at": input.UpdatedAt,
48+
}
49+
}

tap/stream_actions.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(&StreamActions{})
14+
}
15+
16+
type StreamActions struct {
17+
}
18+
19+
func (s *StreamActions) Output() *Output {
20+
return &Output{
21+
Type: OutputTypeSchema,
22+
Stream: "actions",
23+
Schema: &model.Schema{
24+
HasAdditionalProperties: false,
25+
Type: []string{"object"},
26+
Properties: model.ActionV2.Schema().Properties,
27+
},
28+
KeyProperties: []string{"id"},
29+
BookmarkProperties: []string{},
30+
}
31+
}
32+
33+
func (s *StreamActions) 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.ActionsV2ListWithResponse(ctx, &client.ActionsV2ListParams{})
39+
if err != nil {
40+
return nil, errors.Wrap(err, "listing incidents for actions stream")
41+
}
42+
43+
for _, element := range response.JSON200.Actions {
44+
results = append(results, model.ActionV2.Serialize(element))
45+
}
46+
47+
return results, nil
48+
}

0 commit comments

Comments
 (0)