@@ -7,14 +7,15 @@ import (
77 "net/http"
88 "strconv"
99
10+ apphttp "github.com/jfrog/jfrog-cli-application/apptrust/http"
1011 "github.com/jfrog/jfrog-cli-application/apptrust/service"
1112 "github.com/jfrog/jfrog-client-go/utils/log"
1213
1314 "github.com/jfrog/jfrog-cli-application/apptrust/model"
1415)
1516
1617type VersionService interface {
17- CreateAppVersion (ctx service.Context , request * model.CreateAppVersionRequest , sync bool ) error
18+ CreateAppVersion (ctx service.Context , request * model.CreateAppVersionRequest , sync , dryRun bool ) error
1819 PromoteAppVersion (ctx service.Context , applicationKey string , version string , payload * model.PromoteAppVersionRequest , sync bool ) error
1920 ReleaseAppVersion (ctx service.Context , applicationKey string , version string , request * model.ReleaseAppVersionRequest , sync bool ) error
2021 RollbackAppVersion (ctx service.Context , applicationKey string , version string , request * model.RollbackAppVersionRequest , sync bool ) error
@@ -29,24 +30,20 @@ func NewVersionService() VersionService {
2930 return & versionService {}
3031}
3132
32- func (vs * versionService ) CreateAppVersion (ctx service.Context , request * model.CreateAppVersionRequest , sync bool ) error {
33+ func (vs * versionService ) CreateAppVersion (ctx service.Context , request * model.CreateAppVersionRequest , sync , dryRun bool ) error {
3334 endpoint := fmt .Sprintf ("/v1/applications/%s/versions/" , request .ApplicationKey )
34- response , responseBody , err := ctx .GetHttpClient ().Post (endpoint , request , map [string ]string {"async" : strconv .FormatBool (! sync )})
35+ response , responseBody , err := ctx .GetHttpClient ().Post (endpoint , request ,
36+ map [string ]string {"async" : strconv .FormatBool (! sync ), "dry_run" : strconv .FormatBool (dryRun )})
3537 if err != nil {
3638 return err
3739 }
3840
39- expectedStatusCode := http .StatusCreated
40- if ! sync {
41- expectedStatusCode = http .StatusAccepted
42- }
43-
44- if response .StatusCode != expectedStatusCode {
41+ if ! apphttp .IsSuccessStatusCode (response .StatusCode ) {
4542 return fmt .Errorf ("failed to create app version. Status code: %d. \n %s" ,
4643 response .StatusCode , responseBody )
4744 }
4845
49- log . Info ( "Application version created successfully." )
46+ logSuccessMessage ( sync , request , dryRun )
5047 log .Output (string (responseBody ))
5148 return nil
5249}
@@ -58,7 +55,7 @@ func (vs *versionService) PromoteAppVersion(ctx service.Context, applicationKey,
5855 return err
5956 }
6057
61- if response .StatusCode >= http . StatusBadRequest {
58+ if ! apphttp . IsSuccessStatusCode ( response .StatusCode ) {
6259 return fmt .Errorf ("failed to promote app version. Status code: %d. \n %s" ,
6360 response .StatusCode , responseBody )
6461 }
@@ -74,7 +71,7 @@ func (vs *versionService) ReleaseAppVersion(ctx service.Context, applicationKey,
7471 return err
7572 }
7673
77- if response .StatusCode >= http . StatusBadRequest {
74+ if ! apphttp . IsSuccessStatusCode ( response .StatusCode ) {
7875 return fmt .Errorf ("failed to release app version. Status code: %d. \n %s" ,
7976 response .StatusCode , responseBody )
8077 }
@@ -90,13 +87,7 @@ func (vs *versionService) RollbackAppVersion(ctx service.Context, applicationKey
9087 return err
9188 }
9289
93- // Validate status code based on sync mode
94- expectedStatusCode := http .StatusAccepted
95- if sync {
96- expectedStatusCode = http .StatusOK
97- }
98-
99- if response .StatusCode != expectedStatusCode {
90+ if ! apphttp .IsSuccessStatusCode (response .StatusCode ) {
10091 return fmt .Errorf ("failed to rollback app version. Status code: %d. \n %s" ,
10192 response .StatusCode , responseBody )
10293 }
@@ -165,3 +156,13 @@ func (vs *versionService) UpdateAppVersionSources(ctx service.Context, applicati
165156 log .Output (string (responseBody ))
166157 return nil
167158}
159+
160+ func logSuccessMessage (sync bool , request * model.CreateAppVersionRequest , dryRun bool ) {
161+ if ! sync {
162+ log .Info (fmt .Sprintf ("Application version creation initiated: %s:%s" , request .ApplicationKey , request .Version ))
163+ } else if dryRun {
164+ log .Info (fmt .Sprintf ("Dry run successful for application version: %s:%s" , request .ApplicationKey , request .Version ))
165+ } else {
166+ log .Info (fmt .Sprintf ("Application version created successfully: %s:%s" , request .ApplicationKey , request .Version ))
167+ }
168+ }
0 commit comments