99from slack_sdk import WebClient
1010from slack_sdk .errors import SlackApiError
1111
12+ from redis_release .models import SlackFormat
1213from redis_release .state_display import DisplayModel , StepStatus
1314
1415from .bht .state import (
@@ -44,6 +45,7 @@ def init_slack_printer(
4445 slack_channel_id : Optional [str ],
4546 thread_ts : Optional [str ] = None ,
4647 reply_broadcast : bool = False ,
48+ slack_format : SlackFormat = SlackFormat .DEFAULT ,
4749) -> "SlackStatePrinter" :
4850 """Initialize SlackStatePrinter with validation.
4951
@@ -52,6 +54,7 @@ def init_slack_printer(
5254 slack_channel_id: Slack channel ID to post to
5355 thread_ts: Optional thread timestamp to post messages in a thread
5456 reply_broadcast: If True and thread_ts is set, also show in main channel
57+ slack_format: Slack message format (default or one-step)
5558
5659 Returns:
5760 SlackStatePrinter instance
@@ -69,7 +72,9 @@ def init_slack_printer(
6972 "Slack token not provided. Use slack_token argument or set SLACK_BOT_TOKEN environment variable"
7073 )
7174
72- return SlackStatePrinter (token , slack_channel_id , thread_ts , reply_broadcast )
75+ return SlackStatePrinter (
76+ token , slack_channel_id , thread_ts , reply_broadcast , slack_format
77+ )
7378
7479
7580class SlackStatePrinter :
@@ -81,6 +86,7 @@ def __init__(
8186 slack_channel_id : str ,
8287 thread_ts : Optional [str ] = None ,
8388 reply_broadcast : bool = False ,
89+ slack_format : SlackFormat = SlackFormat .DEFAULT ,
8490 ):
8591 """Initialize the Slack printer.
8692
@@ -89,11 +95,13 @@ def __init__(
8995 slack_channel_id: Slack channel ID to post messages to
9096 thread_ts: Optional thread timestamp to post messages in a thread
9197 reply_broadcast: If True and thread_ts is set, also show in main channel
98+ slack_format: Slack message format (default or one-step)
9299 """
93100 self .client = WebClient (token = slack_token )
94101 self .channel_id : str = slack_channel_id
95102 self .thread_ts = thread_ts
96103 self .reply_broadcast = reply_broadcast
104+ self .slack_format = slack_format
97105 self .message_ts : Optional [str ] = None
98106 self .last_blocks_json : Optional [str ] = None
99107 self .started_at = datetime .now (timezone .utc )
@@ -409,16 +417,31 @@ def _format_steps_for_slack(
409417 details : List [str ] = []
410418 details .append (f"*{ prefix } *" )
411419
412- for step_status , step_name , step_message in steps :
413- if step_status == StepStatus .SUCCEEDED :
414- details .append (f"• ✅ { step_name } " )
415- elif step_status == StepStatus .RUNNING :
416- details .append (f"• ⏳ { step_name } " )
417- elif step_status == StepStatus .NOT_STARTED :
418- details .append (f"• ⚪ { step_name } " )
419- else : # FAILED or INCORRECT
420- msg = f" ({ step_message } )" if step_message else ""
421- details .append (f"• ❌ { step_name } { msg } " )
422- break
420+ # If one-step format, only show the last step
421+ if self .slack_format == SlackFormat .ONE_STEP :
422+ if steps :
423+ step_status , step_name , step_message = steps [- 1 ]
424+ if step_status == StepStatus .SUCCEEDED :
425+ details .append (f"• ✅ { step_name } " )
426+ elif step_status == StepStatus .RUNNING :
427+ details .append (f"• ⏳ { step_name } " )
428+ elif step_status == StepStatus .NOT_STARTED :
429+ details .append (f"• ⚪ { step_name } " )
430+ else : # FAILED or INCORRECT
431+ msg = f" ({ step_message } )" if step_message else ""
432+ details .append (f"• ❌ { step_name } { msg } " )
433+ else :
434+ # Default format: show all steps
435+ for step_status , step_name , step_message in steps :
436+ if step_status == StepStatus .SUCCEEDED :
437+ details .append (f"• ✅ { step_name } " )
438+ elif step_status == StepStatus .RUNNING :
439+ details .append (f"• ⏳ { step_name } " )
440+ elif step_status == StepStatus .NOT_STARTED :
441+ details .append (f"• ⚪ { step_name } " )
442+ else : # FAILED or INCORRECT
443+ msg = f" ({ step_message } )" if step_message else ""
444+ details .append (f"• ❌ { step_name } { msg } " )
445+ break
423446
424447 return details
0 commit comments