Testing for slack integration #30
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow sends a notification to Slack when an issue labeled 'type-bug' is opened, edited, or labeled and the 'Anaconda.org' checkbox is checked in the issue description. | |
name: Anaconda.org Issues Notification to Slack | |
on: | |
issues: | |
types: [opened, edited, labeled] | |
jobs: | |
check-conditions: | |
if: contains(github.event.issue.labels.*.name, 'type-bug') | |
runs-on: | |
labels: ubuntu-latest | |
outputs: | |
should-notify: ${{ steps.filter.outputs.should-notify }} | |
steps: | |
- name: Check if "Anaconda.org" checkbox is checked | |
id: filter | |
run: | | |
body="${{ github.event.issue.body }}" | |
search_term="- [x] Anaconda.org" | |
if printf '%s\n' "$body" | grep -Fxq -- "$search_term"; then | |
echo "::set-output name=should-notify::true" | |
else | |
echo "::set-output name=should-notify::false" | |
fi | |
notify-slack: | |
if: needs.check-conditions.outputs.should-notify == 'true' | |
runs-on: ubuntu-latest | |
needs: [check-conditions] | |
steps: | |
- name: Send message to Slack | |
env: | |
# Tokens and url are stored in the repository's secrets settings | |
SLACK_CHANNEL_ID: ${{ secrets.DOT_ORG_SLACK_CHANNEL_ID }} | |
SLACK_BOT_TOKEN: ${{ secrets.DOT_ORG_SLACK_BOT_TOKEN }} | |
SLACK_TITLE: "Issue with 'type-bug' label Detected" | |
SLACK_MESSAGE: "Title: ${{ github.event.issue.title }} - URL: ${{ github.event.issue.html_url }}" | |
run: | | |
response=$(curl -X POST -H 'Content-type: application/json' -H "Authorization: Bearer $SLACK_BOT_TOKEN" --data '{ | |
"channel":"'"$SLACK_CHANNEL_ID"'", | |
"text":"'"$SLACK_TITLE"'", | |
"attachments": [ | |
{ | |
"text": "'"$SLACK_MESSAGE"'" | |
} | |
] | |
}' https://slack.com/api/chat.postMessage) | |
echo $response |