-
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 #5 from incident-io/rob/add-followups-stream
Add the followups stream and required models
- Loading branch information
Showing
3 changed files
with
150 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,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, | ||
} | ||
} |
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,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, | ||
} | ||
} |
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(&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 | ||
} |