-
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.
Add definitions and types for incidents, users
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
Showing
22 changed files
with
779 additions
and
15 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,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, | ||
} | ||
} |
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,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) | ||
} |
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,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 | ||
} |
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,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) | ||
}), | ||
} | ||
} |
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,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) | ||
} |
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,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) | ||
}), | ||
} | ||
} |
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,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), | ||
} | ||
} |
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 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, | ||
} | ||
} |
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,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, | ||
} | ||
} |
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,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), | ||
} | ||
} |
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,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) | ||
} |
Oops, something went wrong.