Skip to content

Commit

Permalink
Code improvements that will help with code gen (#350)
Browse files Browse the repository at this point in the history
  • Loading branch information
Taimoor Ahmad authored Jan 12, 2024
1 parent 2afd833 commit ba5d57f
Show file tree
Hide file tree
Showing 33 changed files with 280 additions and 258 deletions.
3 changes: 3 additions & 0 deletions .changes/unreleased/Feature-20240112-142046.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Feature
body: Add RefTo - alias for RefOf
time: 2024-01-12T14:20:46.773099-05:00
4 changes: 4 additions & 0 deletions .changes/unreleased/Refactor-20240109-202355.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
kind: Refactor
body: Combine DeleteService(ID) and DeleteServiceWithAlias(string) into a unified
function
time: 2024-01-09T20:23:55.747843-05:00
3 changes: 3 additions & 0 deletions .changes/unreleased/Refactor-20240109-202941.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Refactor
body: DeleteScorecard() now returns a pointer like other Delete functions
time: 2024-01-09T20:29:41.335381-05:00
3 changes: 3 additions & 0 deletions .changes/unreleased/Refactor-20240109-205045.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Refactor
body: List() functions consistently return a (*Connection, error)
time: 2024-01-09T20:50:45.694558-05:00
3 changes: 3 additions & 0 deletions .changes/unreleased/Refactor-20240109-214205.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Refactor
body: Merge DeleteTeam(ID) and DeleteTeamWithAlias(string) into DeleteTeam(identifier string)
time: 2024-01-09T21:42:05.208198-05:00
3 changes: 3 additions & 0 deletions .changes/unreleased/Refactor-20240110-142526.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Refactor
body: NewIdentifierInput() now returns a pointer to be consistent with NewIdentifier()
time: 2024-01-10T14:25:26.514448-05:00
3 changes: 3 additions & 0 deletions .changes/unreleased/Refactor-20240112-141014.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Refactor
body: JSON functions now return (ptr, error) instead of panic()-ing
time: 2024-01-12T14:10:14.452468-05:00
16 changes: 8 additions & 8 deletions actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (client *Client) GetCustomAction(input string) (*CustomActionsExternalActio
return &q.Account.Action, HandleErrors(err, nil)
}

func (client *Client) ListCustomActions(variables *PayloadVariables) (CustomActionsExternalActionsConnection, error) {
func (client *Client) ListCustomActions(variables *PayloadVariables) (*CustomActionsExternalActionsConnection, error) {
var q struct {
Account struct {
Actions CustomActionsExternalActionsConnection `graphql:"customActionsExternalActions(after: $after, first: $first)"`
Expand All @@ -126,18 +126,18 @@ func (client *Client) ListCustomActions(variables *PayloadVariables) (CustomActi
variables = client.InitialPageVariablesPointer()
}
if err := client.Query(&q, *variables, WithName("ExternalActionList")); err != nil {
return CustomActionsExternalActionsConnection{}, err
return nil, err
}
for q.Account.Actions.PageInfo.HasNextPage {
(*variables)["after"] = q.Account.Actions.PageInfo.End
resp, err := client.ListCustomActions(variables)
if err != nil {
return CustomActionsExternalActionsConnection{}, err
return nil, err
}
q.Account.Actions.Nodes = append(q.Account.Actions.Nodes, resp.Nodes...)
q.Account.Actions.PageInfo = resp.PageInfo
}
return q.Account.Actions, nil
return &q.Account.Actions, nil
}

func (client *Client) UpdateWebhookAction(input CustomActionsWebhookActionUpdateInput) (*CustomActionsExternalAction, error) {
Expand Down Expand Up @@ -203,7 +203,7 @@ func (client *Client) GetTriggerDefinition(input string) (*CustomActionsTriggerD
return &q.Account.Definition, HandleErrors(err, nil)
}

func (client *Client) ListTriggerDefinitions(variables *PayloadVariables) (CustomActionsTriggerDefinitionsConnection, error) {
func (client *Client) ListTriggerDefinitions(variables *PayloadVariables) (*CustomActionsTriggerDefinitionsConnection, error) {
var q struct {
Account struct {
Definitions CustomActionsTriggerDefinitionsConnection `graphql:"customActionsTriggerDefinitions(after: $after, first: $first)"`
Expand All @@ -213,19 +213,19 @@ func (client *Client) ListTriggerDefinitions(variables *PayloadVariables) (Custo
variables = client.InitialPageVariablesPointer()
}
if err := client.Query(&q, *variables, WithName("TriggerDefinitionList")); err != nil {
return CustomActionsTriggerDefinitionsConnection{}, err
return nil, err
}
for q.Account.Definitions.PageInfo.HasNextPage {
(*variables)["after"] = q.Account.Definitions.PageInfo.End
resp, err := client.ListTriggerDefinitions(variables)
if err != nil {
return CustomActionsTriggerDefinitionsConnection{}, err
return nil, err
}
q.Account.Definitions.Nodes = append(q.Account.Definitions.Nodes, resp.Nodes...)
q.Account.Definitions.PageInfo = resp.PageInfo
q.Account.Definitions.TotalCount += resp.TotalCount
}
return q.Account.Definitions, nil
return &q.Account.Definitions, nil
}

func (client *Client) UpdateTriggerDefinition(input CustomActionsTriggerDefinitionUpdateInput) (*CustomActionsTriggerDefinition, error) {
Expand Down
4 changes: 2 additions & 2 deletions category.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ func (client *Client) ListCategories(variables *PayloadVariables) (*CategoryConn
variables = client.InitialPageVariablesPointer()
}
if err := client.Query(&q, *variables, WithName("CategoryList")); err != nil {
return &CategoryConnection{}, err
return nil, err
}
for q.Account.Rubric.Categories.PageInfo.HasNextPage {
(*variables)["after"] = q.Account.Rubric.Categories.PageInfo.End
resp, err := client.ListCategories(variables)
if err != nil {
return &CategoryConnection{}, err
return nil, err
}
q.Account.Rubric.Categories.Nodes = append(q.Account.Rubric.Categories.Nodes, resp.Nodes...)
q.Account.Rubric.Categories.PageInfo = resp.PageInfo
Expand Down
8 changes: 4 additions & 4 deletions check.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func (client *Client) GetCheck(id ID) (*Check, error) {
return &q.Account.Check, HandleErrors(err, nil)
}

func (client *Client) ListChecks(variables *PayloadVariables) (CheckConnection, error) {
func (client *Client) ListChecks(variables *PayloadVariables) (*CheckConnection, error) {
var q struct {
Account struct {
Rubric struct {
Expand All @@ -243,19 +243,19 @@ func (client *Client) ListChecks(variables *PayloadVariables) (CheckConnection,
variables = client.InitialPageVariablesPointer()
}
if err := client.Query(&q, *variables, WithName("CheckList")); err != nil {
return CheckConnection{}, err
return nil, err
}
for q.Account.Rubric.Checks.PageInfo.HasNextPage {
(*variables)["after"] = q.Account.Rubric.Checks.PageInfo.End
resp, err := client.ListChecks(variables)
if err != nil {
return CheckConnection{}, err
return nil, err
}
q.Account.Rubric.Checks.Nodes = append(q.Account.Rubric.Checks.Nodes, resp.Nodes...)
q.Account.Rubric.Checks.PageInfo = resp.PageInfo
q.Account.Rubric.Checks.TotalCount += resp.TotalCount
}
return q.Account.Rubric.Checks, nil
return &q.Account.Rubric.Checks, nil
}

//#endregion
Expand Down
4 changes: 4 additions & 0 deletions common.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ func RefOf[T any](v T) *T {
return &v
}

func RefTo[T any](v T) *T {
return &v
}

func HandleErrors(err error, errs []OpsLevelErrors) error {
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ func (c *Client) ListDomains(variables *PayloadVariables) (*DomainConnection, er
variables = c.InitialPageVariablesPointer()
}
if err := c.Query(&q, *variables, WithName("DomainsList")); err != nil {
return &DomainConnection{}, err
return nil, err
}
for q.Account.Domains.PageInfo.HasNextPage {
(*variables)["after"] = q.Account.Domains.PageInfo.End
resp, err := c.ListDomains(variables)
if err != nil {
return &DomainConnection{}, err
return nil, err
}
q.Account.Domains.Nodes = append(q.Account.Domains.Nodes, resp.Nodes...)
q.Account.Domains.PageInfo = resp.PageInfo
Expand Down
8 changes: 4 additions & 4 deletions filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (client *Client) GetFilter(id ID) (*Filter, error) {
return &q.Account.Filter, HandleErrors(err, nil)
}

func (client *Client) ListFilters(variables *PayloadVariables) (FilterConnection, error) {
func (client *Client) ListFilters(variables *PayloadVariables) (*FilterConnection, error) {
var q struct {
Account struct {
Filters FilterConnection `graphql:"filters(after: $after, first: $first)"`
Expand All @@ -87,19 +87,19 @@ func (client *Client) ListFilters(variables *PayloadVariables) (FilterConnection
variables = client.InitialPageVariablesPointer()
}
if err := client.Query(&q, *variables, WithName("FilterList")); err != nil {
return FilterConnection{}, err
return nil, err
}
for q.Account.Filters.PageInfo.HasNextPage {
(*variables)["after"] = q.Account.Filters.PageInfo.End
resp, err := client.ListFilters(variables)
if err != nil {
return FilterConnection{}, err
return nil, err
}
q.Account.Filters.Nodes = append(q.Account.Filters.Nodes, resp.Nodes...)
q.Account.Filters.PageInfo = resp.PageInfo
q.Account.Filters.TotalCount += resp.TotalCount
}
return q.Account.Filters, nil
return &q.Account.Filters, nil
}

//#endregion
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ go 1.21

require (
github.com/Masterminds/sprig/v3 v3.2.3
github.com/creasty/defaults v1.7.0
github.com/go-playground/validator/v10 v10.16.0
github.com/go-resty/resty/v2 v2.11.0
github.com/gosimple/slug v1.13.1
github.com/hashicorp/go-retryablehttp v0.7.5
github.com/hasura/go-graphql-client v0.10.2
github.com/opslevel/moredefaults v0.0.0-20240112142637-078c8ff8ba9c
github.com/relvacode/iso8601 v1.3.0
github.com/rocktavious/autopilot/v2023 v2023.12.7
github.com/rs/zerolog v1.31.0
gopkg.in/yaml.v3 v3.0.1
)

require (
Expand Down
5 changes: 2 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYr
github.com/Masterminds/sprig/v3 v3.2.3 h1:eL2fZNezLomi0uOLqjQoN6BfsDD+fyLtgbJMAj9n6YA=
github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBaRMhvYXJNkGuM=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/creasty/defaults v1.7.0 h1:eNdqZvc5B509z18lD8yc212CAqJNvfT1Jq6L8WowdBA=
github.com/creasty/defaults v1.7.0/go.mod h1:iGzKe6pbEHnpMPtfDXZEr0NVxWnPTjb1bbDy08fPzYM=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -61,6 +59,8 @@ github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyua
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY=
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/opslevel/moredefaults v0.0.0-20240112142637-078c8ff8ba9c h1:m4sNHcfkE02xZy1oxF2QVGfhHulamxw9UlzRM7c45QQ=
github.com/opslevel/moredefaults v0.0.0-20240112142637-078c8ff8ba9c/go.mod h1:g2GSXVP6LO+5+AIsnMRPN+BeV86OXuFRTX7HXCDtYeI=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down Expand Up @@ -141,7 +141,6 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
Expand Down
16 changes: 8 additions & 8 deletions infra.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (client *Client) GetInfrastructure(identifier string) (*InfrastructureResou
return &q.Account.InfrastructureResource, HandleErrors(err, nil)
}

func (client *Client) ListInfrastructureSchemas(variables *PayloadVariables) (InfrastructureResourceSchemaConnection, error) {
func (client *Client) ListInfrastructureSchemas(variables *PayloadVariables) (*InfrastructureResourceSchemaConnection, error) {
var q struct {
Account struct {
InfrastructureResourceSchemas InfrastructureResourceSchemaConnection `graphql:"infrastructureResourceSchemas(after: $after, first: $first)"`
Expand All @@ -159,22 +159,22 @@ func (client *Client) ListInfrastructureSchemas(variables *PayloadVariables) (In
variables = client.InitialPageVariablesPointer()
}
if err := client.Query(&q, *variables, WithName("IntegrationList")); err != nil {
return InfrastructureResourceSchemaConnection{}, err
return nil, err
}
for q.Account.InfrastructureResourceSchemas.PageInfo.HasNextPage {
(*variables)["after"] = q.Account.InfrastructureResourceSchemas.PageInfo.End
resp, err := client.ListInfrastructureSchemas(variables)
if err != nil {
return InfrastructureResourceSchemaConnection{}, err
return nil, err
}
q.Account.InfrastructureResourceSchemas.Nodes = append(q.Account.InfrastructureResourceSchemas.Nodes, resp.Nodes...)
q.Account.InfrastructureResourceSchemas.PageInfo = resp.PageInfo
}
q.Account.InfrastructureResourceSchemas.TotalCount = len(q.Account.InfrastructureResourceSchemas.Nodes)
return q.Account.InfrastructureResourceSchemas, nil
return &q.Account.InfrastructureResourceSchemas, nil
}

func (client *Client) ListInfrastructure(variables *PayloadVariables) (InfrastructureResourceConnection, error) {
func (client *Client) ListInfrastructure(variables *PayloadVariables) (*InfrastructureResourceConnection, error) {
var q struct {
Account struct {
InfrastructureResource InfrastructureResourceConnection `graphql:"infrastructureResources(after: $after, first: $first)"`
Expand All @@ -185,19 +185,19 @@ func (client *Client) ListInfrastructure(variables *PayloadVariables) (Infrastru
(*variables)["all"] = true
}
if err := client.Query(&q, *variables, WithName("IntegrationList")); err != nil {
return InfrastructureResourceConnection{}, err
return nil, err
}
for q.Account.InfrastructureResource.PageInfo.HasNextPage {
(*variables)["after"] = q.Account.InfrastructureResource.PageInfo.End
resp, err := client.ListInfrastructure(variables)
if err != nil {
return InfrastructureResourceConnection{}, err
return nil, err
}
q.Account.InfrastructureResource.Nodes = append(q.Account.InfrastructureResource.Nodes, resp.Nodes...)
q.Account.InfrastructureResource.PageInfo = resp.PageInfo
}
q.Account.InfrastructureResource.TotalCount = len(q.Account.InfrastructureResource.Nodes)
return q.Account.InfrastructureResource, nil
return &q.Account.InfrastructureResource, nil
}

func (client *Client) UpdateInfrastructure(identifier string, input InfraInput) (*InfrastructureResource, error) {
Expand Down
8 changes: 4 additions & 4 deletions integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (client *Client) GetIntegration(id ID) (*Integration, error) {
return &q.Account.Integration, HandleErrors(err, nil)
}

func (client *Client) ListIntegrations(variables *PayloadVariables) (IntegrationConnection, error) {
func (client *Client) ListIntegrations(variables *PayloadVariables) (*IntegrationConnection, error) {
var q struct {
Account struct {
Integrations IntegrationConnection `graphql:"integrations(after: $after, first: $first)"`
Expand All @@ -122,19 +122,19 @@ func (client *Client) ListIntegrations(variables *PayloadVariables) (Integration
variables = client.InitialPageVariablesPointer()
}
if err := client.Query(&q, *variables, WithName("IntegrationList")); err != nil {
return IntegrationConnection{}, err
return nil, err
}
for q.Account.Integrations.PageInfo.HasNextPage {
(*variables)["after"] = q.Account.Integrations.PageInfo.End
resp, err := client.ListIntegrations(variables)
if err != nil {
return IntegrationConnection{}, err
return nil, err
}
q.Account.Integrations.Nodes = append(q.Account.Integrations.Nodes, resp.Nodes...)
q.Account.Integrations.PageInfo = resp.PageInfo
q.Account.Integrations.TotalCount += resp.TotalCount
}
return q.Account.Integrations, nil
return &q.Account.Integrations, nil
}

//#endregion
Expand Down
Loading

0 comments on commit ba5d57f

Please sign in to comment.