@@ -30,21 +30,8 @@ def _getToolchainLink() -> str:
3030 return toolchainLink
3131 return ""
3232
33- def _broadcast (channels : str , message : list ):
34- channelList = [ch .strip () for ch in channels .split ("," )]
35- responses = []
36- for channel in channelList :
37- try :
38- if channel :
39- response = SlackUtil .postMessageBlocks (channel , message )
40- responses .append (response .data .get ("ok" , False ))
41- except Exception as e :
42- print (f"Failed to send message to channel { channel } : { e } " )
43- responses .append (False )
44- return all (responses ) if responses else True
45-
4633
47- def notifyProvisionFyre (channels : str , rc : int ) -> bool :
34+ def notifyProvisionFyre (channels : list [ str ] , rc : int , additionalMsg : str = "" ) -> bool :
4835 """Send Slack notification about Fyre OCP cluster provisioning status."""
4936 name = _getClusterName ()
5037 toolchainLink = _getToolchainLink ()
@@ -64,16 +51,21 @@ def notifyProvisionFyre(channels: str, rc: int) -> bool:
6451 SlackUtil .buildSection (f"- Username: `{ username } `\n - Password: `{ password } `" ),
6552 SlackUtil .buildSection (f"<https://beta.fyre.ibm.com/development/vms|Fyre Dashboard>{ toolchainLink } " )
6653 ]
54+ if additionalMsg :
55+ message .append (SlackUtil .buildSection (additionalMsg ))
6756 else :
6857 message = [
6958 SlackUtil .buildHeader (f":glyph-fail: Your IBM DevIT Fyre OCP cluster ({ name } ) failed to deploy" ),
7059 SlackUtil .buildSection (f"<https://beta.fyre.ibm.com/development/vms|Fyre Dashboard>{ toolchainLink } " )
7160 ]
72-
73- return _broadcast (channels , message )
61+
62+ response = SlackUtil .postMessageBlocks (channels , message )
63+ if isinstance (response , list ):
64+ return all ([res .data .get ("ok" , False ) for res in response ])
65+ return response .data .get ("ok" , False )
7466
7567
76- def notifyProvisionRoks (channels : str , rc : int , additionalDetails : str = "" ) -> bool :
68+ def notifyProvisionRoks (channels : list [ str ] , rc : int , additionalMsg : str = "" ) -> bool :
7769 """Send Slack notification about ROKS cluster provisioning status."""
7870 name = _getClusterName ()
7971 toolchainLink = _getToolchainLink ()
@@ -89,15 +81,18 @@ def notifyProvisionRoks(channels: str, rc: int, additionalDetails: str = "") ->
8981 SlackUtil .buildSection (f"{ url } " ),
9082 SlackUtil .buildSection (f"<https://cloud.ibm.com/kubernetes/clusters|IBM Cloud Dashboard>{ toolchainLink } " )
9183 ]
92- if additionalDetails != "" :
93- message .append (SlackUtil .buildSection (additionalDetails ))
84+ if additionalMsg :
85+ message .append (SlackUtil .buildSection (additionalMsg ))
9486 else :
9587 message = [
9688 SlackUtil .buildHeader (f":glyph-fail: Your IBM Cloud ROKS cluster ({ name } ) failed to deploy" ),
9789 SlackUtil .buildSection (f"<https://cloud.ibm.com/kubernetes/clusters|IBM Cloud Dashboard>{ toolchainLink } " )
9890 ]
9991
100- return _broadcast (channels , message )
92+ response = SlackUtil .postMessageBlocks (channels , message )
93+ if isinstance (response , list ):
94+ return all ([res .data .get ("ok" , False ) for res in response ])
95+ return response .data .get ("ok" , False )
10196
10297
10398if __name__ == "__main__" :
@@ -106,21 +101,21 @@ if __name__ == "__main__":
106101 SLACK_CHANNEL = os .getenv ("SLACK_CHANNEL" , "" )
107102 if SLACK_TOKEN == "" or SLACK_CHANNEL == "" :
108103 sys .exit (0 )
109-
104+
105+ # Parse comma-separated channel list
106+ channelList = [ch .strip () for ch in SLACK_CHANNEL .split ("," )]
107+
110108 # Initialize the properties we need
111109 parser = argparse .ArgumentParser ()
112110
113111 # Primary Options
114112 parser .add_argument ("--action" , required = True )
115113 parser .add_argument ("--rc" , required = True , type = int )
116- parser .add_argument ("--add-details " )
114+ parser .add_argument ("--msg" , required = False , default = " " )
117115
118116 args , unknown = parser .parse_known_args ()
119117
120118 if args .action == "ocp-provision-fyre" :
121- notifyProvisionFyre (SLACK_CHANNEL , args .rc )
119+ notifyProvisionFyre (channelList , args .rc , args . msg )
122120 elif args .action == "ocp-provision-roks" :
123- if args .add_details :
124- notifyProvisionRoks (SLACK_CHANNEL , args .rc , args .add_details )
125- else :
126- notifyProvisionRoks (SLACK_CHANNEL , args .rc )
121+ notifyProvisionRoks (channelList , args .rc , args .msg )
0 commit comments