Skip to content

Commit

Permalink
Added threaded message to slack when deploy finishes
Browse files Browse the repository at this point in the history
  • Loading branch information
orangejenny committed Jan 29, 2025
1 parent d6adf3b commit f756e8a
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/commcare_cloud/commands/deploy/slack.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from enum import Enum
from datetime import datetime

import requests
from clint.textui import puts
Expand Down Expand Up @@ -77,6 +78,10 @@ def send_deploy_end_message(self, context, is_success):
thread_ts = context.get_meta_value('slack_thread_ts')
reaction_emoji = Emoji.success_reaction if is_success else Emoji.failure_reaction
self._post_reaction(thread_ts, reaction_emoji)
status = "completed" if is_success else "failed"
end = datetime.utcnow()
message = f"Deploy {status} in {end - context.start_time}"
self._post_message(message, self._get_text_blocks(message), thread_ts)

def _post_message(self, notification_text, blocks, thread_ts=None):
data = {
Expand All @@ -91,14 +96,7 @@ def _post_message(self, notification_text, blocks, thread_ts=None):

def _get_message_blocks(self, message, context):
env_name = self.environment.meta_config.deploy_env
return [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": message,
}
},
return self._get_text_blocks(message) + [
{
"type": "context",
"elements": [
Expand All @@ -118,6 +116,15 @@ def _get_message_blocks(self, message, context):
}
]

def _get_text_blocks(self, message):
return [{
"type": "section",
"text": {
"type": "mrkdwn",
"text": message,
}
}]

def _post_reaction(self, thread_ts, emoji):
data = {
"channel": self.channel,
Expand Down

0 comments on commit f756e8a

Please sign in to comment.