Skip to content

Mend Slack Notifier #4512

Mend Slack Notifier

Mend Slack Notifier #4512

Workflow file for this run

name: 'Mend Slack Notifier'
on:
discussion:
types: [created, labeled]
permissions:
discussions: read
jobs:
slack:
if: >
(github.event.action == 'created' && contains(github.event.discussion.labels.*.name, 'mend-app')) ||
(github.event.action == 'labeled' && github.event.label.name == 'mend-app')
runs-on: ubuntu-slim
steps:
- name: Calculate time ago
id: timeago
env:
CREATED_AT: ${{ github.event.discussion.created_at }}
run: |
created_at="$CREATED_AT"
created_epoch=$(date -d "$created_at" "+%s")
now_epoch=$(date +%s)
diff=$((now_epoch - created_epoch))
if [ $diff -lt 86400 ]; then
hours=$((diff / 3600))
echo "ago=$hours hours ago" >> "$GITHUB_OUTPUT"
else
days=$((diff / 86400))
echo "ago=$days days ago" >> "$GITHUB_OUTPUT"
fi
- name: Post to Slack
id: slack
uses: slackapi/slack-github-action@dcb1066f776dd043e64d0e8ba94ca15cc7e1875d # v4.0.0
with:
method: chat.postMessage
payload: |
channel: 'C05NLTMGCJC'
text: ${{ toJSON(format('<{0}|{1}> ({2}, {3})', github.event.discussion.html_url, github.event.discussion.title, github.event.discussion.created_at, steps.timeago.outputs.ago)) }}
errors: true
token: ${{ secrets.SLACK_BOT_TOKEN }}