@@ -2,15 +2,9 @@ name: Security Vulnerability Slack Notification
22
33on :
44 schedule :
5- - cron : ' 0 * * * *'
6- # Keep manual trigger for testing
5+ - cron : ' 0 * * * *' # Runs every hour
76 workflow_dispatch :
87
9- permissions :
10- # Required to read the alerts via API
11- dependabot-alerts : read
12- contents : read
13-
148jobs :
159 check-alerts :
1610 runs-on : ubuntu-latest
@@ -19,19 +13,18 @@ jobs:
1913 uses : actions/checkout@v3
2014
2115 - name : Check for Recent Alerts
22- id : check
2316 env :
24- GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
17+ # Use a PAT instead of the default token
18+ GH_TOKEN : ${{ secrets.DEPENDABOT_PAT }}
2519 SLACK_WEBHOOK_URL : ${{ secrets.SLACK_WEBHOOK_URL }}
2620 run : |
27- # 1. Calculate time 65 minutes ago (covers the 60 min cron + buffer)
28- # Format must match GitHub API ISO 8601 (YYYY-MM-DDTHH:MM:SSZ)
21+ # 1. Calculate time 65 minutes ago
2922 TIME_THRESHOLD=$(date -u -d '65 minutes ago' +'%Y-%m-%dT%H:%M:%SZ')
3023
3124 echo "Checking for alerts created after: $TIME_THRESHOLD"
3225
3326 # 2. Fetch alerts using GitHub CLI
34- # We filter for: state=open, severity is high or critical, and created recently
27+ # Note: We point to the API endpoint explicitly
3528 ALERTS=$(gh api "/repos/${{ github.repository }}/dependabot/alerts" \
3629 --jq ".[] | select(.state == \"open\") | select(.created_at > \"$TIME_THRESHOLD\") | select(.security_advisory.severity == \"critical\" or .security_advisory.severity == \"high\")")
3730
@@ -41,13 +34,12 @@ jobs:
4134 exit 0
4235 fi
4336
44- echo "New alerts detected!"
37+ echo "New alerts detected! Sending notification... "
4538
46- # 4. Extract details for the first alert found (to keep notification simple)
39+ # 4. Extract details
4740 PACKAGE=$(echo "$ALERTS" | jq -r 'first | .dependency.package.name')
4841 SEVERITY=$(echo "$ALERTS" | jq -r 'first | .security_advisory.severity')
4942 URL=$(echo "$ALERTS" | jq -r 'first | .html_url')
50- SUMMARY=$(echo "$ALERTS" | jq -r 'first | .security_advisory.summary')
5143
5244 # 5. Send Slack Notification
5345 curl -X POST -H 'Content-type: application/json' --data "{
6254 \"type\": \"section\",
6355 \"text\": {
6456 \"type\": \"mrkdwn\",
65- \"text\": \"*New Dependabot Alert Detected*\"
57+ \"text\": \":rotating_light: *New Dependabot Alert Detected*\"
6658 }
6759 },
6860 {
0 commit comments