@@ -36,7 +36,18 @@ func generateMessageIDForActionsWorkflowRunStatusEmail(repo *repo_model.Reposito
3636 return fmt .Sprintf ("<%s/actions/runs/%d@%s>" , repo .FullName (), run .Index , setting .Domain )
3737}
3838
39- func composeAndSendActionsWorkflowRunStatusEmail (ctx context.Context , repo * repo_model.Repository , run * actions_model.ActionRun , sender * user_model.User , recipients []* user_model.User ) {
39+ func composeAndSendActionsWorkflowRunStatusEmail (ctx context.Context , repo * repo_model.Repository , run * actions_model.ActionRun , sender * user_model.User , recipients []* user_model.User ) error {
40+ jobs , err := actions_model .GetRunJobsByRunID (ctx , run .ID )
41+ if err != nil {
42+ return err
43+ }
44+ for _ , job := range jobs {
45+ if ! job .Status .IsDone () {
46+ log .Debug ("composeAndSendActionsWorkflowRunStatusEmail: A job is not done. Will not compose and send actions email." )
47+ return nil
48+ }
49+ }
50+
4051 var subjectTrString string
4152 switch run .Status {
4253 case actions_model .StatusFailure :
@@ -50,11 +61,6 @@ func composeAndSendActionsWorkflowRunStatusEmail(ctx context.Context, repo *repo
5061 messageID := generateMessageIDForActionsWorkflowRunStatusEmail (repo , run )
5162 metadataHeaders := generateMetadataHeaders (repo )
5263
53- jobs , err := actions_model .GetRunJobsByRunID (ctx , run .ID )
54- if err != nil {
55- log .Error ("GetRunJobsByRunID: %v" , err )
56- return
57- }
5864 sort .SliceStable (jobs , func (i , j int ) bool {
5965 si , sj := jobs [i ].Status , jobs [j ].Status
6066 /*
@@ -115,11 +121,11 @@ func composeAndSendActionsWorkflowRunStatusEmail(ctx context.Context, repo *repo
115121 "Jobs" : convertedJobs ,
116122 "locale" : locale ,
117123 }); err != nil {
118- log .Error ("ExecuteTemplate [%s]: %v" , tplWorkflowRun , err )
119- return
124+ return err
120125 }
121126 msgs := make ([]* sender_service.Message , 0 , len (tos ))
122127 for _ , rec := range tos {
128+ log .Trace ("Sending actions email to %s (UID: %d)" , rec .Name , rec .ID )
123129 msg := sender_service .NewMessageFrom (
124130 rec .Email ,
125131 displayName ,
@@ -139,14 +145,16 @@ func composeAndSendActionsWorkflowRunStatusEmail(ctx context.Context, repo *repo
139145 }
140146 SendAsync (msgs ... )
141147 }
148+
149+ return nil
142150}
143151
144- func MailActionsTrigger (ctx context.Context , sender * user_model.User , repo * repo_model.Repository , run * actions_model.ActionRun ) {
152+ func MailActionsTrigger (ctx context.Context , sender * user_model.User , repo * repo_model.Repository , run * actions_model.ActionRun ) error {
145153 if setting .MailService == nil {
146- return
154+ return nil
147155 }
148- if run .Status .IsSkipped () {
149- return
156+ if ! run . Status . IsDone () || run .Status .IsSkipped () {
157+ return nil
150158 }
151159
152160 recipients := make ([]* user_model.User , 0 )
@@ -155,15 +163,16 @@ func MailActionsTrigger(ctx context.Context, sender *user_model.User, repo *repo
155163 notifyPref , err := user_model .GetUserSetting (ctx , sender .ID ,
156164 user_model .SettingsKeyEmailNotificationGiteaActions , user_model .SettingEmailNotificationGiteaActionsFailureOnly )
157165 if err != nil {
158- log .Error ("GetUserSetting: %v" , err )
159- return
166+ return err
160167 }
161168 if notifyPref == user_model .SettingEmailNotificationGiteaActionsAll || ! run .Status .IsSuccess () && notifyPref != user_model .SettingEmailNotificationGiteaActionsDisabled {
162169 recipients = append (recipients , sender )
163170 }
164171 }
165172
166173 if len (recipients ) > 0 {
167- composeAndSendActionsWorkflowRunStatusEmail (ctx , repo , run , sender , recipients )
174+ log .Debug ("MailActionsTrigger: Initiate email composition" )
175+ return composeAndSendActionsWorkflowRunStatusEmail (ctx , repo , run , sender , recipients )
168176 }
177+ return nil
169178}
0 commit comments