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

generate input objects, start using Nullable #498

Merged
merged 17 commits into from
Jan 3, 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/Refactor-20241227-103359.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Refactor
body: 'BREAKING CHANGE: "Nullable" type now wraps some optional struct fields of API input objects. This "Nullable" type enables fields to be set to the JSON "null" value.'
time: 2024-12-27T10:33:59.906375-06:00
3 changes: 3 additions & 0 deletions .changes/unreleased/Refactor-20250103-150158.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Refactor
body: "enums converted from consts to vars, e.g. opslevel.RefOf(opslevel.AlertSourceTypeEnumDatadog) should now be &opslevel.AlertSourceTypeEnumDatadog"
time: 2025-01-03T15:01:58.276367-06:00
3 changes: 3 additions & 0 deletions .changes/unreleased/Removed-20250103-151332.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Removed
body: removed NullableString func, no longer used
time: 2025-01-03T15:13:32.484099-06:00
4 changes: 2 additions & 2 deletions actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ func (client *Client) CreateTriggerDefinition(input CustomActionsTriggerDefiniti
} `graphql:"customActionsTriggerDefinitionCreate(input: $input)"`
}
if input.AccessControl == nil {
input.AccessControl = RefOf(CustomActionsTriggerDefinitionAccessControlEnumEveryone)
input.AccessControl = &CustomActionsTriggerDefinitionAccessControlEnumEveryone
}
if input.EntityType == nil {
input.EntityType = RefOf(CustomActionsEntityTypeEnumService)
input.EntityType = &CustomActionsEntityTypeEnumService
}
v := PayloadVariables{
"input": input,
Expand Down
32 changes: 18 additions & 14 deletions actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ func TestCreateWebhookAction(t *testing.T) {
client := BestTestClient(t, "custom_actions/create_action", testRequest)

// Act
jsonHeaders, err := ol.NewJSON(`{"Content-Type": "application/json"}`)
autopilot.Ok(t, err)
action, err := client.CreateWebhookAction(ol.CustomActionsWebhookActionCreateInput{
Name: "Deploy Rollback",
LiquidTemplate: ol.RefOf("{\"token\": \"XXX\", \"ref\":\"main\", \"action\": \"rollback\"}"),
Headers: &ol.JSON{"Content-Type": "application/json"},
Headers: jsonHeaders,
HttpMethod: ol.CustomActionsHttpMethodEnumPost,
WebhookUrl: "https://gitlab.com/api/v4/projects/1/trigger/pipeline",
})
Expand Down Expand Up @@ -71,7 +73,7 @@ func TestUpdateWebhookAction(t *testing.T) {
// Act
action, err := client.UpdateWebhookAction(ol.CustomActionsWebhookActionUpdateInput{
Id: *newID,
HttpMethod: ol.RefOf(ol.CustomActionsHttpMethodEnumPut),
HttpMethod: &ol.CustomActionsHttpMethodEnumPut,
})

// Assert
Expand All @@ -90,10 +92,12 @@ func TestUpdateWebhookAction2(t *testing.T) {
client := BestTestClient(t, "custom_actions/update_action2", testRequest)

// Act
jsonHeaders, err := ol.NewJSON(`{"Accept": "application/json"}`)
autopilot.Ok(t, err)
action, err := client.UpdateWebhookAction(ol.CustomActionsWebhookActionUpdateInput{
Id: *newID,
Description: ol.RefOf(""),
Headers: &ol.JSON{"Accept": "application/json"},
Headers: jsonHeaders,
})

// Assert
Expand Down Expand Up @@ -130,13 +134,13 @@ func TestCreateTriggerDefinition(t *testing.T) {
// Act
trigger, err := client.CreateTriggerDefinition(ol.CustomActionsTriggerDefinitionCreateInput{
Name: "Deploy Rollback",
AccessControl: ol.RefOf(ol.CustomActionsTriggerDefinitionAccessControlEnumEveryone),
AccessControl: &ol.CustomActionsTriggerDefinitionAccessControlEnumEveryone,
Description: ol.RefOf("Disables the Deploy Freeze"),
ResponseTemplate: ol.RefOf(""),
ManualInputsDefinition: ol.RefOf(""),
ActionId: newID,
ActionId: ol.RefOf(*newID),
davidbloss marked this conversation as resolved.
Show resolved Hide resolved
OwnerId: *newID,
FilterId: ol.NewID("987654321"),
FilterId: ol.RefOf(ol.ID("987654321")),
})
// Assert
autopilot.Ok(t, err)
Expand All @@ -155,14 +159,14 @@ func TestCreateTriggerDefinitionWithGlobalEntityType(t *testing.T) {
// Act
trigger, err := client.CreateTriggerDefinition(ol.CustomActionsTriggerDefinitionCreateInput{
Name: "Deploy Rollback",
AccessControl: ol.RefOf(ol.CustomActionsTriggerDefinitionAccessControlEnumEveryone),
AccessControl: &ol.CustomActionsTriggerDefinitionAccessControlEnumEveryone,
Description: ol.RefOf("Disables the Deploy Freeze"),
ActionId: newID,
ActionId: ol.RefOf(*newID),
davidbloss marked this conversation as resolved.
Show resolved Hide resolved
ManualInputsDefinition: ol.RefOf(""),
ResponseTemplate: ol.RefOf(""),
OwnerId: *newID,
FilterId: ol.NewID("987654321"),
EntityType: ol.RefOf(ol.CustomActionsEntityTypeEnumGlobal),
FilterId: ol.RefOf(ol.ID("987654321")),
EntityType: &ol.CustomActionsEntityTypeEnumGlobal,
ExtendedTeamAccess: &[]ol.IdentifierInput{
*ol.NewIdentifier("example_1"),
*ol.NewIdentifier("example_1"),
Expand All @@ -186,12 +190,12 @@ func TestCreateTriggerDefinitionWithNullExtendedTeams(t *testing.T) {
trigger, err := client.CreateTriggerDefinition(ol.CustomActionsTriggerDefinitionCreateInput{
Name: "Deploy Rollback",
Description: ol.RefOf("Disables the Deploy Freeze"),
AccessControl: ol.RefOf(ol.CustomActionsTriggerDefinitionAccessControlEnumEveryone),
AccessControl: &ol.CustomActionsTriggerDefinitionAccessControlEnumEveryone,
ManualInputsDefinition: ol.RefOf(""),
ResponseTemplate: ol.RefOf(""),
ActionId: newID,
ActionId: ol.RefOf(*newID),
davidbloss marked this conversation as resolved.
Show resolved Hide resolved
OwnerId: *newID,
FilterId: ol.NewID("987654321"),
FilterId: ol.RefOf(ol.ID("987654321")),
ExtendedTeamAccess: &[]ol.IdentifierInput{},
})
// Assert
Expand Down Expand Up @@ -258,7 +262,7 @@ func TestUpdateTriggerDefinition(t *testing.T) {
// Act
trigger, err := client.UpdateTriggerDefinition(ol.CustomActionsTriggerDefinitionUpdateInput{
Id: *newID,
FilterId: ol.NewID(),
FilterId: ol.NewNullOf[ol.ID](),
})
// Assert
autopilot.Ok(t, err)
Expand Down
2 changes: 1 addition & 1 deletion aliases.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (client *Client) CreateAliases(ownerId ID, aliases []string) ([]string, err
for _, alias := range aliases {
input := AliasCreateInput{
Alias: alias,
OwnerId: ownerId,
OwnerId: ID(ownerId),
}
result, err := client.CreateAlias(input)
allErrors = errors.Join(allErrors, err)
Expand Down
36 changes: 18 additions & 18 deletions check.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ type CheckCreateInputProvider interface {
}

type CheckCreateInput struct {
Name string `json:"name" yaml:"name" mapstructure:"name"`
Enabled *bool `json:"enabled" yaml:"enabled" mapstructure:"enabled"`
EnableOn *iso8601.Time `json:"enableOn,omitempty" yaml:"enableOn,omitempty" mapstructure:"enabledOn,omitempty"`
Category ID `json:"categoryId" yaml:"categoryId" mapstructure:"categoryId"`
Level ID `json:"levelId" yaml:"levelId" mapstructure:"levelId"`
Owner *ID `json:"ownerId,omitempty" yaml:"ownerId,omitempty" mapstructure:"ownerId,omitempty"`
Filter *ID `json:"filterId,omitempty" yaml:"filterId,omitempty" mapstructure:"filterId,omitempty"`
Notes *string `json:"notes" yaml:"notes" default:"Notes on Example Check" mapstructure:"notes"`
Category ID `json:"categoryId" yaml:"categoryId" mapstructure:"categoryId"`
EnableOn *Nullable[iso8601.Time] `json:"enableOn,omitempty" yaml:"enableOn,omitempty" mapstructure:"enabledOn,omitempty"`
Enabled *Nullable[bool] `json:"enabled,omitempty" yaml:"enabled,omitempty" mapstructure:"enabled"`
Filter *Nullable[ID] `json:"filterId,omitempty" yaml:"filterId,omitempty" mapstructure:"filterId,omitempty"`
Level ID `json:"levelId" yaml:"levelId" mapstructure:"levelId"`
Name string `json:"name" yaml:"name" mapstructure:"name"`
Notes *Nullable[string] `json:"notes,omitempty" yaml:"notes,omitempty" mapstructure:"notes,omitempty"`
Owner *Nullable[ID] `json:"ownerId,omitempty" yaml:"ownerId,omitempty" mapstructure:"ownerId,omitempty"`
}

func NewCheckCreateInputTypeOf[T any](checkCreateInput CheckCreateInput) *T {
Expand All @@ -113,15 +113,15 @@ type CheckUpdateInputProvider interface {
}

type CheckUpdateInput struct {
Id ID `json:"id" mapstructure:"id"`
Name string `json:"name,omitempty" mapstructure:"name,omitempty"`
Enabled *bool `json:"enabled,omitempty" mapstructure:"enabled,omitempty"`
EnableOn *iso8601.Time `json:"enableOn,omitempty" mapstructure:"enabledOn,omitempty"`
Category ID `json:"categoryId,omitempty" mapstructure:"categoryId,omitempty"`
Level ID `json:"levelId,omitempty" mapstructure:"levelId,omitempty"`
Owner *ID `json:"ownerId,omitempty" yaml:"ownerId,omitempty" mapstructure:"ownerId,omitempty"`
Filter *ID `json:"filterId,omitempty" yaml:"filterId,omitempty" mapstructure:"filterId,omitempty"`
Notes *string `json:"notes,omitempty" mapstructure:"notes,omitempty"`
Category *Nullable[ID] `json:"categoryId,omitempty" mapstructure:"categoryId,omitempty"`
EnableOn *Nullable[iso8601.Time] `json:"enableOn,omitempty" mapstructure:"enabledOn,omitempty"`
Enabled *Nullable[bool] `json:"enabled,omitempty" mapstructure:"enabled,omitempty"`
Filter *Nullable[ID] `json:"filterId,omitempty" yaml:"filterId,omitempty" mapstructure:"filterId,omitempty"`
Id ID `json:"id" mapstructure:"id"`
Level *Nullable[ID] `json:"levelId,omitempty" mapstructure:"levelId,omitempty"`
Name *Nullable[string] `json:"name,omitempty" mapstructure:"name,omitempty"`
Notes *Nullable[string] `json:"notes,omitempty" mapstructure:"notes,omitempty"`
Owner *Nullable[ID] `json:"ownerId,omitempty" yaml:"ownerId,omitempty" mapstructure:"ownerId,omitempty"`
}

func NewCheckUpdateInputTypeOf[T any](checkUpdateInput CheckUpdateInput) *T {
Expand Down Expand Up @@ -275,7 +275,7 @@ func (client *Client) DeleteCheck(id ID) error {
} `graphql:"checkDelete(input: $input)"`
}
v := PayloadVariables{
"input": CheckDeleteInput{Id: &id},
"input": CheckDeleteInput{Id: RefOf(id)},
}
err := client.Mutate(&m, v, WithName("CheckDelete"))
return HandleErrors(err, m.Payload.Errors)
Expand Down
4 changes: 2 additions & 2 deletions check_manual.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ func NewManualCheckFrequencyInput(startingDate string, timeScale FrequencyTimeSc
func NewManualCheckFrequencyUpdateInput(startingDate string, timeScale FrequencyTimeScale, value int) *ManualCheckFrequencyUpdateInput {
startingDateIso := NewISO8601Date(startingDate)
return &ManualCheckFrequencyUpdateInput{
StartingDate: &startingDateIso,
StartingDate: RefOf(startingDateIso),
FrequencyTimeScale: &timeScale,
FrequencyValue: &value,
FrequencyValue: RefOf(value),
}
}

Expand Down
Loading
Loading