mirror of
https://github.com/go-gitea/gitea.git
synced 2025-02-20 11:43:57 +08:00
Notify action added
Signed-off-by: Mayank Mohapatra <125661248+Mayank77maruti@users.noreply.github.com>
This commit is contained in:
parent
ba0805520a
commit
70f02e00ae
@ -204,62 +204,66 @@ func (m *mailNotifier) RepoPendingTransfer(ctx context.Context, doer, newOwner *
|
||||
}
|
||||
}
|
||||
|
||||
// func (m *mailNotifier) ActionRunFinished(ctx context.Context, run *actions_model.ActionRun) {
|
||||
// // Check status first to avoid unnecessary processing
|
||||
// if run.Status != actions_model.StatusSuccess && run.Status != actions_model.StatusFailure {
|
||||
// return
|
||||
// }
|
||||
|
||||
// // Load required attributes after status check
|
||||
// if err := run.LoadAttributes(ctx); err != nil {
|
||||
// log.Error("LoadAttributes: %v", err)
|
||||
// return
|
||||
// }
|
||||
|
||||
// subject := fmt.Sprintf("[%s] Workflow run %s: %s",
|
||||
// run.Repo.FullName(),
|
||||
// run.WorkflowName,
|
||||
// run.Status,
|
||||
// )
|
||||
|
||||
// // Safely handle short commit SHA
|
||||
// commitSHA := run.CommitSHA
|
||||
// if len(commitSHA) > 7 {
|
||||
// commitSHA = commitSHA[:7]
|
||||
// }
|
||||
|
||||
// body := fmt.Sprintf(`Workflow "%s" run #%d has completed with status: %s
|
||||
|
||||
// Repository: %s
|
||||
// Branch: %s
|
||||
// Commit: %s
|
||||
// Triggered by: %s
|
||||
|
||||
// View the run details here: %s`,
|
||||
// run.WorkflowName,
|
||||
// run.Index,
|
||||
// run.Status,
|
||||
// run.Repo.FullName(),
|
||||
// run.RefName,
|
||||
// commitSHA,
|
||||
// run.TriggerUser.Name,
|
||||
// run.HTMLURL(),
|
||||
// )
|
||||
|
||||
// // Send to repo owner if notifications enabled and email present
|
||||
// if run.Repo.Owner.Email != "" &&
|
||||
// run.Repo.Owner.EmailNotificationsPreference != user_model.EmailNotificationsDisabled {
|
||||
// if err := SendMail(ctx, []string{run.Repo.Owner.Email}, subject, body); err != nil {
|
||||
// log.Error("Failed to send email to repo owner %s: %v", run.Repo.Owner.Email, err)
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Send to commit author if different from trigger user and notifications enabled
|
||||
// if run.TriggerUser.ID != run.CommitAuthor.ID &&
|
||||
// run.CommitAuthor.Email != "" &&
|
||||
// run.CommitAuthor.EmailNotificationsPreference != user_model.EmailNotificationsDisabled {
|
||||
// if err := SendMail(ctx, []string{run.CommitAuthor.Email}, subject, body); err != nil {
|
||||
// log.Error("Failed to send email to commit author %s: %v", run.CommitAuthor.Email, err)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
func (m *mailNotifier) ActionRunFinished(ctx context.Context, run *actions_model.ActionRun) {
|
||||
// Check status first to avoid unnecessary processing
|
||||
if run.Status != actions_model.StatusSuccess && run.Status != actions_model.StatusFailure {
|
||||
return
|
||||
}
|
||||
|
||||
// Load required attributes after status check
|
||||
if err := run.LoadAttributes(ctx); err != nil {
|
||||
log.Error("LoadAttributes: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
subject := fmt.Sprintf("[%s] Workflow run %s: %s",
|
||||
run.Repo.FullName(),
|
||||
run.WorkflowName,
|
||||
run.Status,
|
||||
)
|
||||
|
||||
// Safely handle short commit SHA
|
||||
commitSHA := run.CommitSHA
|
||||
if len(commitSHA) > 7 {
|
||||
commitSHA = commitSHA[:7]
|
||||
}
|
||||
|
||||
body := fmt.Sprintf(`Workflow "%s" run #%d has completed with status: %s
|
||||
|
||||
Repository: %s
|
||||
Branch: %s
|
||||
Commit: %s
|
||||
Triggered by: %s
|
||||
|
||||
View the run details here: %s`,
|
||||
run.WorkflowName,
|
||||
run.Index,
|
||||
run.Status,
|
||||
run.Repo.FullName(),
|
||||
run.RefName,
|
||||
commitSHA,
|
||||
run.TriggerUser.Name,
|
||||
run.HTMLURL(),
|
||||
)
|
||||
|
||||
// Send to repo owner if notifications enabled and email present
|
||||
if run.Repo.Owner.Email != "" &&
|
||||
run.Repo.Owner.EmailNotificationsPreference != user_model.EmailNotificationsDisabled {
|
||||
if err := SendMail(ctx, []string{run.Repo.Owner.Email}, subject, body); err != nil {
|
||||
log.Error("Failed to send email to repo owner %s: %v", run.Repo.Owner.Email, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Send to commit author if different from trigger user and notifications enabled
|
||||
if run.TriggerUser.ID != run.CommitAuthor.ID &&
|
||||
run.CommitAuthor.Email != "" &&
|
||||
run.CommitAuthor.EmailNotificationsPreference != user_model.EmailNotificationsDisabled {
|
||||
if err := SendMail(ctx, []string{run.CommitAuthor.Email}, subject, body); err != nil {
|
||||
log.Error("Failed to send email to commit author %s: %v", run.CommitAuthor.Email, err)
|
||||
}
|
||||
}
|
||||
// TODO: send email to related users
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user