Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that SMTP message body is not empty #6313

Merged
merged 4 commits into from
Jun 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions src/commcare_cloud/commands/deploy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,30 @@ def send_deploy_start_email(environment, context):
and context.revision is not None
)
env_name = environment.meta_config.deploy_env
subject = f"{context.user} has initiated a {context.service_name} deploy to {env_name}"
message = f"{context.user} has initiated a {context.service_name} deploy to {env_name}"
prefix = ""
if is_nonstandard_deploy_time:
subject += " outside maintenance window"
message += " outside maintenance window"
prefix = "ATTENTION: "
if is_non_default_branch:
subject += f" with non-default branch '{context.revision}'"
message += f" with non-default branch '{context.revision}'"
prefix = "ATTENTION: "
subject = f"{prefix}{subject}"
message = f"{prefix}{message}"

send_email(
environment,
subject=subject,
subject=message,
message=message,
)


def record_deploy_failed(environment, context):
notify_slack_deploy_end(environment, context, is_success=False)
message = f"{context.service_name} deploy to {environment.name} failed"
send_email(
environment,
subject=f"{context.service_name} deploy to {environment.name} failed",
subject=message,
message=message,
)


Expand All @@ -96,16 +99,19 @@ def announce_deploy_success(environment, context):
)


def send_email(environment, subject, message='', to_admins=True, recipients=None):
def send_email(environment, subject, message, to_admins=True, recipients=None):
"""
Call a Django management command to send an email.

:param environment: The Environement object
:param environment: The Environment object
:param subject: Email subject
:param message: Email message
:param message: Email message body
:param to_admins: True if mail should be sent to Django admins
:param recipients: List of additional addresses to send mail to
"""
if not message:
raise ValueError('Some cloud hosting providers require a message body')

if environment.fab_settings_config.email_enabled:
print(color_summary(f">> Sending email: {subject}"))
args = [
Expand Down
Loading