-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from incident-io/rob/add-actions-stream
Add the actions stream and required model
- Loading branch information
Showing
2 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |