Skip to content

Commit 750b420

Browse files
Update Security-Notification.yml
Fixed index object with number error
1 parent 44bff2e commit 750b420

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

.github/workflows/Security-Notification.yml

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
name: Security Vulnerability Slack Notification
2+
23
on:
34
schedule:
45
- cron: '0 * * * *' # Runs every hour
@@ -13,38 +14,41 @@ jobs:
1314

1415
- name: Check for Recent Alerts
1516
env:
16-
# Use a PAT instead of the default token
1717
GH_TOKEN: ${{ secrets.DEPENDABOT_PAT }}
18-
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK}}
18+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
1919
run: |
20-
# 1. Calculate time 65 minutes ago
20+
# 1. Calculate time 65 minutes ago
2121
TIME_THRESHOLD=$(date -u -d '65 minutes ago' +'%Y-%m-%dT%H:%M:%SZ')
2222
2323
echo "Checking for alerts created after: $TIME_THRESHOLD"
2424
2525
# 2. Fetch alerts using GitHub CLI
26+
# FIX: Added [ ] wrapping to force output as an Array [{...}]
2627
ALERTS=$(gh api "/repos/${{ github.repository }}/dependabot/alerts" \
27-
--jq ".[] | select(.state == \"open\") | select(.created_at > \"$TIME_THRESHOLD\") | select(.security_advisory.severity == \"critical\" or .security_advisory.severity == \"high\")")
28+
--jq "[ .[] | select(.state == \"open\") | select(.created_at > \"$TIME_THRESHOLD\") | select(.security_advisory.severity == \"critical\" or .security_advisory.severity == \"high\") ]")
2829
2930
# 3. Check if any alerts were found
30-
if [ -z "$ALERTS" ]; then
31+
# Now valid because ALERTS is definitely an array
32+
LENGTH=$(echo "$ALERTS" | jq 'length')
33+
34+
if [ "$LENGTH" -eq 0 ]; then
3135
echo "No new alerts found in the last hour."
3236
exit 0
3337
fi
3438
3539
echo "New alerts detected! Sending notification..."
3640
3741
# 4. Extract details from the first alert found
42+
# Now valid because ALERTS is an array, so .[0] exists
3843
PACKAGE=$(echo "$ALERTS" | jq -r '.[0] | .dependency.package.name')
3944
SEVERITY=$(echo "$ALERTS" | jq -r '.[0] | .security_advisory.severity')
40-
STATE=$(echo "$ALERTS" | jq -r '.[0] | .state')
41-
42-
REPO_NAME="${{ github.repository }}"
4345
44-
ISSUE_TITLE=$(echo "$ALERTS" | jq -r '.[0] | .dependency.package.name + " (" + .security_advisory.severity + ")"')
46+
REPO_NAME="${{ github.repository }}"
47+
ISSUE_TITLE="${PACKAGE} (${SEVERITY})"
4548
ISSUE_USER="Dependabot"
4649
ISSUE_URL=$(echo "$ALERTS" | jq -r '.[0] | .html_url')
4750
51+
# 5. Build Message
4852
MESSAGE_TEXT=$(jq -n \
4953
--arg repo "$REPO_NAME" \
5054
--arg title "$ISSUE_TITLE" \
@@ -53,7 +57,7 @@ jobs:
5357
--arg template "*📢 New Dependabot Alert ($REPO_NAME) 📢*\n\n*Issue Title:* $ISSUE_TITLE\n*Opened By:* $ISSUE_USER\n\n*View Issue:* $ISSUE_URL" \
5458
'$template')
5559
56-
# Build Slack payload
60+
# 6. Build Payload
5761
SLACK_PAYLOAD=$(jq -n \
5862
--arg text "$MESSAGE_TEXT" \
5963
'{
@@ -63,7 +67,7 @@ jobs:
6367
"text": $text
6468
}')
6569
66-
# Send to Slack
70+
# 7. Send to Slack
6771
curl -X POST \
6872
-H 'Content-type: application/json' \
6973
--data "$SLACK_PAYLOAD" \

0 commit comments

Comments
 (0)