Skip to content

Commit

Permalink
Merge pull request #5 from incident-io/rob/add-followups-stream
Browse files Browse the repository at this point in the history
Add the followups stream and required models
  • Loading branch information
rliddler authored Oct 19, 2023
2 parents ae5f45d + 5dc878b commit ef248d3
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 0 deletions.
40 changes: 40 additions & 0 deletions model/follow_up_priority_v2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package model

import "github.com/incident-io/singer-tap/client"

type followUpPriorityV2 struct{}

var FollowUpPriorityV2 followUpPriorityV2

func (followUpPriorityV2) Schema() Property {
return Property{
Types: []string{"object"},
Properties: map[string]Property{
"id": {
Types: []string{"string"},
},
"name": {
Types: []string{"string"},
},
"rank": {
Types: []string{"integer"},
},
"description": {
Types: []string{"string", "null"},
},
},
}
}

func (followUpPriorityV2) Serialize(input *client.FollowUpPriorityV2) map[string]any {
if input == nil {
return nil
}

return map[string]any{
"id": input.Id,
"name": input.Name,
"rank": input.Rank,
"description": input.Description,
}
}
62 changes: 62 additions & 0 deletions model/follow_up_v2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package model

import "github.com/incident-io/singer-tap/client"

type followUpV2 struct{}

var FollowUpV2 followUpV2

func (followUpV2) Schema() Property {
return Property{
Types: []string{"object"},
Properties: map[string]Property{
"assignee": Optional(UserV1.Schema()),
"id": {
Types: []string{"string"},
},
"incident_id": {
Types: []string{"string"},
},
"priority": Optional(FollowUpPriorityV2.Schema()),
"status": {
Types: []string{"string"},
},
"title": {
Types: []string{"string"},
},
"description": {
Types: []string{"string", "null"},
},
"external_issue_reference": Optional(ExternalIssueReferenceV2.Schema()),
"completed_at": DateTime.Schema(),
"created_at": DateTime.Schema(),
"updated_at": DateTime.Schema(),
},
}
}

func (followUpV2) Serialize(input client.FollowUpV2) map[string]any {
var external_issue_reference map[string]any
if input.ExternalIssueReference != nil {
external_issue_reference = ExternalIssueReferenceV2.Serialize(input.ExternalIssueReference)
}

var assignee map[string]any
if input.Assignee != nil {
assignee = UserV1.Serialize(*input.Assignee)
}

return map[string]any{
"assignee": assignee,
"id": input.Id,
"incident_id": input.IncidentId,
"priority": FollowUpPriorityV2.Serialize(input.Priority),
"status": input.Status,
"title": input.Title,
"description": input.Description,
"external_issue_reference": external_issue_reference,
"completed_at": input.CompletedAt,
"created_at": input.CreatedAt,
"updated_at": input.UpdatedAt,
}
}
48 changes: 48 additions & 0 deletions tap/stream_follow_ups.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package tap

import (
"context"

kitlog "github.com/go-kit/log"
"github.com/incident-io/singer-tap/client"
"github.com/incident-io/singer-tap/model"
"github.com/pkg/errors"
)

func init() {
register(&StreamFollowUps{})
}

type StreamFollowUps struct {
}

func (s *StreamFollowUps) Output() *Output {
return &Output{
Type: OutputTypeSchema,
Stream: "follow_ups",
Schema: &model.Schema{
HasAdditionalProperties: false,
Type: []string{"object"},
Properties: model.FollowUpV2.Schema().Properties,
},
KeyProperties: []string{"id"},
BookmarkProperties: []string{},
}
}

func (s *StreamFollowUps) GetRecords(ctx context.Context, logger kitlog.Logger, cl *client.ClientWithResponses) ([]map[string]any, error) {
var (
results = []map[string]any{}
)

response, err := cl.FollowUpsV2ListWithResponse(ctx, &client.FollowUpsV2ListParams{})
if err != nil {
return nil, errors.Wrap(err, "listing incidents for actions stream")
}

for _, element := range response.JSON200.FollowUps {
results = append(results, model.FollowUpV2.Serialize(element))
}

return results, nil
}

0 comments on commit ef248d3

Please sign in to comment.