@@ -85,15 +85,23 @@ func (r *Repo) CreateDeployment(c *gin.Context) {
8585 vr , _ := c .Get (KeyRepo )
8686 re := vr .(* ent.Repo )
8787
88- env , err := r .i .GetEnv (ctx , u , re , p . Env )
88+ config , err := r .i .GetConfig (ctx , u , re )
8989 if e .HasErrorCode (err , e .ErrorCodeEntityNotFound ) {
90- r .log .Check (gb .GetZapLogLevel (err ), "The configuration file is not found." ).Write (zap .Error (err ))
91- // To override the HTTP status 422.
90+ r .log .Check (gb .GetZapLogLevel (err ), "Failed to get the configuration." ).Write (zap .Error (err ))
9291 gb .ResponseWithStatusAndError (c , http .StatusUnprocessableEntity , err )
9392 return
94- } else if err != nil {
95- r .log .Check (gb .GetZapLogLevel (err ), "It has failed to get the configuration." ).Write (zap .Error (err ))
96- gb .ResponseWithError (c , err )
93+ }
94+
95+ if err := config .Eval (& vo.EvalValues {}); err != nil {
96+ r .log .Check (gb .GetZapLogLevel (err ), "Failed to evaluate the configuration." ).Write (zap .Error (err ))
97+ gb .ResponseWithStatusAndError (c , http .StatusUnprocessableEntity , err )
98+ return
99+ }
100+
101+ var env * vo.Env
102+ if env = config .GetEnv (p .Env ); env == nil {
103+ r .log .Warn ("The environment is not found." , zap .String ("env" , p .Env ))
104+ gb .ResponseWithStatusAndError (c , http .StatusUnprocessableEntity , e .NewError (e .ErrorCodeConfigUndefinedEnv , nil ))
97105 return
98106 }
99107
@@ -110,7 +118,6 @@ func (r *Repo) CreateDeployment(c *gin.Context) {
110118 return
111119 }
112120
113- // TODO: Migrate the event logic into the interactor.
114121 if _ , err := r .i .CreateEvent (ctx , & ent.Event {
115122 Kind : event .KindDeployment ,
116123 Type : event .TypeCreated ,
@@ -124,6 +131,7 @@ func (r *Repo) CreateDeployment(c *gin.Context) {
124131 d = de
125132 }
126133
134+ r .log .Info ("Start to deploy." , zap .String ("repo" , re .GetFullName ()), zap .String ("env" , p .Env ))
127135 gb .Response (c , http .StatusCreated , d )
128136}
129137
@@ -149,15 +157,23 @@ func (r *Repo) UpdateDeployment(c *gin.Context) {
149157 return
150158 }
151159
152- env , err := r .i .GetEnv (ctx , u , re , d . Env )
160+ config , err := r .i .GetConfig (ctx , u , re )
153161 if e .HasErrorCode (err , e .ErrorCodeEntityNotFound ) {
154- r .log .Check (gb .GetZapLogLevel (err ), "The configuration file is not found." ).Write (zap .Error (err ))
155- // To override the HTTP status 422.
162+ r .log .Check (gb .GetZapLogLevel (err ), "Failed to get the configuration." ).Write (zap .Error (err ))
156163 gb .ResponseWithStatusAndError (c , http .StatusUnprocessableEntity , err )
157164 return
158- } else if err != nil {
159- r .log .Check (gb .GetZapLogLevel (err ), "It has failed to get the configuration." ).Write (zap .Error (err ))
160- gb .ResponseWithError (c , err )
165+ }
166+
167+ if err := config .Eval (& vo.EvalValues {IsRollback : d .IsRollback }); err != nil {
168+ r .log .Check (gb .GetZapLogLevel (err ), "Failed to evaludate the configuration." ).Write (zap .Error (err ))
169+ gb .ResponseWithStatusAndError (c , http .StatusUnprocessableEntity , err )
170+ return
171+ }
172+
173+ var env * vo.Env
174+ if env = config .GetEnv (d .Env ); env == nil {
175+ r .log .Warn ("The environment is not found." , zap .String ("env" , d .Env ))
176+ gb .ResponseWithStatusAndError (c , http .StatusUnprocessableEntity , e .NewError (e .ErrorCodeConfigUndefinedEnv , nil ))
161177 return
162178 }
163179
@@ -180,6 +196,7 @@ func (r *Repo) UpdateDeployment(c *gin.Context) {
180196 d = de
181197 }
182198
199+ r .log .Info ("Start to deploy." , zap .String ("repo" , re .GetFullName ()), zap .Int ("number" , d .Number ))
183200 gb .Response (c , http .StatusOK , d )
184201}
185202
@@ -203,15 +220,23 @@ func (r *Repo) RollbackDeployment(c *gin.Context) {
203220 return
204221 }
205222
206- env , err := r .i .GetEnv (ctx , u , re , d . Env )
223+ config , err := r .i .GetConfig (ctx , u , re )
207224 if e .HasErrorCode (err , e .ErrorCodeEntityNotFound ) {
208- r .log .Check (gb .GetZapLogLevel (err ), "The configuration file is not found." ).Write (zap .Error (err ))
209- // To override the HTTP status 422.
225+ r .log .Check (gb .GetZapLogLevel (err ), "Failed to get the configuration." ).Write (zap .Error (err ))
210226 gb .ResponseWithStatusAndError (c , http .StatusUnprocessableEntity , err )
211227 return
212- } else if err != nil {
213- r .log .Check (gb .GetZapLogLevel (err ), "It has failed to get the configuration." ).Write (zap .Error (err ))
214- gb .ResponseWithError (c , err )
228+ }
229+
230+ if err := config .Eval (& vo.EvalValues {IsRollback : true }); err != nil {
231+ r .log .Check (gb .GetZapLogLevel (err ), "Failed to evaludate the configuration." ).Write (zap .Error (err ))
232+ gb .ResponseWithStatusAndError (c , http .StatusUnprocessableEntity , err )
233+ return
234+ }
235+
236+ var env * vo.Env
237+ if env = config .GetEnv (d .Env ); env == nil {
238+ r .log .Warn ("The environment is not found." , zap .String ("env" , d .Env ))
239+ gb .ResponseWithStatusAndError (c , http .StatusUnprocessableEntity , e .NewError (e .ErrorCodeConfigUndefinedEnv , nil ))
215240 return
216241 }
217242
@@ -242,6 +267,7 @@ func (r *Repo) RollbackDeployment(c *gin.Context) {
242267 d = de
243268 }
244269
270+ r .log .Info ("Start to rollback." , zap .String ("repo" , re .GetFullName ()), zap .Int ("number" , d .Number ))
245271 gb .Response (c , http .StatusCreated , d )
246272}
247273
0 commit comments