Skip to content

Commit

Permalink
Add reaction
Browse files Browse the repository at this point in the history
  • Loading branch information
orangejenny committed Jan 30, 2025
1 parent f756e8a commit adcd359
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/commcare_cloud/commands/deploy/slack.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from enum import Enum
from datetime import datetime

import random
import requests
import re
from clint.textui import puts
from requests import RequestException

Expand All @@ -14,6 +16,10 @@ class Emoji(Enum):
success_reaction = 'white_check_mark'
failure_reaction = 'x'

slow_reaction = random.choice(['snail', 'turtle', 'tortoise_wag'])
medium_reaction = random.choice(['meh', 'meh_blue', 'cat-roomba'])
fast_reaction = random.choice(['racing_car', 'zap', 'dash', 'rocket'])

@property
def code(self):
return f":{self.value}:"
Expand Down Expand Up @@ -78,9 +84,22 @@ 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}"
duration = end - context.start_time

if is_success:
if duration.seconds < 60 * 15:
speed_emoji = Emoji.fast_reaction
elif duration.seconds > 60 * 30:
speed_emoji = Emoji.slow_reaction
else:
speed_emoji = Emoji.medium_reaction
self._post_reaction(thread_ts, speed_emoji)

status = "completed" if is_success else "failed"
duration = re.sub(r'\.\d+', '', str(duration))
message = f"Deploy {status} in {duration}"
self._post_message(message, self._get_text_blocks(message), thread_ts)

def _post_message(self, notification_text, blocks, thread_ts=None):
Expand Down

0 comments on commit adcd359

Please sign in to comment.