Skip to content

Commit 441342e

Browse files
Merge pull request #143 from rtpg/split-channel
PLT-1224: Allow deploy alerts to go to a different channel
2 parents 09f8211 + 78d9d1a commit 441342e

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

gitops_server/settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@
1212
# The slack channel ID starts with C
1313
SLACK_CHANNEL_ID = os.environ.get("SLACK_CHANNEL_ID", "")
1414

15+
SLACK_ALERT_CHANNEL_ID = os.environ.get("SLACK_ALERT_CHANNEL_ID", "")
16+
1517
# How many parallel deploys can be done at once
1618
GITOPS_MAX_PARALLEL_DEPLOYS = os.environ.get("GITOPS_MAX_PARALLEL_DEPLOYS", "5")

gitops_server/utils/slack.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,22 @@ def __str__(self) -> str:
2727
return f"<!subteam^{self.id}|{self.name}>"
2828

2929

30+
async def post_alert(message: str) -> str | None:
31+
"""
32+
Post a message to a slack alert channel (if it's configured) or the default slack channel
33+
"""
34+
return await post_to_channel(message, channel_id=settings.SLACK_ALERT_CHANNEL_ID or settings.SLACK_CHANNEL_ID)
35+
36+
3037
async def post(message: str) -> str | None:
3138
"""Post a message to a slack channel"""
39+
return await post_to_channel(message, channel_id=settings.SLACK_CHANNEL_ID)
40+
41+
42+
async def post_to_channel(message: str, channel_id: str | None) -> str | None:
3243
logger.info("POSTING TO SLACK")
33-
if settings.SLACK_TOKEN and settings.SLACK_CHANNEL_ID:
34-
response = client.chat_postMessage(channel=settings.SLACK_CHANNEL_ID, text=message)
44+
if settings.SLACK_TOKEN and channel_id:
45+
response = client.chat_postMessage(channel=channel_id, text=message)
3546
if response.status_code >= 300:
3647
logger.warning("Failed to post a message to slack (see below):")
3748
logger.error(f"{message}", exc_info=True)

gitops_server/workers/deployer/deploy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ async def post_result(self, app: App, result: UpdateAppResult, deployer: "Deploy
282282
deploy_result["slack_message"]
283283
or f"Failed to deploy app `{result['app_name']}` for cluster `{settings.CLUSTER_NAME}`:\n>>>{result['output']}"
284284
)
285-
await slack.post(message)
285+
await slack.post_alert(message)
286286
else:
287287
self.successful_apps.add(app.name)
288288
await handle_successful_deploy(app, result, deployer)

0 commit comments

Comments
 (0)