@@ -33,7 +33,18 @@ func generateMessageIDForActionsWorkflowRunStatusEmail(repo *repo_model.Reposito
3333 return fmt .Sprintf ("<%s/actions/runs/%d@%s>" , repo .FullName (), run .Index , setting .Domain )
3434}
3535
36- func composeAndSendActionsWorkflowRunStatusEmail (ctx context.Context , repo * repo_model.Repository , run * actions_model.ActionRun , sender * user_model.User , recipients []* user_model.User ) {
36+ func composeAndSendActionsWorkflowRunStatusEmail (ctx context.Context , repo * repo_model.Repository , run * actions_model.ActionRun , sender * user_model.User , recipients []* user_model.User ) error {
37+ jobs , err := actions_model .GetRunJobsByRunID (ctx , run .ID )
38+ if err != nil {
39+ return err
40+ }
41+ for _ , job := range jobs {
42+ if ! job .Status .IsDone () {
43+ log .Debug ("composeAndSendActionsWorkflowRunStatusEmail: A job is not done. Will not compose and send actions email." )
44+ return nil
45+ }
46+ }
47+
3748 subject := "Run"
3849 switch run .Status {
3950 case actions_model .StatusFailure :
@@ -48,11 +59,6 @@ func composeAndSendActionsWorkflowRunStatusEmail(ctx context.Context, repo *repo
4859 messageID := generateMessageIDForActionsWorkflowRunStatusEmail (repo , run )
4960 metadataHeaders := generateMetadataHeaders (repo )
5061
51- jobs , err := actions_model .GetRunJobsByRunID (ctx , run .ID )
52- if err != nil {
53- log .Error ("GetRunJobsByRunID: %v" , err )
54- return
55- }
5662 sort .SliceStable (jobs , func (i , j int ) bool {
5763 si , sj := jobs [i ].Status , jobs [j ].Status
5864 /*
@@ -111,11 +117,11 @@ func composeAndSendActionsWorkflowRunStatusEmail(ctx context.Context, repo *repo
111117 "Jobs" : convertedJobs ,
112118 "locale" : locale ,
113119 }); err != nil {
114- log .Error ("ExecuteTemplate [%s]: %v" , tplWorkflowRun , err )
115- return
120+ return err
116121 }
117122 msgs := make ([]* sender_service.Message , 0 , len (tos ))
118123 for _ , rec := range tos {
124+ log .Trace ("Sending actions email to %s (UID: %d)" , rec .Name , rec .ID )
119125 msg := sender_service .NewMessageFrom (
120126 rec .Email ,
121127 displayName ,
@@ -135,14 +141,16 @@ func composeAndSendActionsWorkflowRunStatusEmail(ctx context.Context, repo *repo
135141 }
136142 SendAsync (msgs ... )
137143 }
144+
145+ return nil
138146}
139147
140- func MailActionsTrigger (ctx context.Context , sender * user_model.User , repo * repo_model.Repository , run * actions_model.ActionRun ) {
148+ func MailActionsTrigger (ctx context.Context , sender * user_model.User , repo * repo_model.Repository , run * actions_model.ActionRun ) error {
141149 if setting .MailService == nil {
142- return
150+ return nil
143151 }
144- if run .Status .IsSkipped () {
145- return
152+ if ! run . Status . IsDone () || run .Status .IsSkipped () {
153+ return nil
146154 }
147155
148156 recipients := make ([]* user_model.User , 0 )
@@ -151,15 +159,16 @@ func MailActionsTrigger(ctx context.Context, sender *user_model.User, repo *repo
151159 notifyPref , err := user_model .GetUserSetting (ctx , sender .ID ,
152160 user_model .SettingsKeyEmailNotificationGiteaActions , user_model .SettingEmailNotificationGiteaActionsFailureOnly )
153161 if err != nil {
154- log .Error ("GetUserSetting: %v" , err )
155- return
162+ return err
156163 }
157164 if notifyPref == user_model .SettingEmailNotificationGiteaActionsAll || ! run .Status .IsSuccess () && notifyPref != user_model .SettingEmailNotificationGiteaActionsDisabled {
158165 recipients = append (recipients , sender )
159166 }
160167 }
161168
162169 if len (recipients ) > 0 {
163- composeAndSendActionsWorkflowRunStatusEmail (ctx , repo , run , sender , recipients )
170+ log .Debug ("MailActionsTrigger: Initiate email composition" )
171+ return composeAndSendActionsWorkflowRunStatusEmail (ctx , repo , run , sender , recipients )
164172 }
173+ return nil
165174}
0 commit comments