11name : Security Vulnerability Slack Notification
22
33on :
4+ # The real trigger (fires on real alerts)
45 repository_vulnerability_alert :
56 types : [create]
7+
8+ # The manual trigger (for testing)
9+ workflow_dispatch :
10+ inputs :
11+ mock_package :
12+ description : ' Package Name'
13+ required : true
14+ default : ' axios (Test)'
15+ mock_severity :
16+ description : ' Severity'
17+ required : true
18+ default : ' critical'
19+ type : choice
20+ options :
21+ - critical
22+ - high
23+ - moderate
24+ - low
625
726jobs :
827 notify-slack :
@@ -11,13 +30,15 @@ jobs:
1130 - name : Send Slack Notification
1231 env :
1332 SLACK_WEBHOOK_URL : ${{ secrets.SLACK_WEBHOOK_URL }}
14- # Extract alert details from the event payload
15- PACKAGE_NAME : ${{ github.event.alert.affected_package_name }}
16- SEVERITY : ${{ github.event.alert.severity }}
17- ALERT_URL : ${{ github.event.alert.html_url }}
18- ECOSYSTEM : ${{ github.event.alert.affected_range }}
33+ # LOGIC: Use real data if available, otherwise use manual inputs (or defaults)
34+ PACKAGE_NAME : ${{ github.event.alert.affected_package_name || inputs.mock_package || 'Test-Package' }}
35+ SEVERITY : ${{ github.event.alert.severity || inputs.mock_severity || 'high' }}
36+ ALERT_URL : ${{ github.event.alert.html_url || github.server_url }}
1937 run : |
20- # Map severity to an emoji for better visibility
38+ echo "Triggered by: ${{ github.event_name }}"
39+ echo "Package: $PACKAGE_NAME"
40+
41+ # Map severity to an emoji
2142 if [ "$SEVERITY" == "critical" ]; then
2243 EMOJI=":rotating_light:"
2344 elif [ "$SEVERITY" == "high" ]; then
2647 EMOJI=":information_source:"
2748 fi
2849
29- # Construct the JSON payload
50+ # JSON Payload
3051 PAYLOAD=$(cat <<EOF
3152 {
3253 "channel": "#docs-devdocs-notifications",
4061 "type": "section",
4162 "text": {
4263 "type": "mrkdwn",
43- "text": "$EMOJI *New Vulnerability Alert Detected*"
64+ "text": "$EMOJI *New Vulnerability Alert Detected* (Trigger: ${{ github.event_name }}) "
4465 }
4566 },
4667 {
7091 EOF
7192 )
7293
73- # Send the request
7494 curl -X POST -H 'Content-type: application/json' --data "$PAYLOAD" "$SLACK_WEBHOOK_URL"
0 commit comments