Skip to content

Commit 9cbe67a

Browse files
committed
Adding include option to deployment runs read/list
1 parent b24090e commit 9cbe67a

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

stack_deployment_runs.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type StackDeploymentRuns interface {
1515
// List returns a list of stack deployment runs for a given deployment group.
1616
List(ctx context.Context, deploymentGroupID string, options *StackDeploymentRunListOptions) (*StackDeploymentRunList, error)
1717
Read(ctx context.Context, stackDeploymentRunID string) (*StackDeploymentRun, error)
18+
ReadWithOptions(ctx context.Context, stackDeploymentRunID string, options *StackDeploymentRunReadOptions) (*StackDeploymentRun, error)
1819
ApproveAllPlans(ctx context.Context, deploymentRunID string) error
1920
}
2021

@@ -36,15 +37,28 @@ type StackDeploymentRun struct {
3637
StackDeploymentGroup *StackDeploymentGroup `jsonapi:"relation,stack-deployment-group"`
3738
}
3839

40+
type SDRIncludeOpt string
41+
42+
const (
43+
SDRDeploymentGroup SDRIncludeOpt = "stack-deployment-group"
44+
)
45+
3946
// StackDeploymentRunList represents a list of stack deployment runs.
4047
type StackDeploymentRunList struct {
4148
*Pagination
4249
Items []*StackDeploymentRun
4350
}
4451

52+
type StackDeploymentRunReadOptions struct {
53+
// Optional: A list of relations to include.
54+
Include []SDRIncludeOpt `url:"include,omitempty"`
55+
}
56+
4557
// StackDeploymentRunListOptions represents the options for listing stack deployment runs.
4658
type StackDeploymentRunListOptions struct {
4759
ListOptions
60+
// Optional: A list of relations to include.
61+
Include []SDRIncludeOpt `url:"include,omitempty"`
4862
}
4963

5064
// List returns a list of stack deployment runs for a given deployment group.
@@ -78,6 +92,25 @@ func (s stackDeploymentRuns) Read(ctx context.Context, stackDeploymentRunID stri
7892
return &run, nil
7993
}
8094

95+
func (s stackDeploymentRuns) ReadWithOptions(ctx context.Context, stackDeploymentRunID string, options *StackDeploymentRunReadOptions) (*StackDeploymentRun, error) {
96+
if err := options.valid(); err != nil {
97+
return nil, err
98+
}
99+
100+
req, err := s.client.NewRequest("GET", fmt.Sprintf("stack-deployment-runs/%s", url.PathEscape(stackDeploymentRunID)), options)
101+
if err != nil {
102+
return nil, err
103+
}
104+
105+
run := StackDeploymentRun{}
106+
err = req.Do(ctx, &run)
107+
if err != nil {
108+
return nil, err
109+
}
110+
111+
return &run, nil
112+
}
113+
81114
func (s stackDeploymentRuns) ApproveAllPlans(ctx context.Context, stackDeploymentRunID string) error {
82115
req, err := s.client.NewRequest("POST", fmt.Sprintf("stack-deployment-runs/%s/approve-all-plans", url.PathEscape(stackDeploymentRunID)), nil)
83116
if err != nil {
@@ -86,3 +119,15 @@ func (s stackDeploymentRuns) ApproveAllPlans(ctx context.Context, stackDeploymen
86119

87120
return req.Do(ctx, nil)
88121
}
122+
123+
func (o *StackDeploymentRunReadOptions) valid() error {
124+
for _, include := range o.Include {
125+
switch include {
126+
case SDRDeploymentGroup:
127+
// Valid option, do nothing.
128+
default:
129+
return fmt.Errorf("invalid include option: %s", include)
130+
}
131+
}
132+
return nil
133+
}

0 commit comments

Comments
 (0)