Skip to content

Mend Slack Notifier #4293

Mend Slack Notifier

Mend Slack Notifier #4293

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-latest
steps:
- name: Calculate time ago
id: timeago
run: |
created_at="${{ github.event.discussion.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@fc46ded2fc4d7f11bfa62864526f920cf1a1167d # v3.0.4
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 }}