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