Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Unreleased

## Enhancements
* Adds `ReadWithOptions` method to `RunTriggers` to support including related resources when reading a run trigger by @Maed223 [#1275](https://github.com/hashicorp/go-tfe/pull/1275)
* Adds `UserTokensEnabled` field to `Organization` to support enabling/disabling user tokens for an organization by @JarrettSpiker [#1225](https://github.com/hashicorp/go-tfe/pull/1225)
* Adds `DeploymentRunStatus` and `DeploymentStepStatus` types by @Maed223 [#1261](https://github.com/hashicorp/go-tfe/pull/1261)

Expand Down
15 changes: 14 additions & 1 deletion run_trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ type RunTriggers interface {
// Read a run trigger by its ID.
Read(ctx context.Context, RunTriggerID string) (*RunTrigger, error)

// ReadWithOptions reads a run trigger by its ID using the options supplied
ReadWithOptions(ctx context.Context, runID string, options *RunTriggerReadOptions) (*RunTrigger, error)

// Delete a run trigger by its ID.
Delete(ctx context.Context, RunTriggerID string) error
}
Expand Down Expand Up @@ -100,6 +103,11 @@ type RunTriggerCreateOptions struct {
Sourceable *Workspace `jsonapi:"relation,sourceable"`
}

// RunTriggerCreateOptions represents the options for reading a run.
type RunTriggerReadOptions struct {
Include []RunTriggerIncludeOpt `url:"include,omitempty"` // optional`
}

// List all the run triggers associated with a workspace.
func (s *runTriggers) List(ctx context.Context, workspaceID string, options *RunTriggerListOptions) (*RunTriggerList, error) {
if !validStringID(&workspaceID) {
Expand Down Expand Up @@ -156,12 +164,17 @@ func (s *runTriggers) Create(ctx context.Context, workspaceID string, options Ru

// Read a run trigger by its ID.
func (s *runTriggers) Read(ctx context.Context, runTriggerID string) (*RunTrigger, error) {
return s.ReadWithOptions(ctx, runTriggerID, nil)
}

// Read a run trigger by its ID.
func (s *runTriggers) ReadWithOptions(ctx context.Context, runTriggerID string, options *RunTriggerReadOptions) (*RunTrigger, error) {
if !validStringID(&runTriggerID) {
return nil, ErrInvalidRunTriggerID
}

u := fmt.Sprintf("run-triggers/%s", url.PathEscape(runTriggerID))
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, options)
if err != nil {
return nil, err
}
Expand Down
29 changes: 29 additions & 0 deletions run_trigger_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,35 @@ func TestRunTriggerRead(t *testing.T) {
})
}

func TestRunTriggerReadWithOptions(t *testing.T) {
client := testClient(t)
ctx := context.Background()

orgTest, orgTestCleanup := createOrganization(t, client)
defer orgTestCleanup()

wTest, wTestCleanup := createWorkspace(t, client, orgTest)
defer wTestCleanup()

sourceableTest, sourceableTestCleanup := createWorkspace(t, client, orgTest)
defer sourceableTestCleanup()

rtTest, rtTestCleanup := createRunTrigger(t, client, wTest, sourceableTest)
defer rtTestCleanup()

t.Run("with include options", func(t *testing.T) {
rt, err := client.RunTriggers.ReadWithOptions(ctx, rtTest.ID, &RunTriggerReadOptions{
Include: []RunTriggerIncludeOpt{RunTriggerSourceable, RunTriggerWorkspace},
})
require.NoError(t, err)
assert.Equal(t, rtTest.ID, rt.ID)
require.NotNil(t, rt.Sourceable)
assert.Equal(t, sourceableTest.ID, rt.Sourceable.ID)
require.NotNil(t, rt.Workspace)
assert.Equal(t, wTest.ID, rt.Workspace.ID)
})
}

func TestRunTriggerDelete(t *testing.T) {
client := testClient(t)
ctx := context.Background()
Expand Down
Loading