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

Make slack deploy diff work for longer diffs as well #6460

Merged
merged 2 commits into from
Jan 10, 2025
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
30 changes: 25 additions & 5 deletions src/commcare_cloud/commands/deploy/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,31 @@ def send_deploy_start_message(self, context):
response = self._post_message(message, blocks)
context.set_meta_value('slack_thread_ts', response["ts"])
if self.environment.fab_settings_config.generate_deploy_diffs:
diff_blocks = [{
"type": "section",
"text": {"type": "mrkdwn", "text": context.diff.get_slack_diff()}
}]
self._post_message("Deploy diff", diff_blocks, thread_ts=response["ts"])
diff_text = context.diff.get_slack_diff()
for chunked_diff_text in self._chunk_diff(diff_text):
diff_blocks = [{
"type": "section",
"text": {"type": "mrkdwn", "text": chunked_diff_text}
}]
self._post_message("Deploy diff", diff_blocks, thread_ts=response["ts"])

def _chunk_diff(self, diff_text, chunk_size=2800):
# Slack has a limit of 3000 characters per message block
# https://api.slack.com/reference/block-kit/blocks#section_fields
diff_lines = diff_text.split('\n')
current_chunk = []
current_length = 0
for line in diff_lines:
line_length = len(line) + 1
if current_length + line_length > chunk_size:
yield '\n'.join(current_chunk)
current_chunk = [line]
current_length = line_length
else:
current_chunk.append(line)
current_length += line_length
if current_chunk:
yield '\n'.join(current_chunk)

def send_deploy_end_message(self, context, is_success):
thread_ts = context.get_meta_value('slack_thread_ts')
Expand Down
Loading