Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Db/gen remaining data structs #373

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
linters:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Temporarily added because go vet points out an issue with ServiceDocumentSource.
Right now it looks like:

# Embedded, both `IntegrationId` and `ServiceRepository` have a clashing `json:"id"` tag
type ServiceDocumentSource struct {
	IntegrationId     `graphql:"... on ApiDocIntegration"`
	ServiceRepository `graphql:"... on ServiceRepository"`
}

but it should look like

type ServiceDocumentSource struct {
	IntegrationId     IntegrationId     `graphql:"... on ApiDocIntegration"`
	ServiceRepository ServiceRepository `graphql:"... on ServiceRepository"`
}

disable:
- govet
18 changes: 18 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ tasks:
cmds:
- go generate
- gofumpt -w .
- task: schema_update
- task: gqlgen

schema_update:
desc: Get latest OpsLevel GraphQL API schema and make subschemas
dir: codegen
cmds:
- curl https://app.opslevel.com/public/schemas/schema.graphql > schema.graphql
- mkdir -p graph
- ./split_schema.sh

gqlgen:
desc: Experimental - gen code with gqlgen
dir: codegen
cmds:
- go run github.com/99designs/gqlgen generate
- ./gen_models_clean_up.sh
- cp ./graph/model/objects.go {{.ROOT_DIR}}

lint:
desc: Formatting and linting
Expand Down
28 changes: 3 additions & 25 deletions actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,6 @@ type CustomActionsId struct {
Id ID `graphql:"id"`
}

type CustomActionsWebhookAction struct {
Headers JSON `graphql:"headers" scalar:"true"`
HTTPMethod CustomActionsHttpMethodEnum `graphql:"httpMethod"`
WebhookURL string `graphql:"webhookUrl"`
}

type CustomActionsTriggerDefinition struct {
Action CustomActionsId `graphql:"action"`
Aliases []string `graphql:"aliases"`
Description string `graphql:"description"`
Filter FilterId `graphql:"filter"`
Id ID `graphql:"id"`
ManualInputsDefinition string `graphql:"manualInputsDefinition"`
Name string `graphql:"name"`
Owner TeamId `graphql:"owner"`
Published bool `graphql:"published"`
Timestamps Timestamps `graphql:"timestamps"`
AccessControl CustomActionsTriggerDefinitionAccessControlEnum `graphql:"accessControl"`
ResponseTemplate string `graphql:"responseTemplate"`
EntityType CustomActionsEntityTypeEnum `graphql:"entityType"`
}

