Skip to content

Commit

Permalink
Allow FileTriggersEnabled to be set to false when Git tags are present
Browse files Browse the repository at this point in the history
  • Loading branch information
hashimoon committed Jul 18, 2022
1 parent f6825bf commit a9a5f59
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
8 changes: 4 additions & 4 deletions workspace.go
Expand Up @@ -1080,8 +1080,8 @@ func (o WorkspaceCreateOptions) valid() error {
o.TriggerPrefixes != nil && len(o.TriggerPrefixes) > 0 {
return ErrUnsupportedBothTagsRegexAndTriggerPrefixes
}
if o.VCSRepo != nil && o.VCSRepo.TagsRegex != nil &&
o.FileTriggersEnabled != nil && *o.FileTriggersEnabled {
if o.VCSRepo != nil && o.VCSRepo.TagsRegex != nil && *o.VCSRepo.TagsRegex != "" &&
o.FileTriggersEnabled != nil && *o.FileTriggersEnabled == true {
return ErrUnsupportedBothTagsRegexAndFileTriggersEnabled
}

Expand Down Expand Up @@ -1111,8 +1111,8 @@ func (o WorkspaceUpdateOptions) valid() error {
o.TriggerPrefixes != nil && len(o.TriggerPrefixes) > 0 {
return ErrUnsupportedBothTagsRegexAndTriggerPrefixes
}
if o.VCSRepo != nil && o.VCSRepo.TagsRegex != nil &&
o.FileTriggersEnabled != nil && *o.FileTriggersEnabled {
if o.VCSRepo != nil && o.VCSRepo.TagsRegex != nil && *o.VCSRepo.TagsRegex != "" &&
o.FileTriggersEnabled != nil && *o.FileTriggersEnabled == true {
return ErrUnsupportedBothTagsRegexAndFileTriggersEnabled
}

Expand Down
24 changes: 24 additions & 0 deletions workspace_integration_test.go
Expand Up @@ -413,6 +413,18 @@ func TestWorkspacesCreate(t *testing.T) {
assert.EqualError(t, err, ErrUnsupportedBothTagsRegexAndFileTriggersEnabled.Error())
})

t.Run("when options include both non-empty tags-regex and file-triggers-enabled as false an error is not returned", func(t *testing.T) {
options := WorkspaceCreateOptions{
Name: String("foobar"),
FileTriggersEnabled: Bool(false),
VCSRepo: &VCSRepoOptions{TagsRegex: String("foobar")},
}
w, err := client.Workspaces.Create(ctx, orgTest.Name, options)

require.NotNil(t, w)
require.NoError(t, err)
})

t.Run("when options include trigger-patterns populated and empty trigger-paths workspace is created", func(t *testing.T) {
// Remove the below organization creation and use the one from the outer scope once the feature flag is removed
orgTest, orgTestCleanup := createOrganizationWithOptions(t, client, OrganizationCreateOptions{
Expand Down Expand Up @@ -888,6 +900,18 @@ func TestWorkspacesUpdate(t *testing.T) {
assert.EqualError(t, err, ErrUnsupportedBothTagsRegexAndFileTriggersEnabled.Error())
})

t.Run("when options include both non-empty tags-regex and file-triggers-enabled an error is returned", func(t *testing.T) {
options := WorkspaceUpdateOptions{
Name: String("foobar"),
FileTriggersEnabled: Bool(true),
VCSRepo: &VCSRepoOptions{TagsRegex: String("foobar")},
}
w, err := client.Workspaces.Update(ctx, orgTest.Name, wTest.Name, options)

assert.Nil(t, w)
assert.EqualError(t, err, ErrUnsupportedBothTagsRegexAndFileTriggersEnabled.Error())
})

t.Run("when options include both tags-regex and trigger-prefixes an error is returned", func(t *testing.T) {
options := WorkspaceUpdateOptions{
Name: String("foobar"),
Expand Down

0 comments on commit a9a5f59

Please sign in to comment.