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 13 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 optional "string", "ID", "bool", and timestamp 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
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
63 changes: 34 additions & 29 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"},
LiquidTemplate: ol.NewNullableFrom("{\"token\": \"XXX\", \"ref\":\"main\", \"action\": \"rollback\"}"),
Headers: jsonHeaders,
HttpMethod: ol.CustomActionsHttpMethodEnumPost,
WebhookUrl: "https://gitlab.com/api/v4/projects/1/trigger/pipeline",
})
Expand Down Expand Up @@ -69,9 +71,10 @@ func TestUpdateWebhookAction(t *testing.T) {
client := BestTestClient(t, "custom_actions/update_action", testRequest)

// Act
putHttpMethod := ol.CustomActionsHttpMethodEnumPut
davidbloss marked this conversation as resolved.
Show resolved Hide resolved
action, err := client.UpdateWebhookAction(ol.CustomActionsWebhookActionUpdateInput{
Id: *newID,
HttpMethod: ol.RefOf(ol.CustomActionsHttpMethodEnumPut),
HttpMethod: &putHttpMethod,
})

// Assert
Expand All @@ -90,10 +93,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"},
Description: ol.NewNullableFrom(""),
Headers: jsonHeaders,
})

// Assert
Expand Down Expand Up @@ -130,13 +135,13 @@ func TestCreateTriggerDefinition(t *testing.T) {
// Act
trigger, err := client.CreateTriggerDefinition(ol.CustomActionsTriggerDefinitionCreateInput{
Name: "Deploy Rollback",
AccessControl: ol.RefOf(ol.CustomActionsTriggerDefinitionAccessControlEnumEveryone),
Description: ol.RefOf("Disables the Deploy Freeze"),
ResponseTemplate: ol.RefOf(""),
ManualInputsDefinition: ol.RefOf(""),
ActionId: newID,
AccessControl: &ol.CustomActionsTriggerDefinitionAccessControlEnumEveryone,
Description: ol.NewNullableFrom("Disables the Deploy Freeze"),
ResponseTemplate: ol.NewNullableFrom(""),
ManualInputsDefinition: ol.NewNullableFrom(""),
ActionId: ol.NewNullableFrom(*newID),
OwnerId: *newID,
FilterId: ol.NewID("987654321"),
FilterId: ol.NewNullableFrom(ol.ID("987654321")),
})
// Assert
autopilot.Ok(t, err)
Expand All @@ -155,14 +160,14 @@ func TestCreateTriggerDefinitionWithGlobalEntityType(t *testing.T) {
// Act
trigger, err := client.CreateTriggerDefinition(ol.CustomActionsTriggerDefinitionCreateInput{
Name: "Deploy Rollback",
AccessControl: ol.RefOf(ol.CustomActionsTriggerDefinitionAccessControlEnumEveryone),
Description: ol.RefOf("Disables the Deploy Freeze"),
ActionId: newID,
ManualInputsDefinition: ol.RefOf(""),
ResponseTemplate: ol.RefOf(""),
AccessControl: &ol.CustomActionsTriggerDefinitionAccessControlEnumEveryone,
Description: ol.NewNullableFrom("Disables the Deploy Freeze"),
ActionId: ol.NewNullableFrom(*newID),
ManualInputsDefinition: ol.NewNullableFrom(""),
ResponseTemplate: ol.NewNullableFrom(""),
OwnerId: *newID,
FilterId: ol.NewID("987654321"),
EntityType: ol.RefOf(ol.CustomActionsEntityTypeEnumGlobal),
FilterId: ol.NewNullableFrom(ol.ID("987654321")),
EntityType: &ol.CustomActionsEntityTypeEnumGlobal,
ExtendedTeamAccess: &[]ol.IdentifierInput{
*ol.NewIdentifier("example_1"),
*ol.NewIdentifier("example_1"),
Expand All @@ -185,13 +190,13 @@ func TestCreateTriggerDefinitionWithNullExtendedTeams(t *testing.T) {
// Act
trigger, err := client.CreateTriggerDefinition(ol.CustomActionsTriggerDefinitionCreateInput{
Name: "Deploy Rollback",
Description: ol.RefOf("Disables the Deploy Freeze"),
AccessControl: ol.RefOf(ol.CustomActionsTriggerDefinitionAccessControlEnumEveryone),
ManualInputsDefinition: ol.RefOf(""),
ResponseTemplate: ol.RefOf(""),
ActionId: newID,
Description: ol.NewNullableFrom("Disables the Deploy Freeze"),
AccessControl: &ol.CustomActionsTriggerDefinitionAccessControlEnumEveryone,
ManualInputsDefinition: ol.NewNullableFrom(""),
ResponseTemplate: ol.NewNullableFrom(""),
ActionId: ol.NewNullableFrom(*newID),
OwnerId: *newID,
FilterId: ol.NewID("987654321"),
FilterId: ol.NewNullableFrom(ol.ID("987654321")),
ExtendedTeamAccess: &[]ol.IdentifierInput{},
})
// Assert
Expand Down Expand Up @@ -258,7 +263,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 All @@ -277,8 +282,8 @@ func TestUpdateTriggerDefinition2(t *testing.T) {
// Act
trigger, err := client.UpdateTriggerDefinition(ol.CustomActionsTriggerDefinitionUpdateInput{
Id: *newID,
Name: ol.RefOf("test"),
Description: ol.RefOf(""),
Name: ol.NewNullableFrom("test"),
Description: ol.NewNullableFrom(""),
ExtendedTeamAccess: &[]ol.IdentifierInput{},
})
// Assert
Expand All @@ -298,8 +303,8 @@ func TestUpdateTriggerDefinition3(t *testing.T) {
// Act
trigger, err := client.UpdateTriggerDefinition(ol.CustomActionsTriggerDefinitionUpdateInput{
Id: *newID,
Name: ol.RefOf("test"),
Description: ol.RefOf(""),
Name: ol.NewNullableFrom("test"),
Description: ol.NewNullableFrom(""),
ExtendedTeamAccess: &[]ol.IdentifierInput{
*ol.NewIdentifier(string(*newID)),
*ol.NewIdentifier(string(id1)),
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
2 changes: 1 addition & 1 deletion category_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestUpdateRubricCategory(t *testing.T) {
// Act
result, err := client.UpdateCategory(ol.CategoryUpdateInput{
Id: id4,
Name: ol.RefOf("Emily"),
Name: ol.NewNullableFrom("Emily"),
})
// Assert
autopilot.Ok(t, 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: NewNullableFrom(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: NewNullableFrom(startingDateIso),
FrequencyTimeScale: &timeScale,
FrequencyValue: &value,
FrequencyValue: NewNullableFrom(value),
}
}

Expand Down
Loading
Loading