Skip to content

Commit

Permalink
Notify action added
Browse files Browse the repository at this point in the history
Signed-off-by: Mayank Mohapatra <125661248+Mayank77maruti@users.noreply.github.com>
  • Loading branch information
Mayank77maruti committed Feb 14, 2025
1 parent 70f02e0 commit 95ee4c6
Showing 1 changed file with 57 additions and 61 deletions.
118 changes: 57 additions & 61 deletions services/mailer/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,66 +204,62 @@ 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) {
// TODO: send email to related users
// 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,

Check failure on line 221 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / backend

run.WorkflowName undefined (type *actions.ActionRun has no field or method WorkflowName)

Check failure on line 221 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-sqlite

run.WorkflowName undefined (type *actions.ActionRun has no field or method WorkflowName)

Check failure on line 221 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-mysql

run.WorkflowName undefined (type *actions.ActionRun has no field or method WorkflowName)

Check failure on line 221 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-mssql

run.WorkflowName undefined (type *actions.ActionRun has no field or method WorkflowName)

Check failure on line 221 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-pgsql

run.WorkflowName undefined (type *actions.ActionRun has no field or method WorkflowName)

Check failure on line 221 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-unit

run.WorkflowName undefined (type *actions.ActionRun has no field or method WorkflowName)

Check failure on line 221 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-e2e

run.WorkflowName undefined (type *actions.ActionRun has no field or method WorkflowName)

Check failure on line 221 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / lint-go-windows

run.WorkflowName undefined (type *actions.ActionRun has no field or method WorkflowName)

Check failure on line 221 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / lint-go-gogit

run.WorkflowName undefined (type *actions.ActionRun has no field or method WorkflowName)

Check failure on line 221 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / lint-backend

run.WorkflowName undefined (type *actions.ActionRun has no field or method 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,

Check failure on line 239 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / backend

run.WorkflowName undefined (type *actions.ActionRun has no field or method WorkflowName)

Check failure on line 239 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-sqlite

run.WorkflowName undefined (type *actions.ActionRun has no field or method WorkflowName)

Check failure on line 239 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-mysql

run.WorkflowName undefined (type *actions.ActionRun has no field or method WorkflowName)

Check failure on line 239 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-mssql

run.WorkflowName undefined (type *actions.ActionRun has no field or method WorkflowName)

Check failure on line 239 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-pgsql

run.WorkflowName undefined (type *actions.ActionRun has no field or method WorkflowName)

Check failure on line 239 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-unit

run.WorkflowName undefined (type *actions.ActionRun has no field or method WorkflowName)

Check failure on line 239 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-e2e

run.WorkflowName undefined (type *actions.ActionRun has no field or method WorkflowName)

Check failure on line 239 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / lint-go-windows

run.WorkflowName undefined (type *actions.ActionRun has no field or method WorkflowName)

Check failure on line 239 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / lint-go-gogit

run.WorkflowName undefined (type *actions.ActionRun has no field or method WorkflowName)

Check failure on line 239 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / lint-backend

run.WorkflowName undefined (type *actions.ActionRun has no field or method WorkflowName)
run.Index,
run.Status,
run.Repo.FullName(),
run.RefName,

Check failure on line 243 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / backend

run.RefName undefined (type *actions.ActionRun has no field or method RefName)

Check failure on line 243 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-sqlite

run.RefName undefined (type *actions.ActionRun has no field or method RefName)

Check failure on line 243 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-mysql

run.RefName undefined (type *actions.ActionRun has no field or method RefName)

Check failure on line 243 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-mssql

run.RefName undefined (type *actions.ActionRun has no field or method RefName)

Check failure on line 243 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-pgsql

run.RefName undefined (type *actions.ActionRun has no field or method RefName)

Check failure on line 243 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-unit

run.RefName undefined (type *actions.ActionRun has no field or method RefName)

Check failure on line 243 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-e2e

run.RefName undefined (type *actions.ActionRun has no field or method RefName)

Check failure on line 243 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / lint-go-windows

run.RefName undefined (type *actions.ActionRun has no field or method RefName)

Check failure on line 243 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / lint-go-gogit

run.RefName undefined (type *actions.ActionRun has no field or method RefName)

Check failure on line 243 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / lint-backend

run.RefName undefined (type *actions.ActionRun has no field or method 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 {

Check failure on line 252 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / backend

undefined: SendMail

Check failure on line 252 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-sqlite

undefined: SendMail

Check failure on line 252 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-mysql

undefined: SendMail

Check failure on line 252 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-mssql

undefined: SendMail

Check failure on line 252 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-pgsql

undefined: SendMail

Check failure on line 252 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-unit

undefined: SendMail

Check failure on line 252 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-e2e

undefined: SendMail

Check failure on line 252 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / lint-go-windows

undefined: SendMail

Check failure on line 252 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / lint-go-gogit

undefined: SendMail

Check failure on line 252 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / lint-backend

undefined: SendMail
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 &&

Check failure on line 258 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / backend

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 258 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-sqlite

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 258 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-mysql

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 258 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-mssql

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 258 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-pgsql

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 258 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-unit

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 258 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-e2e

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 258 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / lint-go-windows

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 258 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / lint-go-gogit

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 258 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / lint-backend

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)
run.CommitAuthor.Email != "" &&

Check failure on line 259 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / backend

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 259 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-sqlite

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 259 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-mysql

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 259 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-mssql

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 259 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-pgsql

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 259 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-unit

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 259 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-e2e

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 259 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / lint-go-windows

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 259 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / lint-go-gogit

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 259 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / lint-backend

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)
run.CommitAuthor.EmailNotificationsPreference != user_model.EmailNotificationsDisabled {

Check failure on line 260 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / backend

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 260 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-sqlite

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 260 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-mysql

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 260 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-mssql

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 260 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-pgsql

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 260 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-unit

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 260 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-e2e

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 260 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / lint-go-windows

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 260 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / lint-go-gogit

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 260 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / lint-backend

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)
if err := SendMail(ctx, []string{run.CommitAuthor.Email}, subject, body); err != nil {

Check failure on line 261 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / backend

undefined: SendMail

Check failure on line 261 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / backend

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 261 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-sqlite

undefined: SendMail

Check failure on line 261 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-sqlite

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 261 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-mysql

undefined: SendMail

Check failure on line 261 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-mysql

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 261 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-mssql

undefined: SendMail

Check failure on line 261 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-mssql

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 261 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-pgsql

undefined: SendMail

Check failure on line 261 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-pgsql

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 261 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-unit

undefined: SendMail

Check failure on line 261 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-unit

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 261 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-e2e

undefined: SendMail

Check failure on line 261 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-e2e

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 261 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / lint-go-windows

undefined: SendMail

Check failure on line 261 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / lint-go-windows

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 261 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / lint-go-gogit

undefined: SendMail

Check failure on line 261 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / lint-go-gogit

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 261 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / lint-backend

undefined: SendMail

Check failure on line 261 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / lint-backend

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)
log.Error("Failed to send email to commit author %s: %v", run.CommitAuthor.Email, err)

Check failure on line 262 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / backend

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 262 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-sqlite

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 262 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-mysql

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 262 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-mssql

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 262 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-pgsql

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 262 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-unit

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)

Check failure on line 262 in services/mailer/notify.go

View workflow job for this annotation

GitHub Actions / test-e2e

run.CommitAuthor undefined (type *actions.ActionRun has no field or method CommitAuthor)
}
}
}

0 comments on commit 95ee4c6

Please sign in to comment.