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

Add markdown formatting for messages #8

Merged
merged 2 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ SLACK_MESSAGE | Generated from git commit message. | The
SLACK_TITLE | Message | Title to use before main Slack message.
SLACK_FOOTER | Powered By rtCamp's GitHub Actions Library | Slack message footer.
MSG_MINIMAL | - | If set to `true`, removes: `Ref`, `Event`, `Actions URL` and `Commit` from the message. You can optionally whitelist any of these 4 removed values by passing it comma separated to the variable instead of `true`. (ex: `MSG_MINIMAL: event` or `MSG_MINIMAL: ref,actions url`, etc.)
SLACKIFY_MARKDOWN | - | If set to `true`, it will convert markdown to slack format. (ex: `*bold*` to `bold`) Note: This only works for custom messages and not for the default message generated by the action.
SLACK_THREAD_TS | - | If you want to send message in a thread, you can pass the timestamp of the parent message to this variable. You can get the timestamp of the parent message from the message URL in Slack. (ex: `SLACK_THREAD_TS: 1586130833.000100`)
SLACK_ON_SUCCESS | - | If set, will send the provided message instead of the default message when the passed status (through ``SLACK_COLOR``) is `success`.
SLACK_ON_FAILURE | - | If set, will send the provided message instead of the default message when the passed status (through ``SLACK_COLOR``) is `failure`.
SLACK_ON_CANCEL | - | If set, will send the provided message instead of the default message when the passed status (through ``SLACK_COLOR``) is `cancelled`.
ENABLE_ESCAPES | - | If set to `true`, enables backslash escapes in the message such as '\n', '\t', etc.


You can see the action block with all variables as below:

```yml
Expand Down
27 changes: 25 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,31 @@ name: 'Slack Notify'
description: 'This action will send a notification to Slack'
author: 'rtCamp'
runs:
using: 'docker'
image: 'docker://ghcr.io/rtcamp/action-slack-notify:v2.2.1'
# using: 'docker'
# image: 'docker://ghcr.io/rtcamp/action-slack-notify:v2.2.1'
using: 'composite'
steps:
- name: "Slack-Markdown Conversion"
if: env.SLACKIFY_MARKDOWN == 'true'
id: slackify
uses: LoveToKnow/slackify-markdown-action@v1.0.2
with:
text: ${{ env.SLACK_MESSAGE }}

- name: "Update Message Variable (Formatted)"
if: env.SLACKIFY_MARKDOWN == 'true'
shell: sh
run: "echo 'SLACK_MESSAGE_FORMATTED=${{ steps.slackify.outputs.text }}' >> $GITHUB_ENV"

- name: "Update Message Variable (Unformatted)"
if: env.SLACKIFY_MARKDOWN == 'false'
shell: sh
run: "echo 'SLACK_MESSAGE_FORMATTED=${{ env.SLACK_MESSAGE }}' >> $GITHUB_ENV"

- name: "Slack Notification"
uses: rtCamp/action-slack-notify@v2.2.1
with:
SLACK_MESSAGE: "${{ env.SLACK_MESSAGE_FORMATTED }}"
branding:
icon: 'bell'
color: 'yellow'