Skip to content

Commit

Permalink
Add definitions and types for incidents, users
Browse files Browse the repository at this point in the history
This is a bit of a slog PR adding a number of types each with a Schema
and Serialize method.

We want to control what we add to the schema, and what we then write
out. Some fields are deprecated (not a lot) and this gives us control.

This will currently export all incident fields for the incidents v2 API
and their nested structures.
  • Loading branch information
rliddler committed Oct 18, 2023
1 parent 413c5c4 commit 1ecfcb6
Show file tree
Hide file tree
Showing 22 changed files with 779 additions and 15 deletions.
34 changes: 34 additions & 0 deletions model/actor_v2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package model

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

type actorV2 struct{}

var ActorV2 actorV2

func (actorV2) Schema() Property {
return Property{
Types: []string{"object"},
Properties: map[string]Property{
"api_key": Optional(APIKey.Schema()),
"user": Optional(UserV1.Schema()),
},
}
}

func (actorV2) Serialize(input client.ActorV2) map[string]any {
var user map[string]any
if input.User != nil {
user = UserV1.Serialize(*input.User)
}

var apiKey map[string]any
if input.ApiKey != nil {
apiKey = APIKey.Serialize(*input.ApiKey)
}

return map[string]any{
"api_key": apiKey,
"user": user,
}
}
25 changes: 25 additions & 0 deletions model/api_key_v2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package model

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

type apiKeyV2 struct{}

var APIKey apiKeyV2

func (apiKeyV2) Schema() Property {
return Property{
Types: []string{"object"},
Properties: map[string]Property{
"id": {
Types: []string{"string"},
},
"name": {
Types: []string{"string"},
},
},
}
}

func (apiKeyV2) Serialize(input client.APIKeyV2) map[string]any {
return DumpToMap(input)
}
16 changes: 16 additions & 0 deletions model/base_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package model

type dateTime struct{}

var DateTime dateTime

func (dateTime) Schema() Property {
return Property{
Types: []string{"string"},
CustomFormat: "date-time",
}
}

func (dateTime) Serialize(input string) any {
return input
}
29 changes: 29 additions & 0 deletions model/custom_field_entry_v1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package model

import (
"github.com/incident-io/singer-tap/client"
"github.com/samber/lo"
)

type customFieldEntryV1 struct{}

var CustomFieldEntryV1 customFieldEntryV1

func (customFieldEntryV1) Schema() Property {
return Property{
Types: []string{"object"},
Properties: map[string]Property{
"custom_field": CustomFieldTypeInfoV1.Schema(),
"values": ArrayOf(CustomFieldValueV1.Schema()),
},
}
}

func (customFieldEntryV1) Serialize(input client.CustomFieldEntryV1) map[string]any {
return map[string]any{
"custom_field": CustomFieldTypeInfoV1.Serialize(input.CustomField),
"values": lo.Map(input.Values, func(value client.CustomFieldValueV1, _ int) map[string]any {
return CustomFieldValueV1.Serialize(value)
}),
}
}
35 changes: 35 additions & 0 deletions model/custom_field_option_v1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package model

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

type customFieldOptionV1 struct{}

var CustomFieldOptionV1 customFieldOptionV1

func (customFieldOptionV1) Schema() Property {
return Property{
Types: []string{"object"},
Properties: map[string]Property{
"id": {
Types: []string{"string"},
},
"custom_field_id": {
Types: []string{"string"},
},
"sort_key": {
Types: []string{"integer"},
},
"value": {
Types: []string{"string"},
},
},
}
}

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

return DumpToMap(input)
}
43 changes: 43 additions & 0 deletions model/custom_field_type_info_v1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package model

import (
"github.com/incident-io/singer-tap/client"
"github.com/samber/lo"
)

type customFieldTypeInfoV1 struct{}

var CustomFieldTypeInfoV1 customFieldTypeInfoV1

func (customFieldTypeInfoV1) Schema() Property {
return Property{
Types: []string{"object"},
Properties: map[string]Property{
"id": {
Types: []string{"string"},
},
"name": {
Types: []string{"string"},
},
"description": {
Types: []string{"string"},
},
"field_type": {
Types: []string{"string"},
},
"options": ArrayOf(CustomFieldOptionV1.Schema()),
},
}
}

