forked from mongodb-university/Bluehawk
-
Notifications
You must be signed in to change notification settings - Fork 0
38 lines (36 loc) · 1.44 KB
/
devdocs-notify.yml
File metadata and controls
38 lines (36 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
name: DevDocs PR or Issue Creation Notifier
on:
issues:
types: [opened]
pull_request_target:
types: [opened]
jobs:
notify_slack_on_issue:
runs-on: ubuntu-latest
steps:
- name: Send Slack Notification
env:
# We use || to ensure this works for both 'issues' and 'pull_request' events
EVENT_TITLE: ${{ github.event.issue.title || github.event.pull_request.title }}
EVENT_USER: ${{ github.event.issue.user.login || github.event.pull_request.user.login }}
EVENT_URL: ${{ github.event.issue.html_url || github.event.pull_request.html_url }}
REPO_NAME: ${{ github.repository }}
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
run: |
# Build Slack payload safely in one step to avoid quoting errors
SLACK_PAYLOAD=$(jq -n \
--arg repo "$REPO_NAME" \
--arg title "$EVENT_TITLE" \
--arg user "$EVENT_USER" \
--arg url "$EVENT_URL" \
'{
"channel": "#docs-devdocs-notifications",
"username": "Issue Notifier",
"icon_emoji": ":mega:",
"text": "📢 @DevDocs a PR was opened or issue created in \($repo)\n*Title:* \($title)\n*By:* \($user)\n*URL:* \($url)"
}')
# Send to Slack
curl -X POST \
-H 'Content-type: application/json' \
--data "$SLACK_PAYLOAD" \
"$SLACK_WEBHOOK"