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 19, 2022
1 parent 954defe commit ce28630
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,7 @@

# v1.6.0
* Add `Name` field to `OAuthClient` by @barrettclark [#466](https://github.com/hashicorp/go-tfe/pull/466)
* [beta] Add support for disabled file trigger runs when setting Git tags [#468](https://github.com/hashicorp/go-tfe/pull/468)

# v1.5.0

Expand Down
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
26 changes: 24 additions & 2 deletions workspace_integration_test.go
Expand Up @@ -345,7 +345,6 @@ func TestWorkspacesCreate(t *testing.T) {
})

t.Run("when options include tags-regex(behind a feature flag)", func(t *testing.T) {
skipIfBeta(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{
Name: String("tst-" + randomString(t)[0:20] + "-git-tag-ff-on"),
Expand Down Expand Up @@ -414,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 @@ -834,7 +845,6 @@ func TestWorkspacesUpdate(t *testing.T) {
})

t.Run("when options include VCSRepo tags-regex (behind a feature flag)", func(t *testing.T) {
skipIfBeta(t)
// Remove the below organization and workspace creation and use the one from the outer scope once the feature flag is removed
orgTest, orgTestCleanup := createOrganizationWithOptions(t, client, OrganizationCreateOptions{
Name: String("tst-" + randomString(t)[0:20] + "-git-tag-ff-on"),
Expand Down Expand Up @@ -890,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 ce28630

Please sign in to comment.