From 9f33925f5ee14af14370fb529f5f8d7916a6a324 Mon Sep 17 00:00:00 2001 From: Alisdair McDiarmid Date: Thu, 9 May 2019 16:33:43 -0400 Subject: [PATCH 1/2] Add workspace filtering fields --- workspace.go | 22 ++++++++++++++++++++++ workspace_test.go | 17 ++++++++++++----- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/workspace.go b/workspace.go index 7b95ac132..ddb3d124c 100644 --- a/workspace.go +++ b/workspace.go @@ -78,6 +78,8 @@ type Workspace struct { TerraformVersion string `jsonapi:"attr,terraform-version"` VCSRepo *VCSRepo `jsonapi:"attr,vcs-repo"` WorkingDirectory string `jsonapi:"attr,working-directory"` + FileTriggersEnabled bool `jsonapi:"attr,file-triggers-enabled"` + TriggerPrefixes []string `jsonapi:"attr,trigger-prefixes"` // Relations CurrentRun *Run `jsonapi:"relation,current-run"` @@ -176,6 +178,16 @@ type WorkspaceCreateOptions struct { // root of your repository and is typically set to a subdirectory matching the // environment when multiple environments exist within the same repository. WorkingDirectory *string `jsonapi:"attr,working-directory,omitempty"` + + // Whether to filter runs based on the changed files in a VCS push. If + // enabled, the working directory and trigger prefixes describe a set of + // paths which must contain changes for a VCS push to trigger a run. If + // disabled, any push will trigger a run. + FileTriggersEnabled *bool `jsonapi:"attr,file-triggers-enabled,omitempty"` + + // List of repository-root-relative paths which list all locations to be + // tracked for changes. See FileTriggersEnabled above for more details. + TriggerPrefixes *[]string `jsonapi:"attr,trigger-prefixes,omitempty"` } // VCSRepoOptions represents the configuration options of a VCS integration. @@ -284,6 +296,16 @@ type WorkspaceUpdateOptions struct { // the environment when multiple environments exist within the same // repository. WorkingDirectory *string `jsonapi:"attr,working-directory,omitempty"` + + // Whether to filter runs based on the changed files in a VCS push. If + // enabled, the working directory and trigger prefixes describe a set of + // paths which must contain changes for a VCS push to trigger a run. If + // disabled, any push will trigger a run. + FileTriggersEnabled *bool `jsonapi:"attr,file-triggers-enabled,omitempty"` + + // List of repository-root-relative paths which list all locations to be + // tracked for changes. See FileTriggersEnabled above for more details. + TriggerPrefixes *[]string `jsonapi:"attr,trigger-prefixes,omitempty"` } // Update settings of an existing workspace. diff --git a/workspace_test.go b/workspace_test.go index fc853ecac..bf16e97e6 100644 --- a/workspace_test.go +++ b/workspace_test.go @@ -86,12 +86,15 @@ func TestWorkspacesCreate(t *testing.T) { t.Run("with valid options", func(t *testing.T) { options := WorkspaceCreateOptions{ - Name: String("foo"), - AutoApply: Bool(true), - QueueAllRuns: Bool(true), - TerraformVersion: String("0.11.0"), - WorkingDirectory: String("bar/"), + Name: String("foo"), + AutoApply: Bool(true), + QueueAllRuns: Bool(true), + TerraformVersion: String("0.11.0"), + WorkingDirectory: String("bar/"), + FileTriggersEnabled: Bool(true), } + triggerPrefixes := []string{"/modules", "/shared"} + options.TriggerPrefixes = &triggerPrefixes w, err := client.Workspaces.Create(ctx, orgTest.Name, options) require.NoError(t, err) @@ -110,6 +113,10 @@ func TestWorkspacesCreate(t *testing.T) { assert.Equal(t, *options.QueueAllRuns, item.QueueAllRuns) assert.Equal(t, *options.TerraformVersion, item.TerraformVersion) assert.Equal(t, *options.WorkingDirectory, item.WorkingDirectory) + + for i := range triggerPrefixes { + assert.Equal(t, triggerPrefixes[i], item.TriggerPrefixes[i]) + } } }) From 9213905d63b2877067501379b19fea06440700ac Mon Sep 17 00:00:00 2001 From: Sander van Harmelen Date: Fri, 10 May 2019 15:54:11 +0200 Subject: [PATCH 2/2] Order fields and fix the pointer to slice type --- workspace.go | 44 ++++++++++++++++++++++---------------------- workspace_test.go | 25 +++++++++++++------------ 2 files changed, 35 insertions(+), 34 deletions(-) diff --git a/workspace.go b/workspace.go index ddb3d124c..cdcd228cd 100644 --- a/workspace.go +++ b/workspace.go @@ -69,6 +69,7 @@ type Workspace struct { CanQueueDestroyPlan bool `jsonapi:"attr,can-queue-destroy-plan"` CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"` Environment string `jsonapi:"attr,environment"` + FileTriggersEnabled bool `jsonapi:"attr,file-triggers-enabled"` Locked bool `jsonapi:"attr,locked"` MigrationEnvironment string `jsonapi:"attr,migration-environment"` Name string `jsonapi:"attr,name"` @@ -76,10 +77,9 @@ type Workspace struct { Permissions *WorkspacePermissions `jsonapi:"attr,permissions"` QueueAllRuns bool `jsonapi:"attr,queue-all-runs"` TerraformVersion string `jsonapi:"attr,terraform-version"` + TriggerPrefixes []string `jsonapi:"attr,trigger-prefixes"` VCSRepo *VCSRepo `jsonapi:"attr,vcs-repo"` WorkingDirectory string `jsonapi:"attr,working-directory"` - FileTriggersEnabled bool `jsonapi:"attr,file-triggers-enabled"` - TriggerPrefixes []string `jsonapi:"attr,trigger-prefixes"` // Relations CurrentRun *Run `jsonapi:"relation,current-run"` @@ -151,6 +151,12 @@ type WorkspaceCreateOptions struct { // Whether to automatically apply changes when a Terraform plan is successful. AutoApply *bool `jsonapi:"attr,auto-apply,omitempty"` + // Whether to filter runs based on the changed files in a VCS push. If + // enabled, the working directory and trigger prefixes describe a set of + // paths which must contain changes for a VCS push to trigger a run. If + // disabled, any push will trigger a run. + FileTriggersEnabled *bool `jsonapi:"attr,file-triggers-enabled,omitempty"` + // The legacy TFE environment to use as the source of the migration, in the // form organization/environment. Omit this unless you are migrating a legacy // environment. @@ -169,6 +175,10 @@ type WorkspaceCreateOptions struct { // workspace, the latest version is selected unless otherwise specified. TerraformVersion *string `jsonapi:"attr,terraform-version,omitempty"` + // List of repository-root-relative paths which list all locations to be + // tracked for changes. See FileTriggersEnabled above for more details. + TriggerPrefixes []string `jsonapi:"attr,trigger-prefixes,omitempty"` + // Settings for the workspace's VCS repository. If omitted, the workspace is // created without a VCS repo. If included, you must specify at least the // oauth-token-id and identifier keys below. @@ -178,16 +188,6 @@ type WorkspaceCreateOptions struct { // root of your repository and is typically set to a subdirectory matching the // environment when multiple environments exist within the same repository. WorkingDirectory *string `jsonapi:"attr,working-directory,omitempty"` - - // Whether to filter runs based on the changed files in a VCS push. If - // enabled, the working directory and trigger prefixes describe a set of - // paths which must contain changes for a VCS push to trigger a run. If - // disabled, any push will trigger a run. - FileTriggersEnabled *bool `jsonapi:"attr,file-triggers-enabled,omitempty"` - - // List of repository-root-relative paths which list all locations to be - // tracked for changes. See FileTriggersEnabled above for more details. - TriggerPrefixes *[]string `jsonapi:"attr,trigger-prefixes,omitempty"` } // VCSRepoOptions represents the configuration options of a VCS integration. @@ -277,6 +277,12 @@ type WorkspaceUpdateOptions struct { // API and UI. Name *string `jsonapi:"attr,name,omitempty"` + // Whether to filter runs based on the changed files in a VCS push. If + // enabled, the working directory and trigger prefixes describe a set of + // paths which must contain changes for a VCS push to trigger a run. If + // disabled, any push will trigger a run. + FileTriggersEnabled *bool `jsonapi:"attr,file-triggers-enabled,omitempty"` + // Whether to queue all runs. Unless this is set to true, runs triggered by // a webhook will not be queued until at least one run is manually queued. QueueAllRuns *bool `jsonapi:"attr,queue-all-runs,omitempty"` @@ -284,6 +290,10 @@ type WorkspaceUpdateOptions struct { // The version of Terraform to use for this workspace. TerraformVersion *string `jsonapi:"attr,terraform-version,omitempty"` + // List of repository-root-relative paths which list all locations to be + // tracked for changes. See FileTriggersEnabled above for more details. + TriggerPrefixes []string `jsonapi:"attr,trigger-prefixes,omitempty"` + // To delete a workspace's existing VCS repo, specify null instead of an // object. To modify a workspace's existing VCS repo, include whichever of // the keys below you wish to modify. To add a new VCS repo to a workspace @@ -296,16 +306,6 @@ type WorkspaceUpdateOptions struct { // the environment when multiple environments exist within the same // repository. WorkingDirectory *string `jsonapi:"attr,working-directory,omitempty"` - - // Whether to filter runs based on the changed files in a VCS push. If - // enabled, the working directory and trigger prefixes describe a set of - // paths which must contain changes for a VCS push to trigger a run. If - // disabled, any push will trigger a run. - FileTriggersEnabled *bool `jsonapi:"attr,file-triggers-enabled,omitempty"` - - // List of repository-root-relative paths which list all locations to be - // tracked for changes. See FileTriggersEnabled above for more details. - TriggerPrefixes *[]string `jsonapi:"attr,trigger-prefixes,omitempty"` } // Update settings of an existing workspace. diff --git a/workspace_test.go b/workspace_test.go index bf16e97e6..6ceaf6925 100644 --- a/workspace_test.go +++ b/workspace_test.go @@ -88,13 +88,12 @@ func TestWorkspacesCreate(t *testing.T) { options := WorkspaceCreateOptions{ Name: String("foo"), AutoApply: Bool(true), + FileTriggersEnabled: Bool(true), QueueAllRuns: Bool(true), TerraformVersion: String("0.11.0"), + TriggerPrefixes: []string{"/modules", "/shared"}, WorkingDirectory: String("bar/"), - FileTriggersEnabled: Bool(true), } - triggerPrefixes := []string{"/modules", "/shared"} - options.TriggerPrefixes = &triggerPrefixes w, err := client.Workspaces.Create(ctx, orgTest.Name, options) require.NoError(t, err) @@ -110,13 +109,11 @@ func TestWorkspacesCreate(t *testing.T) { assert.NotEmpty(t, item.ID) assert.Equal(t, *options.Name, item.Name) assert.Equal(t, *options.AutoApply, item.AutoApply) + assert.Equal(t, *options.FileTriggersEnabled, item.FileTriggersEnabled) assert.Equal(t, *options.QueueAllRuns, item.QueueAllRuns) assert.Equal(t, *options.TerraformVersion, item.TerraformVersion) + assert.Equal(t, options.TriggerPrefixes, item.TriggerPrefixes) assert.Equal(t, *options.WorkingDirectory, item.WorkingDirectory) - - for i := range triggerPrefixes { - assert.Equal(t, triggerPrefixes[i], item.TriggerPrefixes[i]) - } } }) @@ -234,11 +231,13 @@ func TestWorkspacesUpdate(t *testing.T) { t.Run("with valid options", func(t *testing.T) { options := WorkspaceUpdateOptions{ - Name: String(randomString(t)), - AutoApply: Bool(false), - QueueAllRuns: Bool(false), - TerraformVersion: String("0.11.1"), - WorkingDirectory: String("baz/"), + Name: String(randomString(t)), + AutoApply: Bool(false), + FileTriggersEnabled: Bool(true), + QueueAllRuns: Bool(false), + TerraformVersion: String("0.11.1"), + TriggerPrefixes: []string{"/modules", "/shared"}, + WorkingDirectory: String("baz/"), } w, err := client.Workspaces.Update(ctx, orgTest.Name, wTest.Name, options) @@ -254,8 +253,10 @@ func TestWorkspacesUpdate(t *testing.T) { } { assert.Equal(t, *options.Name, item.Name) assert.Equal(t, *options.AutoApply, item.AutoApply) + assert.Equal(t, *options.FileTriggersEnabled, item.FileTriggersEnabled) assert.Equal(t, *options.QueueAllRuns, item.QueueAllRuns) assert.Equal(t, *options.TerraformVersion, item.TerraformVersion) + assert.Equal(t, options.TriggerPrefixes, item.TriggerPrefixes) assert.Equal(t, *options.WorkingDirectory, item.WorkingDirectory) } })