@@ -97,82 +97,53 @@ def notifyProvisionRoks(channels: list[str], rc: int, additionalMsg: str | None
9797 return response .data .get ("ok" , False )
9898
9999
100- def notifyPipelineStart (channels : list [str ], pipelineName : str , instanceId : str | None = None ) -> bool :
100+ def notifyPipelineStart (channels : list [str ], instanceId : str | None = None ) -> dict | None :
101101 """Send Slack notification about pipeline start and create thread."""
102102 namespace = f"mas-{ instanceId } -pipelines"
103- pipelineRunName = os .getenv ("PIPELINERUN_NAME" , "" )
104103 if instanceId is None or instanceId == "" :
105104 print ("instanceId must be set" )
106105 sys .exit (1 )
107- if namespace == "" or pipelineRunName == "" :
108- print ("PIPELINE_NAMESPACE and PIPELINERUN_NAME env vars must be set" )
109- sys .exit (1 )
110-
106+
111107 # Check if thread already exists
112- threadInfo = SlackUtil .getThreadConfigMap (namespace , pipelineRunName )
108+ threadInfo = SlackUtil .getThreadConfigMap (namespace , instanceId )
113109 if threadInfo is not None :
114110 print ("Pipeline start notification already sent" )
115- return True
116-
111+ return threadInfo
112+
117113 # Send pipeline started message
118114 toolchainLink = _getToolchainLink ()
119115 instanceInfo = f"\n Instance ID: `{ instanceId } `" if instanceId else ""
120116 message = [
121- SlackUtil .buildHeader (f "🚀 MAS { pipelineName . title () } Pipeline Started" ),
122- SlackUtil .buildSection (f"Pipeline Run: ` { pipelineRunName } ` { instanceInfo } \n { toolchainLink } " )
117+ SlackUtil .buildHeader ("🚀 MAS Pipeline Started" ),
118+ SlackUtil .buildSection (f"Pipeline Run: { instanceInfo } \n { toolchainLink } " )
123119 ]
124120 response = SlackUtil .postMessageBlocks (channels [0 ], message )
125121 if response .data .get ("ok" , False ):
126122 threadId = response ["ts" ]
127123 channelId = response ["channel" ]
128124 # Store thread information in ConfigMap
129- SlackUtil .createThreadConfigMap (namespace , pipelineRunName , channelId , threadId , pipelineName )
125+ SlackUtil .createThreadConfigMap (namespace , channelId , threadId , instanceId )
130126 return True
131127 else :
132128 print ("Failed to send pipeline start Slack message" )
133129 return False
134130
135131
136- def notifyAnsibleStart (channels : list [str ], taskName : str , pipelineName : str , instanceId : str | None = None ) -> bool :
132+ def notifyAnsibleStart (channels : list [str ], taskName : str , instanceId : str | None = None ) -> bool :
137133 """Send Slack notification about Ansible task start."""
138134 namespace = f"mas-{ instanceId } -pipelines"
139- pipelineRunName = os .getenv ("PIPELINERUN_NAME" , "" )
140135 if instanceId is None or instanceId == "" :
141136 print ("instanceId must be set" )
142137 sys .exit (1 )
143- if namespace == "" or pipelineRunName == "" :
144- print ("PIPELINE_NAMESPACE and PIPELINERUN_NAME env vars must be set" )
145- sys .exit (1 )
146-
138+
147139 # Get thread information, create if doesn't exist
148- threadInfo = SlackUtil .getThreadConfigMap (namespace , pipelineRunName )
140+ threadInfo = SlackUtil .getThreadConfigMap (namespace , instanceId )
149141 if threadInfo is None :
150142 print ("No thread found - creating pipeline start notification" )
151- # Send pipeline started message
152- toolchainLink = _getToolchainLink ()
153- instanceInfo = f"\n Instance ID: `{ instanceId } `" if instanceId else ""
154- message = [
155- SlackUtil .buildHeader (f"🚀 MAS { pipelineName .title ()} Pipeline Started" ),
156- SlackUtil .buildSection (f"Pipeline Run: `{ pipelineRunName } `{ instanceInfo } \n { toolchainLink } " )
157- ]
158- response = SlackUtil .postMessageBlocks (channels [0 ], message )
159- if response .data .get ("ok" , False ):
160- threadId = response ["ts" ]
161- channelId = response ["channel" ]
162- # Store thread information in ConfigMap
163- SlackUtil .createThreadConfigMap (namespace , pipelineRunName , channelId , threadId , pipelineName )
164- threadInfo = {
165- "threadId" : threadId ,
166- "channelId" : channelId ,
167- "pipelineName" : pipelineName
168- }
169- else :
170- print ("Failed to send pipeline start Slack message" )
171- return False
172-
143+ notifyPipelineStart (channels , instanceId )
173144 threadId = threadInfo .get ("threadId" )
174145 channelId = threadInfo .get ("channelId" )
175-
146+
176147 # Send task start message as thread reply
177148 taskMessage = [
178149 SlackUtil .buildSection (f"⏳ **{ taskName } ** - Started" )
@@ -183,43 +154,18 @@ def notifyAnsibleStart(channels: list[str], taskName: str, pipelineName: str, in
183154 return response .data .get ("ok" , False )
184155
185156
186- def notifyAnsibleComplete (channels : list [str ], rc : int , taskName : str , pipelineName : str , instanceId : str | None = None ) -> bool :
157+ def notifyAnsibleComplete (channels : list [str ], rc : int , taskName : str , instanceId : str | None = None ) -> bool :
187158 """Send Slack notification about Ansible task completion status."""
188159 namespace = f"mas-{ instanceId } -pipelines"
189- pipelineRunName = os .getenv ("PIPELINERUN_NAME" , "" )
190160 if instanceId is None or instanceId == "" :
191161 print ("instanceId must be set" )
192162 sys .exit (1 )
193- if namespace == "" or pipelineRunName == "" :
194- print ("PIPELINE_NAMESPACE and PIPELINERUN_NAME env vars must be set" )
195- sys .exit (1 )
196-
163+
197164 # Get thread information, create if doesn't exist
198- threadInfo = SlackUtil .getThreadConfigMap (namespace , pipelineRunName )
165+ threadInfo = SlackUtil .getThreadConfigMap (namespace , instanceId )
199166 if threadInfo is None :
200167 print ("No thread found - creating pipeline start notification" )
201- # Send pipeline started message
202- toolchainLink = _getToolchainLink ()
203- instanceInfo = f"\n Instance ID: `{ instanceId } `" if instanceId else ""
204- message = [
205- SlackUtil .buildHeader (f"🚀 MAS { pipelineName .title ()} Pipeline Started" ),
206- SlackUtil .buildSection (f"Pipeline Run: `{ pipelineRunName } `{ instanceInfo } \n { toolchainLink } " )
207- ]
208- response = SlackUtil .postMessageBlocks (channels [0 ], message )
209- if response .data .get ("ok" , False ):
210- threadId = response ["ts" ]
211- channelId = response ["channel" ]
212- # Store thread information in ConfigMap
213- SlackUtil .createThreadConfigMap (namespace , pipelineRunName , channelId , threadId , pipelineName )
214- threadInfo = {
215- "threadId" : threadId ,
216- "channelId" : channelId ,
217- "pipelineName" : pipelineName
218- }
219- else :
220- print ("Failed to send pipeline start Slack message" )
221- return False
222-
168+ notifyPipelineStart (channels , instanceId )
223169 # Send task completion message as thread reply
224170 threadId = threadInfo .get ("threadId" )
225171 channelId = threadInfo .get ("channelId" )
@@ -240,15 +186,14 @@ def notifyAnsibleComplete(channels: list[str], rc: int, taskName: str, pipelineN
240186 return response .data .get ("ok" , False )
241187
242188
243- def notifyPipelineComplete (channels : list [str ], rc : int , pipelineName : str , instanceId : str | None = None ) -> bool :
189+ def notifyPipelineComplete (channels : list [str ], rc : int , instanceId : str | None = None ) -> bool :
244190 """Send Slack notification about pipeline completion and cleanup ConfigMap."""
245191 namespace = f"mas-{ instanceId } -pipelines"
246- pipelineRunName = os .getenv ("PIPELINERUN_NAME" , "" )
247- if namespace == "" or pipelineRunName == "" :
248- print ("PIPELINE_NAMESPACE and PIPELINERUN_NAME env vars must be set" )
192+ if instanceId is None or instanceId == "" :
193+ print ("instanceId must be set" )
249194 sys .exit (1 )
250195 # Get thread information
251- threadInfo = SlackUtil .getThreadConfigMap (namespace , pipelineRunName )
196+ threadInfo = SlackUtil .getThreadConfigMap (namespace , instanceId )
252197 if threadInfo is None :
253198 print ("No thread information found - pipeline may not have started properly" )
254199 return False
@@ -281,12 +226,12 @@ def notifyPipelineComplete(channels: list[str], rc: int, pipelineName: str, inst
281226 status = "Failed"
282227 additionalInfo = f"\n Pipeline failed with return code: `{ rc } `"
283228 message = [
284- SlackUtil .buildHeader (f"{ emoji } MAS { pipelineName . title () } Pipeline { status } " ),
285- SlackUtil .buildSection (f"Pipeline Run: ` { pipelineRunName } ` { instanceInfo } { durationText } { additionalInfo } " )
229+ SlackUtil .buildHeader (f"{ emoji } MAS Pipeline { status } " ),
230+ SlackUtil .buildSection (f"Pipeline Run: { instanceInfo } { durationText } { additionalInfo } " )
286231 ]
287232 response = SlackUtil .postMessageBlocks (channelId , message , threadId )
288233 # Clean up ConfigMap
289- SlackUtil .deleteThreadConfigMap (namespace , pipelineRunName )
234+ SlackUtil .deleteThreadConfigMap (namespace , instanceId )
290235 if isinstance (response , list ):
291236 return all ([res .data .get ("ok" , False ) for res in response ])
292237 return response .data .get ("ok" , False )
@@ -310,7 +255,6 @@ if __name__ == "__main__":
310255 parser .add_argument ("--rc" , required = True , type = int )
311256 parser .add_argument ("--msg" , required = False , default = None )
312257 parser .add_argument ("--task-name" , required = False , default = "" )
313- parser .add_argument ("--pipeline-name" , required = False , default = "" )
314258 parser .add_argument ("--instance-id" , required = False , default = None )
315259
316260 args , unknown = parser .parse_known_args ()
@@ -320,10 +264,10 @@ if __name__ == "__main__":
320264 elif args .action == "ocp-provision-roks" :
321265 notifyProvisionRoks (channelList , args .rc , args .msg )
322266 elif args .action == "pipeline-start" :
323- notifyPipelineStart (channelList , args .pipeline_name , args . instance_id )
267+ notifyPipelineStart (channelList , args .instance_id )
324268 elif args .action == "ansible-start" :
325- notifyAnsibleStart (channelList , args .task_name , args .pipeline_name , args . instance_id )
269+ notifyAnsibleStart (channelList , args .task_name , args .instance_id )
326270 elif args .action == "ansible-complete" :
327- notifyAnsibleComplete (channelList , args .rc , args .task_name , args .pipeline_name , args . instance_id )
271+ notifyAnsibleComplete (channelList , args .rc , args .task_name , args .instance_id )
328272 elif args .action == "pipeline-complete" :
329- notifyPipelineComplete (channelList , args .rc , args .pipeline_name , args . instance_id )
273+ notifyPipelineComplete (channelList , args .rc , args .instance_id )
0 commit comments