Skip to content

Commit b8e35cd

Browse files
committed
Lint + secrets
1 parent 4b08b80 commit b8e35cd

2 files changed

Lines changed: 30 additions & 82 deletions

File tree

‎.secrets.baseline‎

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎bin/mas-devops-notify-slack‎

Lines changed: 26 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ def _getToolchainLink() -> str:
3333
return ""
3434

3535

36-
def notifyProvisionFyre(
37-
channels: list[str], rc: int, additionalMsg: str | None = None
38-
) -> bool:
36+
def notifyProvisionFyre(channels: list[str], rc: int, additionalMsg: str | None = None) -> bool:
3937
"""Send Slack notification about Fyre OCP cluster provisioning status."""
4038
name = _getClusterName()
4139
toolchainLink = _getToolchainLink()
@@ -46,33 +44,21 @@ def notifyProvisionFyre(
4644
password = os.getenv("OCP_PASSWORD", None)
4745

4846
if url is None or username is None or password is None:
49-
print(
50-
"OCP_CONSOLE_URL, OCP_USERNAME, and OCP_PASSWORD env vars must all be set"
51-
)
47+
print("OCP_CONSOLE_URL, OCP_USERNAME, and OCP_PASSWORD env vars must all be set")
5248
sys.exit(1)
5349

5450
message = [
55-
SlackUtil.buildHeader(
56-
f":glyph-ok: Your IBM DevIT Fyre OCP cluster ({name}) is ready"
57-
),
51+
SlackUtil.buildHeader(f":glyph-ok: Your IBM DevIT Fyre OCP cluster ({name}) is ready"),
5852
SlackUtil.buildSection(f"{url}"),
59-
SlackUtil.buildSection(
60-
f"- Username: `{username}`\n- Password: `{password}`"
61-
),
62-
SlackUtil.buildSection(
63-
f"<https://beta.fyre.ibm.com/development/vms|Fyre Dashboard>{toolchainLink}"
64-
),
53+
SlackUtil.buildSection(f"- Username: `{username}`\n- Password: `{password}`"),
54+
SlackUtil.buildSection(f"<https://beta.fyre.ibm.com/development/vms|Fyre Dashboard>{toolchainLink}"),
6555
]
6656
if additionalMsg is not None:
6757
message.append(SlackUtil.buildSection(additionalMsg))
6858
else:
6959
message = [
70-
SlackUtil.buildHeader(
71-
f":glyph-fail: Your IBM DevIT Fyre OCP cluster ({name}) failed to deploy"
72-
),
73-
SlackUtil.buildSection(
74-
f"<https://beta.fyre.ibm.com/development/vms|Fyre Dashboard>{toolchainLink}"
75-
),
60+
SlackUtil.buildHeader(f":glyph-fail: Your IBM DevIT Fyre OCP cluster ({name}) failed to deploy"),
61+
SlackUtil.buildSection(f"<https://beta.fyre.ibm.com/development/vms|Fyre Dashboard>{toolchainLink}"),
7662
]
7763

7864
response = SlackUtil.postMessageBlocks(channels, message)
@@ -81,9 +67,7 @@ def notifyProvisionFyre(
8167
return response.data.get("ok", False)
8268

8369

84-
def notifyProvisionRoks(
85-
channels: list[str], rc: int, additionalMsg: str | None = None
86-
) -> bool:
70+
def notifyProvisionRoks(channels: list[str], rc: int, additionalMsg: str | None = None) -> bool:
8771
"""Send Slack notification about ROKS cluster provisioning status."""
8872
name = _getClusterName()
8973
toolchainLink = _getToolchainLink()
@@ -95,24 +79,16 @@ def notifyProvisionRoks(
9579
sys.exit(1)
9680

9781
message = [
98-
SlackUtil.buildHeader(
99-
f":glyph-ok: Your IBM Cloud ROKS cluster ({name}) is ready"
100-
),
82+
SlackUtil.buildHeader(f":glyph-ok: Your IBM Cloud ROKS cluster ({name}) is ready"),
10183
SlackUtil.buildSection(f"{url}"),
102-
SlackUtil.buildSection(
103-
f"<https://cloud.ibm.com/kubernetes/clusters|IBM Cloud Dashboard> | {toolchainLink}"
104-
),
84+
SlackUtil.buildSection(f"<https://cloud.ibm.com/kubernetes/clusters|IBM Cloud Dashboard> | {toolchainLink}"),
10585
]
10686
if additionalMsg is not None:
10787
message.append(SlackUtil.buildSection(additionalMsg))
10888
else:
10989
message = [
110-
SlackUtil.buildHeader(
111-
f":glyph-fail: Your IBM Cloud ROKS cluster ({name}) failed to deploy"
112-
),
113-
SlackUtil.buildSection(
114-
f"<https://cloud.ibm.com/kubernetes/clusters|IBM Cloud Dashboard> | {toolchainLink}"
115-
),
90+
SlackUtil.buildHeader(f":glyph-fail: Your IBM Cloud ROKS cluster ({name}) failed to deploy"),
91+
SlackUtil.buildSection(f"<https://cloud.ibm.com/kubernetes/clusters|IBM Cloud Dashboard> | {toolchainLink}"),
11692
]
11793

11894
response = SlackUtil.postMessageBlocks(channels, message)
@@ -153,9 +129,7 @@ def notifyPipelineStart(
153129
instanceInfo = f"Instance ID: `{instanceId}`" if instanceId else ""
154130
message = [
155131
SlackUtil.buildHeader(f"🚀 MAS {pipelineName} Pipeline Started"),
156-
SlackUtil.buildSection(
157-
f"Pipeline Run: {pipelineName}\n{instanceInfo}\n{toolchainLink}"
158-
),
132+
SlackUtil.buildSection(f"Pipeline Run: {pipelineName}\n{instanceInfo}\n{toolchainLink}"),
159133
]
160134
response = SlackUtil.postMessageBlocks(channels, message)
161135

@@ -250,9 +224,7 @@ def notifyAnsibleStart(
250224

251225
# Update ConfigMap with all task message timestamps
252226
if taskMessageData:
253-
SlackUtil.updateThreadConfigMap(
254-
namespace, instanceId, taskMessageData, pipelineName
255-
)
227+
SlackUtil.updateThreadConfigMap(namespace, instanceId, taskMessageData, pipelineName)
256228

257229
return allSuccess
258230

@@ -268,9 +240,7 @@ def notifyAnsibleComplete(
268240
"""Send Slack notification about Ansible task completion status to all channels."""
269241
# Exit early if no channels provided
270242
if not channels or len(channels) == 0:
271-
print(
272-
"No Slack channels provided - skipping Ansible task completion notification"
273-
)
243+
print("No Slack channels provided - skipping Ansible task completion notification")
274244
return False
275245

276246
# Use provided namespace, or fall back to legacy logic for backward compatibility
@@ -338,38 +308,26 @@ def notifyAnsibleComplete(
338308
print(f"Failed to calculate duration for channel {idx}: {e}")
339309

340310
# Build the completion message
341-
taskMessage = [
342-
SlackUtil.buildSection(f"{emoji} *{taskName}* - {status}{durationText}")
343-
]
311+
taskMessage = [SlackUtil.buildSection(f"{emoji} *{taskName}* - {status}{durationText}")]
344312
if rc != 0:
345-
taskMessage.append(
346-
SlackUtil.buildSection(f"Return Code: `{rc}`\nCheck logs for details")
347-
)
313+
taskMessage.append(SlackUtil.buildSection(f"Return Code: `{rc}`\nCheck logs for details"))
348314

349315
# If we have the original message timestamp, update it; otherwise post new message
350316
if taskMessageTs:
351-
response = SlackUtil.updateMessageBlocks(
352-
channelId, taskMessageTs, taskMessage
353-
)
317+
response = SlackUtil.updateMessageBlocks(channelId, taskMessageTs, taskMessage)
354318
if not response.data.get("ok", False):
355319
allSuccess = False
356320
else:
357321
# Fallback: post new message if task start message wasn't tracked
358-
print(
359-
f"No start message found for task {taskName} in channel {idx}, posting new completion message"
360-
)
322+
print(f"No start message found for task {taskName} in channel {idx}, posting new completion message")
361323
response = SlackUtil.postMessageBlocks(channelId, taskMessage, threadId)
362324
if not response.data.get("ok", False):
363325
allSuccess = False
364326

365327
# Special case, mas-update pipeline
366328
if namespace == "mas-pipelines" and taskName == "post-deps-update-verify-ingress":
367-
print(
368-
f"mas-update pipeline completed with status: {rc}, sending pipeline complete message"
369-
)
370-
allSuccess: bool = notifyPipelineComplete(
371-
channels, rc, instanceId, pipelineName, namespace
372-
)
329+
print(f"mas-update pipeline completed with status: {rc}, sending pipeline complete message")
330+
allSuccess: bool = notifyPipelineComplete(channels, rc, instanceId, pipelineName, namespace)
373331

374332
return allSuccess
375333

@@ -440,9 +398,7 @@ def notifyPipelineComplete(
440398

441399
message = [
442400
SlackUtil.buildHeader(f"{emoji} MAS {pipelineName} Pipeline {status}"),
443-
SlackUtil.buildSection(
444-
f"Pipeline Run: {pipelineName}\n{instanceInfo}{durationText}{additionalInfo}"
445-
),
401+
SlackUtil.buildSection(f"Pipeline Run: {pipelineName}\n{instanceInfo}{durationText}{additionalInfo}"),
446402
]
447403

448404
allSuccess = True
@@ -495,22 +451,16 @@ if __name__ == "__main__":
495451
args, unknown = parser.parse_known_args()
496452

497453
# Use namespace from command line arg, or fall back to PIPELINE_NAMESPACE env var
498-
namespace = (
499-
args.namespace if args.namespace else os.getenv("PIPELINE_NAMESPACE", None)
500-
)
454+
namespace = args.namespace if args.namespace else os.getenv("PIPELINE_NAMESPACE", None)
501455

502456
if args.action == "ocp-provision-fyre":
503457
notifyProvisionFyre(channelList, args.rc, args.msg)
504458
elif args.action == "ocp-provision-roks":
505459
notifyProvisionRoks(channelList, args.rc, args.msg)
506460
elif args.action == "pipeline-start":
507-
notifyPipelineStart(
508-
channelList, args.instance_id, args.pipeline_name, namespace
509-
)
461+
notifyPipelineStart(channelList, args.instance_id, args.pipeline_name, namespace)
510462
elif args.action == "ansible-start":
511-
notifyAnsibleStart(
512-
channelList, args.task_name, args.instance_id, args.pipeline_name, namespace
513-
)
463+
notifyAnsibleStart(channelList, args.task_name, args.instance_id, args.pipeline_name, namespace)
514464
elif args.action == "ansible-complete":
515465
notifyAnsibleComplete(
516466
channelList,
@@ -521,6 +471,4 @@ if __name__ == "__main__":
521471
namespace,
522472
)
523473
elif args.action == "pipeline-complete":
524-
notifyPipelineComplete(
525-
channelList, args.rc, args.instance_id, args.pipeline_name, namespace
526-
)
474+
notifyPipelineComplete(channelList, args.rc, args.instance_id, args.pipeline_name, namespace)

0 commit comments

Comments
 (0)