func (c *CustomActionsTriggerDefinition) ExtendedTeamAccess(client *Client, variables *PayloadVariables) (*TeamConnection, error) {
var q struct {
Account struct {
Expand All @@ -52,7 +30,7 @@ func (c *CustomActionsTriggerDefinition) ExtendedTeamAccess(client *Client, vari
}

for q.Account.CustomActionsTriggerDefinition.ExtendedTeamAccess.PageInfo.HasNextPage {
(*variables)["after"] = q.Account.CustomActionsTriggerDefinition.ExtendedTeamAccess.PageInfo.End
(*variables)["after"] = q.Account.CustomActionsTriggerDefinition.ExtendedTeamAccess.PageInfo.EndCursor
resp, err := c.ExtendedTeamAccess(client, variables)
if err != nil {
return nil, err
Expand Down Expand Up @@ -119,7 +97,7 @@ func (client *Client) ListCustomActions(variables *PayloadVariables) (*CustomAct
return nil, err
}
for q.Account.Actions.PageInfo.HasNextPage {
(*variables)["after"] = q.Account.Actions.PageInfo.End
(*variables)["after"] = q.Account.Actions.PageInfo.EndCursor
resp, err := client.ListCustomActions(variables)
if err != nil {
return nil, err
Expand Down Expand Up @@ -206,7 +184,7 @@ func (client *Client) ListTriggerDefinitions(variables *PayloadVariables) (*Cust
return nil, err
}
for q.Account.Definitions.PageInfo.HasNextPage {
(*variables)["after"] = q.Account.Definitions.PageInfo.End
(*variables)["after"] = q.Account.Definitions.PageInfo.EndCursor
resp, err := client.ListTriggerDefinitions(variables)
if err != nil {
return nil, err
Expand Down
18 changes: 9 additions & 9 deletions actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var newID *ol.ID = ol.NewID("123456789")
func TestCreateWebhookAction(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation WebhookActionCreate($input:CustomActionsWebhookActionCreateInput!){customActionsWebhookActionCreate(input: $input){webhookAction{{ template "custom_actions_request" }},errors{message,path}}}`,
`mutation WebhookActionCreate($input:CustomActionsWebhookActionCreateInput!){customActionsWebhookActionCreate(input: $input){webhookAction{aliases,description,id,liquidTemplate,name,... on CustomActionsWebhookAction{aliases,description,headers,httpMethod,id,liquidTemplate,name,webhookUrl}},errors{message,path}}}`,
`{"input":{"headers":"{\"Content-Type\":\"application/json\"}","httpMethod":"POST",{{ template "liquid_template_rollback" }},"name":"Deploy Rollback","webhookUrl":"https://gitlab.com/api/v4/projects/1/trigger/pipeline"}}`,
`{"data": {"customActionsWebhookActionCreate": { "webhookAction": {{ template "custom_action1" }}, "errors": [] }}}`,
)
Expand All @@ -36,12 +36,12 @@ func TestCreateWebhookAction(t *testing.T) {
func TestListCustomActions(t *testing.T) {
// Arrange
testRequestOne := autopilot.NewTestRequest(
`query ExternalActionList($after:String!$first:Int!){account{customActionsExternalActions(after: $after, first: $first){nodes{aliases,id,description,liquidTemplate,name,... on CustomActionsWebhookAction{headers,httpMethod,webhookUrl}},{{ template "pagination_request" }},totalCount}}}`,
`query ExternalActionList($after:String!$first:Int!){account{customActionsExternalActions(after: $after, first: $first){nodes{aliases,description,id,liquidTemplate,name,... on CustomActionsWebhookAction{aliases,description,headers,httpMethod,id,liquidTemplate,name,webhookUrl}},pageInfo{endCursor,hasNextPage,hasPreviousPage,startCursor},totalCount}}}`,
`{{ template "pagination_initial_query_variables" }}`,
`{ "data": { "account": { "customActionsExternalActions": { "nodes": [ { {{ template "custom_action1_response" }} }, { {{ template "custom_action2_response" }} } ], {{ template "pagination_initial_pageInfo_response" }}, "totalCount": 2 }}}}`,
)
testRequestTwo := autopilot.NewTestRequest(
`query ExternalActionList($after:String!$first:Int!){account{customActionsExternalActions(after: $after, first: $first){nodes{aliases,id,description,liquidTemplate,name,... on CustomActionsWebhookAction{headers,httpMethod,webhookUrl}},{{ template "pagination_request" }},totalCount}}}`,
`query ExternalActionList($after:String!$first:Int!){account{customActionsExternalActions(after: $after, first: $first){nodes{aliases,description,id,liquidTemplate,name,... on CustomActionsWebhookAction{aliases,description,headers,httpMethod,id,liquidTemplate,name,webhookUrl}},pageInfo{endCursor,hasNextPage,hasPreviousPage,startCursor},totalCount}}}`,
`{{ template "pagination_second_query_variables" }}`,
`{ "data": { "account": { "customActionsExternalActions": { "nodes": [ { {{ template "custom_action3_response" }} } ], {{ template "pagination_second_pageInfo_response" }}, "totalCount": 1 }}}}`,
)
Expand All @@ -62,7 +62,7 @@ func TestListCustomActions(t *testing.T) {
func TestUpdateWebhookAction(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation WebhookActionUpdate($input:CustomActionsWebhookActionUpdateInput!){customActionsWebhookActionUpdate(input: $input){webhookAction{{ template "custom_actions_request" }},errors{message,path}}}`,
`mutation WebhookActionUpdate($input:CustomActionsWebhookActionUpdateInput!){customActionsWebhookActionUpdate(input: $input){webhookAction{aliases,description,id,liquidTemplate,name,... on CustomActionsWebhookAction{aliases,description,headers,httpMethod,id,liquidTemplate,name,webhookUrl}},errors{message,path}}}`,
`{"input":{"id": "123456789", "httpMethod":"PUT"}}`,
`{"data": {"customActionsWebhookActionUpdate": { "webhookAction": {{ template "custom_action1" }}, "errors": [] }}}`,
)
Expand All @@ -82,7 +82,7 @@ func TestUpdateWebhookAction(t *testing.T) {
func TestUpdateWebhookAction2(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation WebhookActionUpdate($input:CustomActionsWebhookActionUpdateInput!){customActionsWebhookActionUpdate(input: $input){webhookAction{{ template "custom_actions_request" }},errors{message,path}}}`,
`mutation WebhookActionUpdate($input:CustomActionsWebhookActionUpdateInput!){customActionsWebhookActionUpdate(input: $input){webhookAction{aliases,description,id,liquidTemplate,name,... on CustomActionsWebhookAction{aliases,description,headers,httpMethod,id,liquidTemplate,name,webhookUrl}},errors{message,path}}}`,
`{"input":{"id": "123456789","description":"","headers":"{\"Accept\":\"application/json\"}"}}`,
`{"data": {"customActionsWebhookActionUpdate": { "webhookAction": {{ template "custom_action1" }}, "errors": [] }}}`,
)
Expand Down Expand Up @@ -220,12 +220,12 @@ func TestGetTriggerDefinition(t *testing.T) {
func TestListTriggerDefinitions(t *testing.T) {
// Arrange
testRequestOne := autopilot.NewTestRequest(
`query TriggerDefinitionList($after:String!$first:Int!){account{customActionsTriggerDefinitions(after: $after, first: $first){nodes{action{aliases,id},aliases,description,filter{id,name},id,manualInputsDefinition,name,owner{alias,id},published,timestamps{createdAt,updatedAt},accessControl,responseTemplate,entityType},{{ template "pagination_request" }},totalCount}}}`,
`query TriggerDefinitionList($after:String!$first:Int!){account{customActionsTriggerDefinitions(after: $after, first: $first){nodes{accessControl,action{aliases,id},aliases,description,entityType,filter{id,name},id,manualInputsDefinition,name,owner{alias,id},published,responseTemplate,timestamps{createdAt,updatedAt}},pageInfo{endCursor,hasNextPage,hasPreviousPage,startCursor},totalCount}}}`,
`{{ template "pagination_initial_query_variables" }}`,
`{ "data": { "account": { "customActionsTriggerDefinitions": { "nodes": [ { {{ template "custom_action_trigger1_response" }} }, { {{ template "custom_action_trigger2_response" }} } ], {{ template "pagination_initial_pageInfo_response" }}, "totalCount": 2 }}}}`,
)
testRequestTwo := autopilot.NewTestRequest(
`query TriggerDefinitionList($after:String!$first:Int!){account{customActionsTriggerDefinitions(after: $after, first: $first){nodes{action{aliases,id},aliases,description,filter{id,name},id,manualInputsDefinition,name,owner{alias,id},published,timestamps{createdAt,updatedAt},accessControl,responseTemplate,entityType},{{ template "pagination_request" }},totalCount}}}`,
`query TriggerDefinitionList($after:String!$first:Int!){account{customActionsTriggerDefinitions(after: $after, first: $first){nodes{accessControl,action{aliases,id},aliases,description,entityType,filter{id,name},id,manualInputsDefinition,name,owner{alias,id},published,responseTemplate,timestamps{createdAt,updatedAt}},pageInfo{endCursor,hasNextPage,hasPreviousPage,startCursor},totalCount}}}`,
`{{ template "pagination_second_query_variables" }}`,
`{ "data": { "account": { "customActionsTriggerDefinitions": { "nodes": [ { {{ template "custom_action_trigger3_response" }} } ], {{ template "pagination_second_pageInfo_response" }}, "totalCount": 1 }}}}`,
)
Expand Down Expand Up @@ -346,12 +346,12 @@ func TestDeleteTriggerDefinition(t *testing.T) {
func TestListExtendedTeamAccess(t *testing.T) {
// Arrange
testRequestOne := autopilot.NewTestRequest(
`query ExtendedTeamAccessList($after:String!$first:Int!$input:IdentifierInput!){account{customActionsTriggerDefinition(input: $input){extendedTeamAccess(after: $after, first: $first){nodes{alias,id,aliases,managedAliases,contacts{address,displayName,id,type},htmlUrl,manager{id,email,htmlUrl,name,role},memberships{nodes{role,team{alias,id},user{id,email}},{{ template "pagination_request" }},totalCount},name,parentTeam{alias,id},responsibilities,tags{nodes{id,key,value},{{ template "pagination_request" }},totalCount}},{{ template "pagination_request" }},totalCount}}}}`,
`query ExtendedTeamAccessList($after:String!$first:Int!$input:IdentifierInput!){account{customActionsTriggerDefinition(input: $input){extendedTeamAccess(after: $after, first: $first){nodes{alias,id,aliases,managedAliases,contacts{address,displayName,displayType,externalId,id,isDefault,owner{... on Team{alias,id}},type},htmlUrl,manager{id,email,htmlUrl,name,role},memberships{nodes{role,team{alias,id},user{id,email}},pageInfo{endCursor,hasNextPage,hasPreviousPage,startCursor},totalCount},name,parentTeam{alias,id},responsibilities,tags{nodes{id,key,owner{... on Team{alias,id}},value},pageInfo{endCursor,hasNextPage,hasPreviousPage,startCursor},totalCount}},pageInfo{endCursor,hasNextPage,hasPreviousPage,startCursor},totalCount}}}}`,
`{{ template "extended_team_access_get_vars_1" }}`,
`{{ template "extended_team_access_response_1" }}`,
)
testRequestTwo := autopilot.NewTestRequest(
`query ExtendedTeamAccessList($after:String!$first:Int!$input:IdentifierInput!){account{customActionsTriggerDefinition(input: $input){extendedTeamAccess(after: $after, first: $first){nodes{alias,id,aliases,managedAliases,contacts{address,displayName,id,type},htmlUrl,manager{id,email,htmlUrl,name,role},memberships{nodes{role,team{alias,id},user{id,email}},{{ template "pagination_request" }},totalCount},name,parentTeam{alias,id},responsibilities,tags{nodes{id,key,value},{{ template "pagination_request" }},totalCount}},{{ template "pagination_request" }},totalCount}}}}`,
`query ExtendedTeamAccessList($after:String!$first:Int!$input:IdentifierInput!){account{customActionsTriggerDefinition(input: $input){extendedTeamAccess(after: $after, first: $first){nodes{alias,id,aliases,managedAliases,contacts{address,displayName,displayType,externalId,id,isDefault,owner{... on Team{alias,id}},type},htmlUrl,manager{id,email,htmlUrl,name,role},memberships{nodes{role,team{alias,id},user{id,email}},pageInfo{endCursor,hasNextPage,hasPreviousPage,startCursor},totalCount},name,parentTeam{alias,id},responsibilities,tags{nodes{id,key,owner{... on Team{alias,id}},value},pageInfo{endCursor,hasNextPage,hasPreviousPage,startCursor},totalCount}},pageInfo{endCursor,hasNextPage,hasPreviousPage,startCursor},totalCount}}}}`,
`{{ template "extended_team_access_get_vars_2" }}`,
`{{ template "extended_team_access_response_2" }}`,
)
Expand Down
17 changes: 0 additions & 17 deletions alert_source.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
package opslevel

type AlertSource struct {
Description string `graphql:"description"`
ExternalId string `graphql:"externalId"`
Id ID `graphql:"id"`
Integration IntegrationId `graphql:"integration"`
Name string `graphql:"name"`
Type AlertSourceTypeEnum `graphql:"type"`
Url string `graphql:"url"`
}

type AlertSourceService struct {
AlertSource AlertSource `graphql:"alertSource"`
Id ID `graphql:"id"`
Service ServiceId `graphql:"service"`
Status AlertSourceStatusTypeEnum `graphql:"status"`
}

type AlertSourceDeleteInput struct {
Id ID `json:"id"`
}
Expand Down
10 changes: 5 additions & 5 deletions cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ func TestCache(t *testing.T) {
`{"data":{"account":{ "lifecycles":[{{ template "lifecycle_1" }}] }}}`,
)
testRequestThree := autopilot.NewTestRequest(
`query TeamList($after:String!$first:Int!){account{teams(after: $after, first: $first){nodes{alias,id,aliases,managedAliases,contacts{address,displayName,id,type},htmlUrl,manager{id,email,htmlUrl,name,role},memberships{nodes{role,team{alias,id},user{id,email}},{{ template "pagination_request" }},totalCount},name,parentTeam{alias,id},responsibilities,tags{nodes{id,key,value},{{ template "pagination_request" }},totalCount}},{{ template "pagination_request" }},totalCount}}}`,
`query TeamList($after:String!$first:Int!){account{teams(after: $after, first: $first){nodes{alias,id,aliases,managedAliases,contacts{address,displayName,displayType,externalId,id,isDefault,owner{... on Team{alias,id}},type},htmlUrl,manager{id,email,htmlUrl,name,role},memberships{nodes{role,team{alias,id},user{id,email}},pageInfo{endCursor,hasNextPage,hasPreviousPage,startCursor},totalCount},name,parentTeam{alias,id},responsibilities,tags{nodes{id,key,owner{... on Team{alias,id}},value},pageInfo{endCursor,hasNextPage,hasPreviousPage,startCursor},totalCount}},pageInfo{endCursor,hasNextPage,hasPreviousPage,startCursor},totalCount}}}`,
`{ "after": "", "first": 100 }`,
`{"data":{"account":{ "teams":{ "nodes":[{{ template "team_1" }}] } }}}`,
)
testRequestFour := autopilot.NewTestRequest(
`query CategoryList($after:String!$first:Int!){account{rubric{categories(after: $after, first: $first){nodes{id,name},{{ template "pagination_request" }},totalCount}}}}`,
`query CategoryList($after:String!$first:Int!){account{rubric{categories(after: $after, first: $first){nodes{description,id,name},pageInfo{endCursor,hasNextPage,hasPreviousPage,startCursor},totalCount}}}}`,
`{ "after": "", "first": 100 }`,
`{"data":{"account":{"rubric":{ "categories":{ "nodes":[{{ template "category_1" }}] } }}}}`,
)
Expand All @@ -35,7 +35,7 @@ func TestCache(t *testing.T) {
`{"data":{"account":{"rubric":{ "levels":{ "nodes":[{{ template "level_1" }}] } }}}}`,
)
testRequestSix := autopilot.NewTestRequest(
`query FilterList($after:String!$first:Int!){account{filters(after: $after, first: $first){nodes{id,name,connective,htmlUrl,predicates{key,keyData,type,value,caseSensitive}},{{ template "pagination_request" }},totalCount}}}`,
`query FilterList($after:String!$first:Int!){account{filters(after: $after, first: $first){nodes{id,name,connective,htmlUrl,predicates{caseSensitive,key,keyData,type,value}},pageInfo{endCursor,hasNextPage,hasPreviousPage,startCursor},totalCount}}}`,
`{ "after": "", "first": 100 }`,
`{"data":{"account":{ "filters":{ "nodes":[{{ template "filter_1" }}] } }}}`,
)
Expand All @@ -45,12 +45,12 @@ func TestCache(t *testing.T) {
`{"data":{"account":{ "integrations":{ "nodes":[{{ template "integration_1" }}] } }}}`,
)
testRequestEight := autopilot.NewTestRequest(
`query RepositoryList($after:String!$first:Int!){account{repositories(after: $after, first: $first){hiddenCount,nodes{archivedAt,createdOn,defaultAlias,defaultBranch,description,forked,htmlUrl,id,languages{name,usage},lastOwnerChangedAt,name,organization,owner{alias,id},private,repoKey,services{edges{atRoot,node{id,aliases},paths{href,path},serviceRepositories{baseDirectory,displayName,id,repository{id,defaultAlias},service{id,aliases}}},{{ template "pagination_request" }},totalCount},tags{nodes{id,key,value},{{ template "pagination_request" }},totalCount},tier{alias,description,id,index,name},type,url,visible},organizationCount,ownedCount,{{ template "pagination_request" }},totalCount,visibleCount}}}`,
`query RepositoryList($after:String!$first:Int!){account{repositories(after: $after, first: $first){hiddenCount,nodes{services{edges{atRoot,node{id,aliases},paths{href,path},serviceRepositories{baseDirectory,displayName,id,repository{id,defaultAlias},service{id,aliases}}},pageInfo{endCursor,hasNextPage,hasPreviousPage,startCursor},totalCount},tags{nodes{id,key,owner{... on Team{alias,id}},value},pageInfo{endCursor,hasNextPage,hasPreviousPage,startCursor},totalCount},archivedAt,configErrors,createdOn,defaultAlias,defaultBranch,description,forked,htmlUrl,id,languages{name,usage},lastOwnerChangedAt,locked,name,organization,owner{alias,id},repoKey,tier{alias,description,id,index,name},type,url,visibility,visible},organizationCount,ownedCount,pageInfo{endCursor,hasNextPage,hasPreviousPage,startCursor},totalCount,visibleCount}}}`,
`{ "after": "", "first": 100 }`,
`{"data":{"account":{ "repositories":{ "hiddenCount": 0, "nodes":[{{ template "repository_1" }}] } }}}`,
)
testRequestNine := autopilot.NewTestRequest(
`query IntegrationList($after:String!$first:Int!){account{infrastructureResourceSchemas(after: $after, first: $first){nodes{type,schema},{{ template "pagination_request" }}}}}`,
`query IntegrationList($after:String!$first:Int!){account{infrastructureResourceSchemas(after: $after, first: $first){nodes{schema,type},{{ template "pagination_request" }}}}}`,
`{ "after": "", "first": 100 }`,
`{"data":{"account":{ "infrastructureResourceSchemas":{ "nodes":[ {{ template "infra_schema_1" }} ] }}}}`,
)
Expand Down
Loading
Loading