func (customFieldTypeInfoV1) Serialize(input client.CustomFieldTypeInfoV1) map[string]any {
return map[string]any{
"id": input.Id,
"name": input.Name,
"description": input.Description,
"field_type": input.FieldType,
"options": lo.Map(input.Options, func(option client.CustomFieldOptionV1, _ int) map[string]any {
return CustomFieldOptionV1.Serialize(&option)
}),
}
}
36 changes: 36 additions & 0 deletions model/custom_field_value_v1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package model

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

type customFieldValueV1 struct{}

var CustomFieldValueV1 customFieldValueV1

func (customFieldValueV1) Schema() Property {
return Property{
Types: []string{"object"},
Properties: map[string]Property{
"value_link": {
Types: []string{"null", "string"},
},
"value_numeric": {
Types: []string{"null", "number"},
},
"value_text": {
Types: []string{"null", "string"},
},
"value_catalog_entry": Optional(EmbeddedCatalogEntryV1.Schema()),
"value_option": Optional(CustomFieldOptionV1.Schema()),
},
}
}

func (customFieldValueV1) Serialize(input client.CustomFieldValueV1) map[string]any {
return map[string]any{
"value_link": input.ValueLink,
"value_numeric": input.ValueNumeric,
"value_text": input.ValueText,
"value_catalog_entry": EmbeddedCatalogEntryV1.Serialize(input.ValueCatalogEntry),
"value_option": CustomFieldOptionV1.Serialize(input.ValueOption),
}
}
40 changes: 40 additions & 0 deletions model/embedded_catalog_entry_v1.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 embeddedCatalogEntryV1 struct{}

var EmbeddedCatalogEntryV1 embeddedCatalogEntryV1

func (embeddedCatalogEntryV1) Schema() Property {
return Property{
Types: []string{"object"},
Properties: map[string]Property{
"id": {
Types: []string{"string"},
},
"name": {
Types: []string{"string"},
},
"aliases": {
Types: []string{"array", "null"},
},
"external_id": {
Types: []string{"string", "null"},
},
},
}
}

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

return map[string]any{
"id": input.Id,
"name": input.Name,
"aliases": input.Aliases,
"external_id": input.ExternalId,
}
}
36 changes: 36 additions & 0 deletions model/external_issue_reference_v2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package model

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

type externalIssueReferenceV2 struct{}

var ExternalIssueReferenceV2 externalIssueReferenceV2

func (externalIssueReferenceV2) Schema() Property {
return Property{
Types: []string{"object", "null"},
Properties: map[string]Property{
"issue_name": {
Types: []string{"string"},
},
"issue_permalink": {
Types: []string{"string"},
},
"provider": {
Types: []string{"string"},
},
},
}
}

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

return map[string]any{
"issue_name": input.IssueName,
"issue_permalink": input.IssuePermalink,
"provider": input.Provider,
}
}
29 changes: 29 additions & 0 deletions model/incident_role_assignment_v1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package model

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

type incidentRoleAssignmentV1 struct{}

var IncidentRoleAssignmentV1 incidentRoleAssignmentV1

func (incidentRoleAssignmentV1) Schema() Property {
return Property{
Types: []string{"object"},
Properties: map[string]Property{
"assignee": Optional(UserV1.Schema()),
"role": IncidentRoleV1.Schema(),
},
}
}

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

return map[string]any{
"assignee": assignee,
"role": IncidentRoleV1.Serialize(input.Role),
}
}
43 changes: 43 additions & 0 deletions model/incident_role_v1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package model

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

type incidentRoleV1 struct{}

var IncidentRoleV1 incidentRoleV1

func (incidentRoleV1) Schema() Property {
return Property{
Types: []string{"object"},
Properties: map[string]Property{
"id": {
Types: []string{"string"},
},
"name": {
Types: []string{"string"},
},
"description": {
Types: []string{"string"},
},
"instructions": {
Types: []string{"string"},
},
"required": {
Types: []string{"boolean"},
},
"role_type": {
Types: []string{"string"},
},
"short_form": {
Types: []string{"string"},
},
"created_at": DateTime.Schema(),
"updated_at": DateTime.Schema(),
},
}
}

func (incidentRoleV1) Serialize(input client.IncidentRoleV1) map[string]any {
// Just flat convert everything into a map[string]any
return DumpToMap(input)
}
Loading

0 comments on commit 1ecfcb6

Please sign in to comment.