@@ -13,6 +13,7 @@ import (
13
13
"github.com/gitploy-io/gitploy/model/ent"
14
14
"github.com/gitploy-io/gitploy/model/ent/deployment"
15
15
"github.com/gitploy-io/gitploy/model/ent/event"
16
+ "github.com/gitploy-io/gitploy/model/extent"
16
17
"github.com/gitploy-io/gitploy/pkg/e"
17
18
)
18
19
@@ -170,53 +171,52 @@ func (h *Hooks) handleGithubPushEvent(c *gin.Context) {
170
171
return
171
172
} else if r .Edges .Owner == nil {
172
173
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 ))
176
175
return
177
176
}
178
177
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
+ })
180
182
if err != nil {
181
183
h .log .Check (gb .GetZapLogLevel (err ), "Failed to find the configuration file." ).Write (zap .Error (err ))
182
184
gb .ResponseWithError (c , err )
183
185
return
184
186
}
185
187
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.
186
197
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
194
202
}
203
+ }
195
204
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 ))
199
209
continue
200
210
}
201
211
202
212
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 {
204
214
Type : typ ,
205
215
Ref : ref ,
206
216
Env : env .Name ,
207
- }
208
- d , err = h .i .Deploy (ctx , r .Edges .Owner , r , d , env )
217
+ }, env )
209
218
if err != nil {
210
219
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 ))
220
220
}
221
221
}
222
222
0 commit comments