@@ -13,6 +13,7 @@ import (
1313 "github.com/gitploy-io/gitploy/model/ent"
1414 "github.com/gitploy-io/gitploy/model/ent/deployment"
1515 "github.com/gitploy-io/gitploy/model/ent/event"
16+ "github.com/gitploy-io/gitploy/model/extent"
1617 "github.com/gitploy-io/gitploy/pkg/e"
1718)
1819
@@ -170,53 +171,52 @@ func (h *Hooks) handleGithubPushEvent(c *gin.Context) {
170171 return
171172 } else if r .Edges .Owner == nil {
172173 h .log .Warn ("The owner is not found." , zap .Int64 ("repo_id" , r .ID ))
173- gb .ResponseWithError (c ,
174- e .NewErrorWithMessage (e .ErrorCodeInternalError , "The owner is not found." , nil ),
175- )
174+ gb .ResponseWithError (c , e .NewErrorWithMessage (e .ErrorCodeInternalError , "The owner is not found." , nil ))
176175 return
177176 }
178177
179- config , err := h .i .GetConfig (ctx , r .Edges .Owner , r )
178+ h .log .Debug ("Get the configuration of the repository." )
179+ config , err := h .i .GetEvaluatedConfig (ctx , r .Edges .Owner , r , & extent.EvalValues {
180+ IsRollback : false ,
181+ })
180182 if err != nil {
181183 h .log .Check (gb .GetZapLogLevel (err ), "Failed to find the configuration file." ).Write (zap .Error (err ))
182184 gb .ResponseWithError (c , err )
183185 return
184186 }
185187
188+ h .log .Debug ("Parse the ref of the hook." , zap .String ("ref" , * evt .Ref ))
189+ typ , ref , err := parseGithubRef (* evt .Ref )
190+ if err != nil {
191+ h .log .Error ("Failed to parse the ref." , zap .Error (err ))
192+ gb .ResponseWithError (c , err )
193+ return
194+ }
195+
196+ // Checks whether the 'auto_deploy_on' field is valid.
186197 for _ , env := range config .Envs {
187- ok , err := env .IsAutoDeployOn (* evt .Ref )
188- if err != nil {
189- h .log .Warn ("Failed to validate the ref is matched with 'auto_deploy_on'." , zap .Error (err ))
190- continue
191- }
192- if ! ok {
193- continue
198+ if _ , err := env .IsAutoDeployOn (* evt .Ref ); err != nil {
199+ h .log .Error ("Failed to validate the ref is matched with 'auto_deploy_on'." , zap .Error (err ))
200+ gb .ResponseWithError (c , err )
201+ return
194202 }
203+ }
195204
196- typ , ref , err := parseGithubRef (* evt .Ref )
197- if err != nil {
198- h .log .Error ("Failed to parse the ref." , zap .Error (err ))
205+ // If it is a ref matching the 'auto_deploy_on' field, Gitploy trigger to deploy.
206+ for _ , env := range config .Envs {
207+ if ok , _ := env .IsAutoDeployOn (* evt .Ref ); ! ok {
208+ h .log .Debug ("Skip the environment, not matched with the ref." , zap .String ("env" , env .Name ), zap .String ("ref" , * evt .Ref ))
199209 continue
200210 }
201211
202212 h .log .Info ("Trigger to deploy the ref." , zap .String ("ref" , * evt .Ref ), zap .String ("environment" , env .Name ))
203- d := & ent.Deployment {
213+ _ , err = h . i . Deploy ( ctx , r . Edges . Owner , r , & ent.Deployment {
204214 Type : typ ,
205215 Ref : ref ,
206216 Env : env .Name ,
207- }
208- d , err = h .i .Deploy (ctx , r .Edges .Owner , r , d , env )
217+ }, env )
209218 if err != nil {
210219 h .log .Error ("Failed to deploy." , zap .Error (err ))
211- continue
212- }
213-
214- if _ , err := h .i .CreateEvent (ctx , & ent.Event {
215- Kind : event .KindDeployment ,
216- Type : event .TypeCreated ,
217- DeploymentID : d .ID ,
218- }); err != nil {
219- h .log .Error ("It has failed to create the event." , zap .Error (err ))
220220 }
221221 }
222222
0 commit comments