Skip to content

New Comment Slack Notification #239

New Comment Slack Notification

New Comment Slack Notification #239

name: New Comment Slack Notification
on:
discussion:
types: [created]
discussion_comment:
types: [created]
jobs:
send-create-discussion:
runs-on: ubuntu-latest
steps:
- name: slack notification
if: ${{ github.event.discussion && github.event.comment && env.USER_NAME != 'ShanePark' }}
run: |
body=$(
cat << "EOF"
${{ env.COMMENT_BODY }}
EOF
)
printf -v comment_unescaped %b "$body"
jq -n -r --arg text "$comment_unescaped" '{
"channel": "#blog-comments",
"username": "Shane'\''s Planet",
"blocks": [
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "New Comment on *<https://shanepark.tistory.com/${{ env.DISCUSSION_TITLE }}|${{ env.DISCUSSION_TITLE }}>*"
},
{
"type": "mrkdwn",
"text": "*Commented by:* <${{ env.USER_URL }}|${{ env.USER_NAME }}>"
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": $text
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"text": "Read it",
"emoji": true
},
"url": "${{ env.COMMENT_URL }}",
}
}
],
"icon_emoji": ":speech_balloon:"
}
'|curl -X POST -H 'Content-Type: application/json' -d @- https://hooks.slack.com/services/${{secrets.SLACK_TOKEN}}
shell: bash
env:
DISCUSSION_TITLE: ${{ github.event.discussion.title }}
COMMENT_URL: ${{ github.event.comment.html_url }}
COMMENT_BODY: ${{ github.event.comment.body }}
USER_URL: ${{ github.event.comment.user.html_url }}
USER_NAME: ${{ github.event.comment.user.login }}