1name: Slack Notify First Responders
2
3on:
4 issues:
5 types: [labeled]
6
7env:
8 FIRST_RESPONDER_LABELS: '["priority:P0", "priority:P1"]'
9
10jobs:
11 notify-slack:
12 if: github.repository_owner == 'zed-industries'
13 runs-on: ubuntu-latest
14
15 steps:
16 - name: Check if label requires first responder notification
17 id: check-label
18 env:
19 LABEL_NAME: ${{ github.event.label.name }}
20 run: |
21 if echo '${{ env.FIRST_RESPONDER_LABELS }}' | jq -e --arg label "$LABEL_NAME" 'index($label) != null' > /dev/null; then
22 echo "should_notify=true" >> "$GITHUB_OUTPUT"
23 echo "Label '$LABEL_NAME' requires first responder notification"
24 else
25 echo "should_notify=false" >> "$GITHUB_OUTPUT"
26 echo "Label '$LABEL_NAME' does not require first responder notification, skipping"
27 fi
28
29 - name: Build Slack message payload
30 if: steps.check-label.outputs.should_notify == 'true'
31 env:
32 ISSUE_TITLE: ${{ github.event.issue.title }}
33 ISSUE_URL: ${{ github.event.issue.html_url }}
34 LABELED_BY: ${{ github.event.sender.login }}
35 LABEL_NAME: ${{ github.event.label.name }}
36 LABELS_JSON: ${{ toJson(github.event.issue.labels.*.name) }}
37 run: |
38 LABELS=$(echo "$LABELS_JSON" | jq -r 'join(", ")')
39
40 jq -n \
41 --arg label_name "$LABEL_NAME" \
42 --arg issue_title "$ISSUE_TITLE" \
43 --arg issue_url "$ISSUE_URL" \
44 --arg labeled_by "$LABELED_BY" \
45 --arg labels "$LABELS" \
46 '{
47 "blocks": [
48 {
49 "type": "section",
50 "text": {
51 "type": "mrkdwn",
52 "text": "<!subteam^S096CPUUGLF> Issue labeled *\($label_name)*"
53 }
54 },
55 {
56 "type": "section",
57 "fields": [
58 {
59 "type": "mrkdwn",
60 "text": "*Issue:*\n<\($issue_url)|\($issue_title)>"
61 },
62 {
63 "type": "mrkdwn",
64 "text": "*Labeled by:*\n\($labeled_by)"
65 },
66 {
67 "type": "mrkdwn",
68 "text": "*Labels:*\n\($labels)"
69 }
70 ]
71 }
72 ]
73 }' > payload.json
74
75 echo "Payload built successfully:"
76 cat payload.json
77
78 - name: Send Slack notification
79 if: steps.check-label.outputs.should_notify == 'true'
80 env:
81 SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_FIRST_RESPONDERS }}
82 run: |
83 if [ -z "$SLACK_WEBHOOK_URL" ]; then
84 echo "::error::SLACK_WEBHOOK_FIRST_RESPONDERS secret is not set"
85 exit 1
86 fi
87
88 HTTP_RESPONSE=$(curl -s -w "\n%{http_code}" -X POST "$SLACK_WEBHOOK_URL" \
89 -H "Content-Type: application/json" \
90 -d @payload.json)
91
92 HTTP_BODY=$(echo "$HTTP_RESPONSE" | sed '$d')
93 HTTP_STATUS=$(echo "$HTTP_RESPONSE" | tail -n 1)
94
95 echo "Slack API response status: $HTTP_STATUS"
96 echo "Slack API response body: $HTTP_BODY"
97
98 if [ "$HTTP_STATUS" -ne 200 ]; then
99 echo "::error::Slack notification failed with status $HTTP_STATUS: $HTTP_BODY"
100 exit 1
101 fi
102
103 echo "Slack notification sent successfully"