Skip to content

Commit 1884307

Browse files
committed
Refactor PromoteAppVersionRequest to use CommonPromoteAppVersion for improved structure and readability
1 parent 03655ee commit 1884307

File tree

5 files changed

+45
-28
lines changed

5 files changed

+45
-28
lines changed

apptrust/commands/version/promote_app_version_cmd.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,13 @@ func (pv *promoteAppVersionCommand) buildRequestPayload(ctx *components.Context)
8181
}
8282

8383
return &model.PromoteAppVersionRequest{
84-
Stage: stage,
85-
PromotionType: promotionType,
86-
IncludedRepositoryKeys: includedRepos,
87-
ExcludedRepositoryKeys: excludedRepos,
88-
ArtifactAdditionalProperties: artifactProps,
84+
Stage: stage,
85+
CommonPromoteAppVersion: model.CommonPromoteAppVersion{
86+
PromotionType: promotionType,
87+
IncludedRepositoryKeys: includedRepos,
88+
ExcludedRepositoryKeys: excludedRepos,
89+
ArtifactAdditionalProperties: artifactProps,
90+
},
8991
}, nil
9092
}
9193

apptrust/commands/version/promote_app_version_cmd_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ func TestPromoteAppVersionCommand_Run_Error(t *testing.T) {
6868
requestPayload := &model.PromoteAppVersionRequest{
6969
Stage: "prod",
7070
}
71+
sync := true
7172
expectedError := errors.New("service error occurred")
7273

7374
mockVersionService := mockversions.NewMockVersionService(ctrl)
74-
mockVersionService.EXPECT().PromoteAppVersion(gomock.Any(), applicationKey, version, requestPayload, false).
75+
mockVersionService.EXPECT().PromoteAppVersion(gomock.Any(), applicationKey, version, requestPayload, sync).
7576
Return(expectedError).Times(1)
7677

7778
cmd := &promoteAppVersionCommand{
@@ -80,7 +81,7 @@ func TestPromoteAppVersionCommand_Run_Error(t *testing.T) {
8081
applicationKey: applicationKey,
8182
version: version,
8283
requestPayload: requestPayload,
83-
sync: false,
84+
sync: sync,
8485
}
8586

8687
err := cmd.Run()

apptrust/model/promote_app_version_request.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ var PromotionTypeValues = []string{
1414
PromotionTypeMove,
1515
}
1616

17-
type PromoteAppVersionRequest struct {
18-
Stage string `json:"stage"`
17+
type CommonPromoteAppVersion struct {
1918
PromotionType string `json:"promotion_type,omitempty"`
2019
IncludedRepositoryKeys []string `json:"included_repository_keys,omitempty"`
2120
ExcludedRepositoryKeys []string `json:"excluded_repository_keys,omitempty"`
2221
ArtifactAdditionalProperties map[string]string `json:"artifact_additional_properties,omitempty"`
2322
}
23+
24+
type PromoteAppVersionRequest struct {
25+
CommonPromoteAppVersion
26+
Stage string `json:"stage"`
27+
}

apptrust/model/release_app_version_request.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
package model
22

3-
const (
4-
ReleaseStage = "PROD"
5-
)
6-
3+
// ReleaseAppVersionRequest represents a request to release an application version to production.
4+
// This struct reuses CommonPromoteAppVersion for consistency with PromoteAppVersionRequest.
5+
// A release is functionally promoted with a hardcoded stage ("prod") set by the backend,
6+
// so the stage is not included here.
7+
// This separation improves readability and intent in the codebase.
78
type ReleaseAppVersionRequest struct {
8-
PromoteAppVersionRequest
9+
CommonPromoteAppVersion
910
}
1011

12+
// NewReleaseAppVersionRequest constructs a ReleaseAppVersionRequest.
13+
// The provided parameters are identical to those used for promotion, but the stage is always production.
1114
func NewReleaseAppVersionRequest(
1215
promotionType string,
1316
includedRepositoryKeys []string,
1417
excludedRepositoryKeys []string,
1518
artifactProperties map[string]string,
1619
) *ReleaseAppVersionRequest {
1720
return &ReleaseAppVersionRequest{
18-
PromoteAppVersionRequest: PromoteAppVersionRequest{
19-
Stage: ReleaseStage,
21+
CommonPromoteAppVersion: CommonPromoteAppVersion{
2022
PromotionType: promotionType,
2123
IncludedRepositoryKeys: includedRepositoryKeys,
2224
ExcludedRepositoryKeys: excludedRepositoryKeys,

apptrust/service/versions/version_service_test.go

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,12 @@ func TestPromoteAppVersion(t *testing.T) {
9797
applicationKey: "test-app",
9898
version: "1.0.0",
9999
payload: &model.PromoteAppVersionRequest{
100-
Stage: "prod",
101-
PromotionType: model.PromotionTypeCopy,
102-
IncludedRepositoryKeys: []string{"repo1", "repo2"},
103-
ExcludedRepositoryKeys: []string{"repo3"},
100+
Stage: "prod",
101+
CommonPromoteAppVersion: model.CommonPromoteAppVersion{
102+
PromotionType: model.PromotionTypeCopy,
103+
IncludedRepositoryKeys: []string{"repo1", "repo2"},
104+
ExcludedRepositoryKeys: []string{"repo3"},
105+
},
104106
},
105107
sync: true,
106108
expectedEndpoint: "/v1/applications/test-app/versions/1.0.0/promote",
@@ -114,10 +116,12 @@ func TestPromoteAppVersion(t *testing.T) {
114116
applicationKey: "test-app",
115117
version: "1.0.0",
116118
payload: &model.PromoteAppVersionRequest{
117-
Stage: "prod",
118-
PromotionType: model.PromotionTypeCopy,
119-
IncludedRepositoryKeys: []string{"repo1", "repo2"},
120-
ExcludedRepositoryKeys: []string{"repo3"},
119+
Stage: "prod",
120+
CommonPromoteAppVersion: model.CommonPromoteAppVersion{
121+
PromotionType: model.PromotionTypeCopy,
122+
IncludedRepositoryKeys: []string{"repo1", "repo2"},
123+
ExcludedRepositoryKeys: []string{"repo3"},
124+
},
121125
},
122126
sync: false,
123127
expectedEndpoint: "/v1/applications/test-app/versions/1.0.0/promote",
@@ -131,8 +135,10 @@ func TestPromoteAppVersion(t *testing.T) {
131135
applicationKey: "test-app",
132136
version: "1.0.0",
133137
payload: &model.PromoteAppVersionRequest{
134-
Stage: "prod",
135-
PromotionType: model.PromotionTypeCopy,
138+
Stage: "prod",
139+
CommonPromoteAppVersion: model.CommonPromoteAppVersion{
140+
PromotionType: model.PromotionTypeCopy,
141+
},
136142
},
137143
sync: true,
138144
expectedEndpoint: "/v1/applications/test-app/versions/1.0.0/promote",
@@ -146,8 +152,10 @@ func TestPromoteAppVersion(t *testing.T) {
146152
applicationKey: "test-app",
147153
version: "1.0.0",
148154
payload: &model.PromoteAppVersionRequest{
149-
Stage: "prod",
150-
PromotionType: model.PromotionTypeCopy,
155+
Stage: "prod",
156+
CommonPromoteAppVersion: model.CommonPromoteAppVersion{
157+
PromotionType: model.PromotionTypeCopy,
158+
},
151159
},
152160
sync: false,
153161
expectedEndpoint: "/v1/applications/test-app/versions/1.0.0/promote",

0 commit comments

Comments
 (0)