Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sanitise slack message #184

Merged
merged 7 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/test-slack-send.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,15 @@ jobs:
Test some characters: & and * and < > \n \r

Failed to assign <${{ github.event.repository.html_url }}|SDH #my-issue>.

- uses: ./slack/send
id: slack-multi-with-double-quotes
with:
bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
channel-id: "#observablt-bots"
thread-timestamp: ${{ steps.slack-send.outputs.thread-timestamp || '' }}
message: |
:wave: !
I have assigned you the following SDH, as to my knowledge you are currently on duty for `area::observability-rac`:
v1v marked this conversation as resolved.
Show resolved Hide resolved

*`urgency:48h` <https://github.com/elastic/sdh-kibana/issues/5098|#5098 - Adding the field "system.filesystem.free" to the output of an alert>*
v1v marked this conversation as resolved.
Show resolved Hide resolved
12 changes: 7 additions & 5 deletions slack/send/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ runs:
# https://api.slack.com/reference/surfaces/formatting#escaping
import os
from urllib.parse import unquote
import json

if os.environ["MESSAGE"]:
message = os.environ.get('MESSAGE', 'No message')
Expand All @@ -55,11 +56,12 @@ runs:
else:
raise Exception("message must be set.")

# Escape special characters for GitHub Actions output
message = message.replace('\n', '\\n').replace('\r', '\\r')
print("message={}".format(message))
sanitizedMessage = json.dumps(message)
print("sanitized message={}".format(sanitizedMessage))

with open(os.environ.get('GITHUB_OUTPUT'), "a") as f:
f.write("message={}".format(message))
f.write("message={}".format(sanitizedMessage))

- uses: slackapi/slack-github-action@485a9d42d3a73031f12ec201c457e2162c45d02d # v2.0.0
id: slack_message
Expand All @@ -71,9 +73,9 @@ runs:
unfurl_media: false
channel: "${{ inputs.channel-id }}"
thread_ts: "${{ inputs.thread-timestamp }}"
text: "${{ steps.prepare.outputs.message }}"
text: ${{ steps.prepare.outputs.message }}
blocks:
- type: "section"
text:
type: mrkdwn
text: "${{ steps.prepare.outputs.message }}"
text: ${{ steps.prepare.outputs.message }}
Loading