Skip to content

Commit

Permalink
Merge pull request #4 from incident-io/rob/add-actions-stream
Browse files Browse the repository at this point in the history
Add the actions stream and required model
  • Loading branch information
rliddler authored Oct 19, 2023
2 parents ef248d3 + 184aee3 commit a245a47
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
49 changes: 49 additions & 0 deletions model/action_v2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package model

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

type actionV2 struct{}

var ActionV2 actionV2

func (actionV2) Schema() Property {
return Property{
Types: []string{"object"},
Properties: map[string]Property{
"id": {
Types: []string{"string"},
},
"incident_id": {
Types: []string{"string"},
},
"status": {
Types: []string{"string"},
},
"description": {
Types: []string{"string"},
},
"assignee": Optional(UserV1.Schema()),
"completed_at": DateTime.Schema(),
"created_at": DateTime.Schema(),
"updated_at": DateTime.Schema(),
},
}
}

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

return map[string]any{
"id": input.Id,
"incident_id": input.IncidentId,
"status": input.Status,
"description": input.Description,
"assignee": assignee,
"completed_at": input.CompletedAt,
"created_at": input.CreatedAt,
"updated_at": input.UpdatedAt,
}
}
48 changes: 48 additions & 0 deletions tap/stream_actions.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(&StreamActions{})
}

type StreamActions struct {
}

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

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

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

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

return results, nil
}

0 comments on commit a245a47

Please sign in to comment.