Skip to content

Commit 917a9c4

Browse files
[patch] remove extra new lines
1 parent a1ce79e commit 917a9c4

1 file changed

Lines changed: 2 additions & 26 deletions

File tree

bin/mas-devops-notify-slack

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -101,30 +101,23 @@ def notifyAnsibleComplete(channels: list[str], rc: int, taskName: str, pipelineN
101101
"""Send Slack notification about Ansible task completion status."""
102102
namespace = os.getenv("PIPELINE_NAMESPACE", "")
103103
pipelineRunName = os.getenv("PIPELINERUN_NAME", "")
104-
105104
if namespace == "" or pipelineRunName == "":
106105
print("PIPELINE_NAMESPACE and PIPELINERUN_NAME env vars must be set")
107106
sys.exit(1)
108-
109107
# Check if this is the first task (no ConfigMap exists yet)
110108
threadInfo = SlackUtil.getThreadConfigMap(namespace, pipelineRunName)
111-
112109
if threadInfo is None:
113110
# This is the first task - send pipeline started message
114111
toolchainLink = _getToolchainLink()
115112
instanceInfo = f"\nInstance ID: `{instanceId}`" if instanceId else ""
116-
117113
message = [
118114
SlackUtil.buildHeader(f"🚀 MAS {pipelineName.title()} Pipeline Started"),
119115
SlackUtil.buildSection(f"Pipeline Run: `{pipelineRunName}`{instanceInfo}\n{toolchainLink}")
120116
]
121-
122117
response = SlackUtil.postMessageBlocks(channels[0], message)
123-
124118
if response.data.get("ok", False):
125119
threadId = response["ts"]
126120
channelId = response["channel"]
127-
128121
# Store thread information in ConfigMap
129122
SlackUtil.createThreadConfigMap(namespace, pipelineRunName, channelId, threadId, pipelineName)
130123
threadInfo = {
@@ -135,27 +128,21 @@ def notifyAnsibleComplete(channels: list[str], rc: int, taskName: str, pipelineN
135128
else:
136129
print("Failed to send initial Slack message")
137130
return False
138-
139131
# Send task completion message as thread reply
140132
threadId = threadInfo.get("threadId")
141133
channelId = threadInfo.get("channelId")
142-
143134
if rc == 0:
144135
emoji = "✅"
145136
status = "Success"
146137
else:
147138
emoji = "❌"
148139
status = "Failed"
149-
150140
taskMessage = [
151141
SlackUtil.buildSection(f"{emoji} **{taskName}** - {status}")
152142
]
153-
154143
if rc != 0:
155144
taskMessage.append(SlackUtil.buildSection(f"Return Code: `{rc}`\nCheck logs for details"))
156-
157145
response = SlackUtil.postMessageBlocks(channelId, taskMessage, threadId)
158-
159146
if isinstance(response, list):
160147
return all([res.data.get("ok", False) for res in response])
161148
return response.data.get("ok", False)
@@ -165,22 +152,17 @@ def notifyPipelineComplete(channels: list[str], rc: int, pipelineName: str, inst
165152
"""Send Slack notification about pipeline completion and cleanup ConfigMap."""
166153
namespace = os.getenv("PIPELINE_NAMESPACE", "")
167154
pipelineRunName = os.getenv("PIPELINERUN_NAME", "")
168-
169155
if namespace == "" or pipelineRunName == "":
170156
print("PIPELINE_NAMESPACE and PIPELINERUN_NAME env vars must be set")
171157
sys.exit(1)
172-
173158
# Get thread information
174159
threadInfo = SlackUtil.getThreadConfigMap(namespace, pipelineRunName)
175-
176160
if threadInfo is None:
177161
print("No thread information found - pipeline may not have started properly")
178162
return False
179-
180163
threadId = threadInfo.get("threadId")
181164
channelId = threadInfo.get("channelId")
182165
startTime = threadInfo.get("startTime")
183-
184166
# Calculate duration if start time is available
185167
durationText = ""
186168
if startTime:
@@ -196,10 +178,8 @@ def notifyPipelineComplete(channels: list[str], rc: int, pipelineName: str, inst
196178
else:
197179
durationText = f"\nTotal Duration: {minutes}m {seconds}s"
198180
except:
199-
pass
200-
181+
pass
201182
instanceInfo = f"\nInstance ID: `{instanceId}`" if instanceId else ""
202-
203183
if rc == 0:
204184
emoji = "🎉"
205185
status = "Completed Successfully"
@@ -208,17 +188,13 @@ def notifyPipelineComplete(channels: list[str], rc: int, pipelineName: str, inst
208188
emoji = "💥"
209189
status = "Failed"
210190
additionalInfo = f"\nPipeline failed with return code: `{rc}`"
211-
212191
message = [
213192
SlackUtil.buildHeader(f"{emoji} MAS {pipelineName.title()} Pipeline {status}"),
214193
SlackUtil.buildSection(f"Pipeline Run: `{pipelineRunName}`{instanceInfo}{durationText}{additionalInfo}")
215-
]
216-
194+
]
217195
response = SlackUtil.postMessageBlocks(channelId, message, threadId)
218-
219196
# Clean up ConfigMap
220197
SlackUtil.deleteThreadConfigMap(namespace, pipelineRunName)
221-
222198
if isinstance(response, list):
223199
return all([res.data.get("ok", False) for res in response])
224200
return response.data.get("ok", False)

0 commit comments

Comments
 (0)