Skip to content

Commit d73b331

Browse files
authored
ci: sanitize PR name in Slack notification messages like <&test> (#359)
This PR updates the Slack notification workflow to escape special characters `&`, `<` and `>`. https://api.slack.com/reference/surfaces/formatting#escaping
1 parent 914a061 commit d73b331

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

.github/workflows/ci-notify-slack.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,21 @@ jobs:
1212
steps:
1313
- name: Checkout
1414
uses: actions/checkout@v4
15+
16+
- name: Sanitize PR title
17+
id: sanitize
18+
run: |
19+
RAW_TITLE="${{ github.event.pull_request.title }}"
20+
ESCAPED_TITLE=$(echo "$RAW_TITLE" \
21+
| sed 's/&/\&amp;/g' \
22+
| sed 's/</\&lt;/g' \
23+
| sed 's/>/\&gt;/g')
24+
echo "safe_title=$ESCAPED_TITLE" >> "$GITHUB_OUTPUT"
25+
1526
- name: Post to a Slack channel
1627
uses: slackapi/slack-github-action@6c661ce58804a1a20f6dc5fbee7f0381b469e001 # v1.25.0
1728
with:
1829
channel-id: eng-execution-mrs
19-
slack-message: ":github: `${{ github.repository }}` <${{ github.event.pull_request.html_url }}|${{ github.event.pull_request.title }}>"
30+
slack-message: ":github: `${{ github.repository }}` <${{ github.event.pull_request.html_url }}|${{ steps.sanitize.outputs.safe_title }}>"
2031
env:
2132
SLACK_BOT_TOKEN: ${{ secrets.SLACK_API_TOKEN }}

0 commit comments

Comments
 (0)