Skip to content

Commit 5dc878b

Browse files
committed
Add the followups stream and required models
Another pretty straight forward one without pagination etc.
1 parent a39fc89 commit 5dc878b

File tree

3 files changed

+150
-0
lines changed

3 files changed

+150
-0
lines changed

model/follow_up_priority_v2.go

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package model
2+
3+
import "github.com/incident-io/singer-tap/client"
4+
5+
type followUpPriorityV2 struct{}
6+
7+
var FollowUpPriorityV2 followUpPriorityV2
8+
9+
func (followUpPriorityV2) Schema() Property {
10+
return Property{
11+
Types: []string{"object"},
12+
Properties: map[string]Property{
13+
"id": {
14+
Types: []string{"string"},
15+
},
16+
"name": {
17+
Types: []string{"string"},
18+
},
19+
"rank": {
20+
Types: []string{"integer"},
21+
},
22+
"description": {
23+
Types: []string{"string", "null"},
24+
},
25+
},
26+
}
27+
}
28+
29+
func (followUpPriorityV2) Serialize(input *client.FollowUpPriorityV2) map[string]any {
30+
if input == nil {
31+
return nil
32+
}
33+
34+
return map[string]any{
35+
"id": input.Id,
36+
"name": input.Name,
37+
"rank": input.Rank,
38+
"description": input.Description,
39+
}
40+
}

model/follow_up_v2.go

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

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

0 commit comments

Comments
 (0)