Skip to content

Commit

Permalink
Slack webhooks shlex
Browse files Browse the repository at this point in the history
  • Loading branch information
nx10 committed Jan 5, 2024
1 parent 227d729 commit 66d38d4
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/ecpac/slack.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import os
import shlex

SLACK_WEBHOOK_URL: str | None = os.environ.get("SLACK_WEBHOOK_URL")

Expand All @@ -13,7 +14,16 @@ def slack_message_bash(data: dict) -> str:
"""Generate a bash command to send a message to Slack."""
if not slack_webhook_available():
return ""
return f"curl -X POST -H 'Content-type: application/json' --data '{json.dumps(data)}' {SLACK_WEBHOOK_URL}"
return shlex.join([
"curl",
"-X",
"POST",
"-H",
"Content-type: application/json",
"--data",
json.dumps(data),
SLACK_WEBHOOK_URL
])


def slack_message_bash_mrkdwn(text: str) -> str:
Expand Down

0 comments on commit 66d38d4

Please sign in to comment.