Skip to content

Commit

Permalink
✨ Make body optional (#2)
Browse files Browse the repository at this point in the history
* Make body optional

* lazy code change
  • Loading branch information
viniciuskneves authored Nov 10, 2021
1 parent 0de6239 commit baa7796
Showing 1 changed file with 40 additions and 32 deletions.
72 changes: 40 additions & 32 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ inputs:
required: true
description: Message title
body:
required: true
required: false
description: Message body (markdown allowed but needs to be Slackified first)
context:
required: true
Expand All @@ -20,37 +20,45 @@ runs:
- name: Announce on Slack 📢
shell: bash
run: |
header='{
"type": "header",
"text": {
"type": "plain_text",
"text": "${{ inputs.title }}"
}
},'
divider='{
"type": "divider"
},'
# Slack markdown doesn't accept empty `text`
if [ ! -z '${{ inputs.body }}' ]
then
body='{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "${{ inputs.body }}"
}
},'
fi
context='{
"type": "context",
"elements": [
{
"type": "plain_text",
"text": "${{ inputs.context }}"
}
]
}'
blocks='"blocks": [
'$header'
'$divider'
'$body'
'$context'
]'
data='{'$blocks'}'
curl ${{ inputs.webhook_url }} \
--request POST \
--header 'Content-type: application/json' \
--data \
'{
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "${{ inputs.title }}"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "${{ inputs.body }}"
}
},
{
"type": "context",
"elements": [
{
"type": "plain_text",
"text": "${{ inputs.context }}"
}
]
}
]
}'
--data "$data"

0 comments on commit baa7796

Please sign in to comment.