Skip to content

Commit 413fb86

Browse files
committed
Fix finding deployment group by name
1 parent b6a6276 commit 413fb86

File tree

2 files changed

+30
-22
lines changed

2 files changed

+30
-22
lines changed

stack_deployment_groups.go

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ type StackDeploymentGroups interface {
1919
// Read retrieves a stack deployment group by its ID.
2020
Read(ctx context.Context, stackDeploymentGroupID string) (*StackDeploymentGroup, error)
2121

22+
// ReadByName retrieves a stack deployment group by its Name.
23+
ReadByName(ctx context.Context, stackConfigurationID string, stackDeploymentName string) (*StackDeploymentGroup, error)
24+
2225
// ApproveAllPlans approves all pending plans in a stack deployment group.
2326
ApproveAllPlans(ctx context.Context, stackDeploymentGroupID string) error
2427

@@ -65,8 +68,6 @@ type StackDeploymentGroupList struct {
6568
// StackDeploymentGroupListOptions represents additional options when listing stack deployment groups.
6669
type StackDeploymentGroupListOptions struct {
6770
ListOptions
68-
// A query string used to filter by deployment group name.
69-
GroupName string `url:"group_name,omitempty"`
7071
}
7172

7273
// StackDeploymentGroupRerunOptions represents options for rerunning deployments in a stack deployment group.
@@ -81,12 +82,11 @@ func (s stackDeploymentGroups) List(ctx context.Context, stackConfigID string, o
8182
return nil, fmt.Errorf("invalid stack configuration ID: %s", stackConfigID)
8283
}
8384

84-
u := fmt.Sprintf("stack-configurations/%s/stack-deployment-groups/", url.PathEscape(stackConfigID))
85-
qp, err := decodeQueryParams(options)
86-
if err != nil {
87-
return nil, err
85+
if options == nil {
86+
options = &StackDeploymentGroupListOptions{}
8887
}
89-
req, err := s.client.NewRequestWithAdditionalQueryParams("GET", u, nil, qp)
88+
89+
req, err := s.client.NewRequest("GET", fmt.Sprintf("stack-configurations/%s/stack-deployment-groups", url.PathEscape(stackConfigID)), options)
9090
if err != nil {
9191
return nil, err
9292
}
@@ -100,6 +100,29 @@ func (s stackDeploymentGroups) List(ctx context.Context, stackConfigID string, o
100100
return sdgl, nil
101101
}
102102

103+
// ReadByName retrieves a stack deployment group by its Name.
104+
func (s stackDeploymentGroups) ReadByName(ctx context.Context, stackConfigurationID string, stackDeploymentName string) (*StackDeploymentGroup, error) {
105+
if !validStringID(&stackConfigurationID) {
106+
return nil, fmt.Errorf("invalid stack configuration id: %s", stackConfigurationID)
107+
}
108+
if !validStringID(&stackDeploymentName) {
109+
return nil, fmt.Errorf("invalid stack deployment group name: %s", stackDeploymentName)
110+
}
111+
112+
req, err := s.client.NewRequest("GET", fmt.Sprintf("stack-configurations/%s/stack-deployment-groups/%s", url.PathEscape(stackConfigurationID), url.PathEscape(stackDeploymentName)), nil)
113+
if err != nil {
114+
return nil, err
115+
}
116+
117+
sdg := &StackDeploymentGroup{}
118+
err = req.Do(ctx, sdg)
119+
if err != nil {
120+
return nil, err
121+
}
122+
123+
return sdg, nil
124+
}
125+
103126
// Read retrieves a stack deployment group by its ID.
104127
func (s stackDeploymentGroups) Read(ctx context.Context, stackDeploymentGroupID string) (*StackDeploymentGroup, error) {
105128
if !validStringID(&stackDeploymentGroupID) {

stack_deployment_groups_integration_test.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,6 @@ func TestStackDeploymentGroupsList(t *testing.T) {
7272
require.NotNil(t, sdgl)
7373
require.Len(t, sdgl.Items, 1)
7474
})
75-
76-
t.Run("List with filtering by group name", func(t *testing.T) {
77-
noOptionSdg, err := client.StackDeploymentGroups.List(ctx, stackUpdated.LatestStackConfiguration.ID, nil)
78-
require.NoError(t, err)
79-
require.NotNil(t, noOptionSdg)
80-
require.GreaterOrEqual(t, len(noOptionSdg.Items), 1)
81-
options := &StackDeploymentGroupListOptions{
82-
GroupName: noOptionSdg.Items[0].Name,
83-
}
84-
sdgl, err := client.StackDeploymentGroups.List(ctx, stackUpdated.LatestStackConfiguration.ID, options)
85-
require.NoError(t, err)
86-
require.NotNil(t, sdgl)
87-
require.Equal(t, 1, len(sdgl.Items))
88-
require.Equal(t, noOptionSdg.Items[0].Name, sdgl.Items[0].Name)
89-
})
9075
}
9176

9277
func TestStackDeploymentGroupsRead(t *testing.T) {

0 commit comments

Comments
 (0)