From bdb8c6e129f707161f098bab2993345d8c76e671 Mon Sep 17 00:00:00 2001 From: Michael Yocca Date: Thu, 9 Jan 2025 09:43:16 -0800 Subject: [PATCH 1/3] fix(stacks/vcs): StackVCSRepo nested-struct incorrectly marshalling attributes hashicorp/jsonapi and by extension google/jsonapi packages have issues serializing nested-structs that are not relationship, but attr. Converting to json struct tag directive for the time being . --- stack.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stack.go b/stack.go index d45956450..ff698c84d 100644 --- a/stack.go +++ b/stack.go @@ -69,10 +69,10 @@ type StackList struct { // StackVCSRepo represents the version control system repository for a stack. type StackVCSRepo struct { - Identifier string `jsonapi:"attr,identifier"` - Branch string `jsonapi:"attr,branch,omitempty"` - GHAInstallationID string `jsonapi:"attr,github-app-installation-id,omitempty"` - OAuthTokenID string `jsonapi:"attr,oauth-token-id,omitempty"` + Identifier string `json:"identifier"` + Branch string `json:"branch,omitempty"` + GHAInstallationID string `json:"github-app-installation-id,omitempty"` + OAuthTokenID string `json:"oauth-token-id,omitempty"` } // Stack represents a stack. From 08fb565cba14949acc20350f80e3329318df487e Mon Sep 17 00:00:00 2001 From: Michael Yocca Date: Fri, 10 Jan 2025 10:58:45 -0800 Subject: [PATCH 2/3] fix: separate request/response annotations --- stack.go | 26 +++++++++++++++++++++----- stack_integration_test.go | 10 +++++----- stack_plan_integration_test.go | 2 +- stack_source_integration_test.go | 2 +- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/stack.go b/stack.go index ff698c84d..5d91cbace 100644 --- a/stack.go +++ b/stack.go @@ -69,6 +69,14 @@ type StackList struct { // StackVCSRepo represents the version control system repository for a stack. type StackVCSRepo struct { + Identifier string `jsonapi:"attr,identifier"` + Branch string `jsonapi:"attr,branch,omitempty"` + GHAInstallationID string `jsonapi:"attr,github-app-installation-id,omitempty"` + OAuthTokenID string `jsonapi:"attr,oauth-token-id,omitempty"` +} + +// StackVCSRepoOptions +type StackVCSRepoOptions struct { Identifier string `json:"identifier"` Branch string `json:"branch,omitempty"` GHAInstallationID string `json:"github-app-installation-id,omitempty"` @@ -172,11 +180,11 @@ type StackReadOptions struct { // StackCreateOptions represents the options for creating a stack. The project // relation is required. type StackCreateOptions struct { - Type string `jsonapi:"primary,stacks"` - Name string `jsonapi:"attr,name"` - Description *string `jsonapi:"attr,description,omitempty"` - VCSRepo *StackVCSRepo `jsonapi:"attr,vcs-repo"` - Project *Project `jsonapi:"relation,project"` + Type string `jsonapi:"primary,stacks"` + Name string `jsonapi:"attr,name"` + Description *string `jsonapi:"attr,description,omitempty"` + VCSRepo *StackVCSRepoOptions `jsonapi:"attr,vcs-repo"` + Project *Project `jsonapi:"relation,project"` } // StackUpdateOptions represents the options for updating a stack. @@ -334,6 +342,14 @@ func (s StackVCSRepo) valid() error { return nil } +func (s StackVCSRepoOptions) valid() error { + if s.Identifier == "" { + return ErrRequiredVCSRepo + } + + return nil +} + // awaitPoll is a helper function that uses a callback to read a status, then // waits for a terminal status or an error. The callback should return the // current status, or an error. For each time the status changes, the channel diff --git a/stack_integration_test.go b/stack_integration_test.go index 437120103..d8d82b554 100644 --- a/stack_integration_test.go +++ b/stack_integration_test.go @@ -31,7 +31,7 @@ func TestStackCreateAndList(t *testing.T) { stack1, err := client.Stacks.Create(ctx, StackCreateOptions{ Name: "aa-test-stack", - VCSRepo: &StackVCSRepo{ + VCSRepo: &StackVCSRepoOptions{ Identifier: "hashicorp-guides/pet-nulls-stack", OAuthTokenID: oauthClient.OAuthTokens[0].ID, }, @@ -45,7 +45,7 @@ func TestStackCreateAndList(t *testing.T) { stack2, err := client.Stacks.Create(ctx, StackCreateOptions{ Name: "zz-test-stack", - VCSRepo: &StackVCSRepo{ + VCSRepo: &StackVCSRepoOptions{ Identifier: "hashicorp-guides/pet-nulls-stack", OAuthTokenID: oauthClient.OAuthTokens[0].ID, }, @@ -143,7 +143,7 @@ func TestStackReadUpdateDelete(t *testing.T) { stack, err := client.Stacks.Create(ctx, StackCreateOptions{ Name: "test-stack", - VCSRepo: &StackVCSRepo{ + VCSRepo: &StackVCSRepoOptions{ Identifier: "brandonc/pet-nulls-stack", OAuthTokenID: oauthClient.OAuthTokens[0].ID, Branch: "main", @@ -200,7 +200,7 @@ func TestStackReadUpdateForceDelete(t *testing.T) { stack, err := client.Stacks.Create(ctx, StackCreateOptions{ Name: "test-stack", - VCSRepo: &StackVCSRepo{ + VCSRepo: &StackVCSRepoOptions{ Identifier: "brandonc/pet-nulls-stack", OAuthTokenID: oauthClient.OAuthTokens[0].ID, Branch: "main", @@ -356,7 +356,7 @@ func TestStackConverged(t *testing.T) { stack, err := client.Stacks.Create(ctx, StackCreateOptions{ Name: "test-stack", - VCSRepo: &StackVCSRepo{ + VCSRepo: &StackVCSRepoOptions{ Identifier: "brandonc/pet-nulls-stack", OAuthTokenID: oauthClient.OAuthTokens[0].ID, }, diff --git a/stack_plan_integration_test.go b/stack_plan_integration_test.go index ea5bbe834..29ae34a8a 100644 --- a/stack_plan_integration_test.go +++ b/stack_plan_integration_test.go @@ -29,7 +29,7 @@ func TestStackPlanList(t *testing.T) { stack, err := client.Stacks.Create(ctx, StackCreateOptions{ Name: "aa-test-stack", - VCSRepo: &StackVCSRepo{ + VCSRepo: &StackVCSRepoOptions{ Identifier: "brandonc/pet-nulls-stack", OAuthTokenID: oauthClient.OAuthTokens[0].ID, }, diff --git a/stack_source_integration_test.go b/stack_source_integration_test.go index fafaaa617..ab00fc8f2 100644 --- a/stack_source_integration_test.go +++ b/stack_source_integration_test.go @@ -26,7 +26,7 @@ func TestStackSourceCreateUploadAndRead(t *testing.T) { stack, err := client.Stacks.Create(ctx, StackCreateOptions{ Project: orgTest.DefaultProject, Name: "test-stack", - VCSRepo: &StackVCSRepo{ + VCSRepo: &StackVCSRepoOptions{ Identifier: "hashicorp-guides/pet-nulls-stack", OAuthTokenID: oauthClient.OAuthTokens[0].ID, }, From 4d060ed6d14a4982e3dfd578a453a33e41a91bfc Mon Sep 17 00:00:00 2001 From: Michael Yocca Date: Fri, 10 Jan 2025 14:44:14 -0800 Subject: [PATCH 3/3] chore: fix go-lint ci error --- stack.go | 8 -------- 1 file changed, 8 deletions(-) diff --git a/stack.go b/stack.go index 5d91cbace..7cb95bd8b 100644 --- a/stack.go +++ b/stack.go @@ -334,14 +334,6 @@ func (s StackCreateOptions) valid() error { return s.VCSRepo.valid() } -func (s StackVCSRepo) valid() error { - if s.Identifier == "" { - return ErrRequiredVCSRepo - } - - return nil -} - func (s StackVCSRepoOptions) valid() error { if s.Identifier == "" { return ErrRequiredVCSRepo