133 lines
5.1 KiB
YAML
133 lines
5.1 KiB
YAML
name: Slack Notify First Responders
|
|
|
|
on:
|
|
issues:
|
|
types: [labeled]
|
|
|
|
env:
|
|
PRIORITY_LABELS: '["priority:P0", "priority:P1"]'
|
|
REPRODUCIBLE_LABEL: 'state:reproducible'
|
|
FREQUENCY_LABELS: '["frequency:always", "frequency:common"]'
|
|
|
|
jobs:
|
|
notify-slack:
|
|
if: github.repository_owner == 'zed-industries' && github.event.issue.state == 'open'
|
|
runs-on: namespace-profile-2x4-ubuntu-2404
|
|
# Serialize per-issue so concurrent `labeled` events can't both observe
|
|
# the trifecta and double-notify.
|
|
concurrency:
|
|
group: slack-notify-first-responders-${{ github.event.issue.number }}
|
|
cancel-in-progress: false
|
|
|
|
steps:
|
|
- name: Check if label combination requires first responder notification
|
|
id: check-label
|
|
env:
|
|
LABEL_NAME: ${{ github.event.label.name }}
|
|
ISSUE_LABELS_JSON: ${{ toJson(github.event.issue.labels.*.name) }}
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
# Gate on the just-added label so unrelated labeling on an
|
|
# already-qualifying issue doesn't re-fire the notification.
|
|
TRIGGER_LABELS=$(jq -cn \
|
|
--argjson priority "$PRIORITY_LABELS" \
|
|
--arg repro "$REPRODUCIBLE_LABEL" \
|
|
--argjson freq "$FREQUENCY_LABELS" \
|
|
'$priority + [$repro] + $freq')
|
|
|
|
if ! echo "$TRIGGER_LABELS" | jq -e --arg l "$LABEL_NAME" 'index($l) != null' > /dev/null; then
|
|
echo "Added label '$LABEL_NAME' is not in the trigger set, skipping"
|
|
echo "should_notify=false" >> "$GITHUB_OUTPUT"
|
|
exit 0
|
|
fi
|
|
|
|
MATCHED_PRIORITY=$(echo "$ISSUE_LABELS_JSON" | jq -r --argjson priority "$PRIORITY_LABELS" 'map(select(. as $x | $priority | index($x) != null)) | first // ""')
|
|
HAS_REPRO=$(echo "$ISSUE_LABELS_JSON" | jq --arg l "$REPRODUCIBLE_LABEL" 'index($l) != null')
|
|
HAS_FREQ=$(echo "$ISSUE_LABELS_JSON" | jq --argjson freq "$FREQUENCY_LABELS" 'any(.[]; . as $x | $freq | index($x) != null)')
|
|
|
|
if [ -n "$MATCHED_PRIORITY" ] && [ "$HAS_REPRO" = "true" ] && [ "$HAS_FREQ" = "true" ]; then
|
|
echo "Confirmed high-frequency $MATCHED_PRIORITY, notifying"
|
|
echo "notify_reason=confirmed $MATCHED_PRIORITY" >> "$GITHUB_OUTPUT"
|
|
echo "should_notify=true" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "Combination not yet satisfied (priority=$MATCHED_PRIORITY, reproducible=$HAS_REPRO, frequency=$HAS_FREQ), skipping"
|
|
echo "should_notify=false" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
- name: Build Slack message payload
|
|
if: steps.check-label.outputs.should_notify == 'true'
|
|
env:
|
|
ISSUE_TITLE: ${{ github.event.issue.title }}
|
|
ISSUE_URL: ${{ github.event.issue.html_url }}
|
|
LABELED_BY: ${{ github.event.sender.login }}
|
|
NOTIFY_REASON: ${{ steps.check-label.outputs.notify_reason }}
|
|
LABELS_JSON: ${{ toJson(github.event.issue.labels.*.name) }}
|
|
run: |
|
|
LABELS=$(echo "$LABELS_JSON" | jq -r 'join(", ")')
|
|
|
|
jq -n \
|
|
--arg notify_reason "$NOTIFY_REASON" \
|
|
--arg issue_title "$ISSUE_TITLE" \
|
|
--arg issue_url "$ISSUE_URL" \
|
|
--arg labeled_by "$LABELED_BY" \
|
|
--arg labels "$LABELS" \
|
|
'{
|
|
"blocks": [
|
|
{
|
|
"type": "section",
|
|
"text": {
|
|
"type": "mrkdwn",
|
|
"text": "<!subteam^S096CPUUGLF> New *\($notify_reason)* issue"
|
|
}
|
|
},
|
|
{
|
|
"type": "section",
|
|
"fields": [
|
|
{
|
|
"type": "mrkdwn",
|
|
"text": "*Issue:*\n<\($issue_url)|\($issue_title)>"
|
|
},
|
|
{
|
|
"type": "mrkdwn",
|
|
"text": "*Labeled by:*\n\($labeled_by)"
|
|
},
|
|
{
|
|
"type": "mrkdwn",
|
|
"text": "*Labels:*\n\($labels)"
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}' > payload.json
|
|
|
|
echo "Payload built successfully:"
|
|
cat payload.json
|
|
|
|
- name: Send Slack notification
|
|
if: steps.check-label.outputs.should_notify == 'true'
|
|
env:
|
|
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_FIRST_RESPONDERS }}
|
|
run: |
|
|
if [ -z "$SLACK_WEBHOOK_URL" ]; then
|
|
echo "::error::SLACK_WEBHOOK_FIRST_RESPONDERS secret is not set"
|
|
exit 1
|
|
fi
|
|
|
|
HTTP_RESPONSE=$(curl -s -w "\n%{http_code}" -X POST "$SLACK_WEBHOOK_URL" \
|
|
-H "Content-Type: application/json" \
|
|
-d @payload.json)
|
|
|
|
HTTP_BODY=$(echo "$HTTP_RESPONSE" | sed '$d')
|
|
HTTP_STATUS=$(echo "$HTTP_RESPONSE" | tail -n 1)
|
|
|
|
echo "Slack API response status: $HTTP_STATUS"
|
|
echo "Slack API response body: $HTTP_BODY"
|
|
|
|
if [ "$HTTP_STATUS" -ne 200 ]; then
|
|
echo "::error::Slack notification failed with status $HTTP_STATUS: $HTTP_BODY"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Slack notification sent successfully"
|