From baa77969e9bdc48d3d42457da5bfb4a1b2a0b66c Mon Sep 17 00:00:00 2001 From: Vinicius Kiatkoski Neves Date: Wed, 10 Nov 2021 11:25:02 +0100 Subject: [PATCH] :sparkles: Make body optional (#2) * Make body optional * lazy code change --- action.yml | 72 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/action.yml b/action.yml index 93b4802..5757583 100644 --- a/action.yml +++ b/action.yml @@ -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 @@ -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"