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

Code Gen v2 #509

Merged
merged 10 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changes/unreleased/Feature-20250127-091051.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Feature
body: '''metadata'' field has been added to AlertSource struct'
time: 2025-01-27T09:10:51.188114-06:00
3 changes: 3 additions & 0 deletions .changes/unreleased/Feature-20250127-091116.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Feature
body: '''description'' field has been added to Category struct'
time: 2025-01-27T09:11:16.749514-06:00
4 changes: 4 additions & 0 deletions .changes/unreleased/Feature-20250127-100537.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
kind: Feature
body: Struct 'Scorecard' has been updated to match all the fields possible in the
API
time: 2025-01-27T10:05:37.765025-06:00
3 changes: 3 additions & 0 deletions .changes/unreleased/Refactor-20250127-084043.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Refactor
body: 'BREAKING CHANGE: ''OpsLevelErrors'' has been renamed to ''Error'''
time: 2025-01-27T08:40:43.269477-06:00
4 changes: 4 additions & 0 deletions .changes/unreleased/Refactor-20250127-084159.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
kind: Refactor
body: 'BREAKING CHANGE: Struct ''GoogleCloudProject'' fields `ID` and `URL` are now
`Id` and `Url` respectively'
time: 2025-01-27T08:41:59.292959-06:00
4 changes: 4 additions & 0 deletions .changes/unreleased/Refactor-20250127-100442.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
kind: Refactor
body: Field 'ChecksCount' has been renamed to 'TotalChecks' on the struct 'Scorecard'
to match the API definition
time: 2025-01-27T10:04:42.935235-06:00
3 changes: 3 additions & 0 deletions .changes/unreleased/Refactor-20250127-102513.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Refactor
body: Field 'ID' on struct 'Secret' has been renamed to 'Id' for consistency
time: 2025-01-27T10:25:13.727106-06:00
3 changes: 3 additions & 0 deletions .changes/unreleased/Refactor-20250127-133514.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Refactor
body: 'BREAKING CHANGE: struct ''OpsLevelWarnings'' was renamed to ''Warning'''
time: 2025-01-27T13:35:14.183763-06:00
36 changes: 7 additions & 29 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 (customActionsTriggerDefinition *CustomActionsTriggerDefinition) ExtendedTeamAccess(client *Client, variables *PayloadVariables) (*TeamConnection, error) {
var q struct {
Account struct {
Expand Down Expand Up @@ -80,7 +58,7 @@ func (client *Client) CreateWebhookAction(input CustomActionsWebhookActionCreate
var m struct {
Payload struct {
WebhookAction CustomActionsExternalAction
Errors []OpsLevelErrors
Errors []Error
} `graphql:"customActionsWebhookActionCreate(input: $input)"`
}
v := PayloadVariables{
Expand All @@ -100,7 +78,7 @@ func (client *Client) GetCustomAction(input string) (*CustomActionsExternalActio
"input": *NewIdentifier(input),
}
err := client.Query(&q, v, WithName("ExternalActionGet"))
if q.Account.Action.Id == "" {
if q.Account.Action.CustomActionsId.Id == "" {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This needs to be investigated to see if we can fix this

err = fmt.Errorf("CustomActionsExternalAction with ID or Alias matching '%s' not found", input)
}
return &q.Account.Action, HandleErrors(err, nil)
Expand Down Expand Up @@ -134,7 +112,7 @@ func (client *Client) UpdateWebhookAction(input CustomActionsWebhookActionUpdate
var m struct {
Payload struct {
WebhookAction CustomActionsExternalAction
Errors []OpsLevelErrors
Errors []Error
} `graphql:"customActionsWebhookActionUpdate(input: $input)"`
}
v := PayloadVariables{
Expand All @@ -147,7 +125,7 @@ func (client *Client) UpdateWebhookAction(input CustomActionsWebhookActionUpdate
func (client *Client) DeleteWebhookAction(input string) error {
var m struct {
Payload struct {
Errors []OpsLevelErrors `graphql:"errors"`
Errors []Error `graphql:"errors"`
} `graphql:"customActionsWebhookActionDelete(resource: $input)"`
}
v := PayloadVariables{
Expand All @@ -161,7 +139,7 @@ func (client *Client) CreateTriggerDefinition(input CustomActionsTriggerDefiniti
var m struct {
Payload struct {
TriggerDefinition CustomActionsTriggerDefinition
Errors []OpsLevelErrors
Errors []Error
} `graphql:"customActionsTriggerDefinitionCreate(input: $input)"`
}
if input.AccessControl == nil {
Expand Down Expand Up @@ -222,7 +200,7 @@ func (client *Client) UpdateTriggerDefinition(input CustomActionsTriggerDefiniti
var m struct {
Payload struct {
TriggerDefinition CustomActionsTriggerDefinition
Errors []OpsLevelErrors
Errors []Error
} `graphql:"customActionsTriggerDefinitionUpdate(input: $input)"`
}
v := PayloadVariables{
Expand All @@ -235,7 +213,7 @@ func (client *Client) UpdateTriggerDefinition(input CustomActionsTriggerDefiniti
func (client *Client) DeleteTriggerDefinition(input string) error {
var m struct {
Payload struct {
Errors []OpsLevelErrors `graphql:"errors"`
Errors []Error `graphql:"errors"`
} `graphql:"customActionsTriggerDefinitionDelete(resource: $input)"`
}
v := PayloadVariables{
Expand Down
19 changes: 10 additions & 9 deletions actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,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{{ template "custom_actions_request" }},{{ template "pagination_request" }},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{{ template "custom_actions_request" }},{{ template "pagination_request" }},totalCount}}}`,
`{{ template "pagination_second_query_variables" }}`,
`{ "data": { "account": { "customActionsExternalActions": { "nodes": [ { {{ template "custom_action3_response" }} } ], {{ template "pagination_second_pageInfo_response" }}, "totalCount": 1 }}}}`,
)
Expand Down Expand Up @@ -224,12 +224,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{{ template "custom_actions_trigger_request" }},{{ template "pagination_request" }},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{{ template "custom_actions_trigger_request" }},{{ template "pagination_request" }},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 @@ -316,10 +316,11 @@ func TestUpdateTriggerDefinition3(t *testing.T) {

func TestDeleteTriggerDefinition(t *testing.T) {
// Arrange
request := `{"query":
"mutation TriggerDefinitionDelete($input:IdentifierInput!){customActionsTriggerDefinitionDelete(resource: $input){errors{message,path}}}",
{"input":{"alias":"123456789"}}
}`
request := autopilot.NewTestRequest(
`mutation TriggerDefinitionDelete($input:IdentifierInput!){customActionsTriggerDefinitionDelete(resource: $input){errors{message,path}}}`,
`{"input":{"alias":"123456789"}}`,
`{"data": {"customActionsTriggerDefinitionDelete": { "errors": [{{ template "error1" }}] }}}`,
)

testRequest := autopilot.NewTestRequest(
`mutation TriggerDefinitionDelete($input:IdentifierInput!){customActionsTriggerDefinitionDelete(resource: $input){errors{message,path}}}`,
Expand All @@ -334,7 +335,7 @@ func TestDeleteTriggerDefinition(t *testing.T) {

client := BestTestClient(t, "custom_actions/delete_trigger", testRequest)
clientErr := BestTestClient(t, "custom_actions/delete_trigger_err", testRequestError)
clientErr2 := ABetterTestClient(t, "custom_actions/delete_trigger_err2", request, "")
clientErr2 := BestTestClient(t, "custom_actions/delete_trigger_err2", request)
// Act
err := client.DeleteTriggerDefinition("123456789")
err2 := clientErr.DeleteTriggerDefinition("123456789")
Expand Down
21 changes: 2 additions & 19 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 All @@ -33,7 +16,7 @@ func (client *Client) CreateAlertSourceService(input AlertSourceServiceCreateInp
var m struct {
Payload struct {
AlertSourceService AlertSourceService
Errors []OpsLevelErrors
Errors []Error
} `graphql:"alertSourceServiceCreate(input: $input)"`
}
v := PayloadVariables{
Expand Down Expand Up @@ -74,7 +57,7 @@ func (client *Client) GetAlertSource(id ID) (*AlertSource, error) {
func (client *Client) DeleteAlertSourceService(id ID) error {
var m struct {
Payload struct {
Errors []OpsLevelErrors
Errors []Error
} `graphql:"alertSourceServiceDelete(input: $input)"`
}
v := PayloadVariables{
Expand Down
6 changes: 3 additions & 3 deletions alert_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func TestCreateAlertSourceService(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation AlertSourceServiceCreate($input:AlertSourceServiceCreateInput!){alertSourceServiceCreate(input: $input){alertSourceService{alertSource{description,externalId,id,integration{id,name,type},name,type,url},id,service{id,aliases},status},errors{message,path}}}`,
`mutation AlertSourceServiceCreate($input:AlertSourceServiceCreateInput!){alertSourceServiceCreate(input: $input){alertSourceService{alertSource{description,externalId,id,integration{id,name,type},metadata,name,type,url},id,service{id,aliases},status},errors{message,path}}}`,
`{"input": { "alertSourceExternalIdentifier": { "externalId": "QWERTY", "type": "datadog" }, "service": { "alias": "example" }}}`,
`{"data": { "alertSourceServiceCreate": { "alertSourceService": { "service": { "aliases": ["example"] }}}}}`,
)
Expand All @@ -28,7 +28,7 @@ func TestCreateAlertSourceService(t *testing.T) {
func TestGetAlertSourceWithExternalIdentifier(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`query AlertSourceGet($externalIdentifier:AlertSourceExternalIdentifier!){account{alertSource(externalIdentifier: $externalIdentifier){description,externalId,id,integration{id,name,type},name,type,url}}}`,
`query AlertSourceGet($externalIdentifier:AlertSourceExternalIdentifier!){account{alertSource(externalIdentifier: $externalIdentifier){description,externalId,id,integration{id,name,type},metadata,name,type,url}}}`,
`{"externalIdentifier": { "type": "datadog", "externalId": "12345678" }}`,
`{"data": {
"account": {
Expand Down Expand Up @@ -64,7 +64,7 @@ func TestGetAlertSourceWithExternalIdentifier(t *testing.T) {
func TestGetAlertSource(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`query AlertSourceGet($id:ID!){account{alertSource(id: $id){description,externalId,id,integration{id,name,type},name,type,url}}}`,
`query AlertSourceGet($id:ID!){account{alertSource(id: $id){description,externalId,id,integration{id,name,type},metadata,name,type,url}}}`,
`{"id": "Z2lkOi8vb3BzbGV2ZWwvQWxlcnRTb3VyY2VzOjpQYWdlcmR1dHkvNjE" }`,
`{"data": {
"account": {
Expand Down
4 changes: 2 additions & 2 deletions aliases.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (client *Client) CreateAlias(input AliasCreateInput) ([]string, error) {
Payload struct {
Aliases []string
OwnerId string
Errors []OpsLevelErrors
Errors []Error
} `graphql:"aliasCreate(input: $input)"`
}
v := PayloadVariables{
Expand Down Expand Up @@ -118,7 +118,7 @@ func (client *Client) DeleteAlias(input AliasDeleteInput) error {
var m struct {
Payload struct {
Alias string `graphql:"deletedAlias"`
Errors []OpsLevelErrors
Errors []Error
} `graphql:"aliasDelete(input: $input)"`
}
v := PayloadVariables{
Expand Down
6 changes: 3 additions & 3 deletions cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestCache(t *testing.T) {
`{"data":{"account":{ "lifecycles":[{{ template "lifecycle_1" }}] }}}`,
)
testRequestThree := autopilot.NewTestRequest(
`query SystemsList($after:String!$first:Int!){account{systems(after: $after, first: $first){nodes{id,aliases,managedAliases,name,description,htmlUrl,owner{... on Team{teamAlias:alias,id}},parent{id,aliases,description,htmlUrl,managedAliases,name,note,owner{... on Team{teamAlias:alias,id}}},note},{{ template "pagination_request" }}}}}`,
`query SystemsList($after:String!$first:Int!){account{systems(after: $after, first: $first){nodes{id,aliases,description,htmlUrl,managedAliases,name,note,owner{... on Team{teamAlias:alias,id}},parent{id,aliases,description,htmlUrl,managedAliases,name,note,owner{... on Team{teamAlias:alias,id}}}},{{ template "pagination_request" }}}}}`,
`{ "after": "", "first": 100 }`,
`{"data":{"account":{ "systems":{ "nodes":[{{ template "system1_response" }}] } }}}`,
)
Expand All @@ -30,7 +30,7 @@ func TestCache(t *testing.T) {
`{"data":{"account":{ "teams":{ "nodes":[{{ template "team_1" }}] } }}}`,
)
testRequestFive := 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},{{ template "pagination_request" }},totalCount}}}}`,
`{ "after": "", "first": 100 }`,
`{"data":{"account":{"rubric":{ "categories":{ "nodes":[{{ template "category_1" }}] } }}}}`,
)
Expand All @@ -40,7 +40,7 @@ func TestCache(t *testing.T) {
`{"data":{"account":{"rubric":{ "levels":{ "nodes":[{{ template "level_1" }}] } }}}}`,
)
testRequestSeven := 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}},{{ template "pagination_request" }},totalCount}}}`,
`{ "after": "", "first": 100 }`,
`{"data":{"account":{ "filters":{ "nodes":[{{ template "filter_1" }}] } }}}`,
)
Expand Down
11 changes: 3 additions & 8 deletions category.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ import (
"github.com/hasura/go-graphql-client"
)

type Category struct {
Id ID `json:"id"`
Name string
}

type CategoryConnection struct {
Nodes []Category
PageInfo PageInfo
Expand All @@ -26,7 +21,7 @@ func (client *Client) CreateCategory(input CategoryCreateInput) (*Category, erro
var m struct {
Payload struct {
Category Category
Errors []OpsLevelErrors
Errors []Error
} `graphql:"categoryCreate(input: $input)"`
}
v := PayloadVariables{
Expand Down Expand Up @@ -86,7 +81,7 @@ func (client *Client) UpdateCategory(input CategoryUpdateInput) (*Category, erro
var m struct {
Payload struct {
Category Category
Errors []OpsLevelErrors
Errors []Error
} `graphql:"categoryUpdate(input: $input)"`
}
v := PayloadVariables{
Expand All @@ -100,7 +95,7 @@ func (client *Client) DeleteCategory(id ID) error {
var m struct {
Payload struct {
Id ID `graphql:"deletedCategoryId"`
Errors []OpsLevelErrors
Errors []Error
} `graphql:"categoryDelete(input: $input)"`
}
v := PayloadVariables{
Expand Down
Loading
Loading