@@ -20,10 +20,11 @@ type deployRequest struct {
2020 Enabled bool `json:"enabled"`
2121 Debug bool `json:"debug"`
2222 SourceCode string `json:"sourceCode"`
23- Action string `json:"action"`
23+ Action model. Action `json:"action"`
2424 FilterCriteria * model.FilterCriteria `json:"filterCriteria,omitempty"`
2525 Secrets []* model.Secret `json:"secrets"`
2626 ProjectKey string `json:"projectKey"`
27+ Version * model.Version `json:"version,omitempty"`
2728}
2829
2930func GetDeployCommand () components.Command {
@@ -35,6 +36,9 @@ func GetDeployCommand() components.Command {
3536 plugins_common .GetServerIdFlag (),
3637 model .GetTimeoutFlag (),
3738 model .GetNoSecretsFlag (),
39+ model .GetChangesVersionFlag (),
40+ model .GetChangesDescriptionFlag (),
41+ model .GetChangesCommitShaFlag (),
3842 },
3943 Action : func (c * components.Context ) error {
4044 server , err := model .GetServerDetails (c )
@@ -71,18 +75,32 @@ func GetDeployCommand() components.Command {
7175 }
7276 }
7377
74- return runDeployCommand (c , manifest , actionMeta , server .GetUrl (), server .GetAccessToken ())
78+ version := & model.Version {
79+ Number : c .GetStringFlagValue (model .FlagChangesVersion ),
80+ Description : c .GetStringFlagValue (model .FlagChangesDescription ),
81+ CommitSha : c .GetStringFlagValue (model .FlagChangesCommitSha ),
82+ }
83+ if ! version .IsEmpty () {
84+ options , err := common .FetchOptions (c , server .GetUrl (), server .GetAccessToken ())
85+ if err != nil {
86+ return err
87+ }
88+ if err = common .ValidateVersion (version , options ); err != nil {
89+ return err
90+ }
91+ }
92+ return runDeployCommand (c , manifest , actionMeta , version , server .GetUrl (), server .GetAccessToken ())
7593 },
7694 }
7795}
7896
79- func runDeployCommand (ctx * components.Context , manifest * model.Manifest , actionMeta * model.ActionMetadata , serverUrl string , token string ) error {
97+ func runDeployCommand (ctx * components.Context , manifest * model.Manifest , actionMeta * model.ActionMetadata , version * model. Version , serverUrl string , token string ) error {
8098 existingWorker , err := common .FetchWorkerDetails (ctx , serverUrl , token , manifest .Name , manifest .ProjectKey )
8199 if err != nil {
82100 return err
83101 }
84102
85- body , err := prepareDeployRequest (ctx , manifest , actionMeta , existingWorker )
103+ body , err := prepareDeployRequest (ctx , manifest , actionMeta , version , existingWorker )
86104 if err != nil {
87105 return err
88106 }
@@ -101,6 +119,7 @@ func runDeployCommand(ctx *components.Context, manifest *model.Manifest, actionM
101119 Body : bodyBytes ,
102120 OkStatuses : []int {http .StatusCreated },
103121 Path : []string {"workers" },
122+ ApiVersion : common .ApiVersionV2 ,
104123 })
105124 if err == nil {
106125 log .Info (fmt .Sprintf ("Worker '%s' deployed" , manifest .Name ))
@@ -116,6 +135,7 @@ func runDeployCommand(ctx *components.Context, manifest *model.Manifest, actionM
116135 Body : bodyBytes ,
117136 OkStatuses : []int {http .StatusNoContent },
118137 Path : []string {"workers" },
138+ ApiVersion : common .ApiVersionV2 ,
119139 })
120140 if err == nil {
121141 log .Info (fmt .Sprintf ("Worker '%s' updated" , manifest .Name ))
@@ -124,7 +144,7 @@ func runDeployCommand(ctx *components.Context, manifest *model.Manifest, actionM
124144 return err
125145}
126146
127- func prepareDeployRequest (ctx * components.Context , manifest * model.Manifest , actionMeta * model.ActionMetadata , existingWorker * model.WorkerDetails ) (* deployRequest , error ) {
147+ func prepareDeployRequest (ctx * components.Context , manifest * model.Manifest , actionMeta * model.ActionMetadata , version * model. Version , existingWorker * model.WorkerDetails ) (* deployRequest , error ) {
128148 sourceCode , err := common .ReadSourceCode (manifest )
129149 if err != nil {
130150 return nil , err
@@ -136,21 +156,20 @@ func prepareDeployRequest(ctx *components.Context, manifest *model.Manifest, act
136156 if ! ctx .GetBoolFlagValue (model .FlagNoSecrets ) {
137157 secrets = common .PrepareSecretsUpdate (manifest , existingWorker )
138158 }
139-
140159 payload := & deployRequest {
141160 Key : manifest .Name ,
142- Action : manifest .Action ,
161+ Action : actionMeta .Action ,
143162 Description : manifest .Description ,
144163 Enabled : manifest .Enabled ,
145164 Debug : manifest .Debug ,
146165 SourceCode : sourceCode ,
147166 Secrets : secrets ,
148167 ProjectKey : manifest .ProjectKey ,
168+ Version : version ,
149169 }
150170
151171 if actionMeta .MandatoryFilter {
152172 payload .FilterCriteria = manifest .FilterCriteria
153173 }
154-
155174 return payload , nil
156175}
0 commit comments