Skip to content

Commit 44bff2e

Browse files
Update Security-Notification.yml
Remove test code
1 parent b9142ee commit 44bff2e

1 file changed

Lines changed: 12 additions & 26 deletions

File tree

.github/workflows/Security-Notification.yml

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,23 @@ jobs:
1717
GH_TOKEN: ${{ secrets.DEPENDABOT_PAT }}
1818
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK}}
1919
run: |
20-
echo "--- TEST MODE ACTIVE ---"
21-
echo "Fetching ALL alerts (Open, Fixed, Dismissed) to verify Slack connection..."
22-
23-
# 1. Fetch alerts via API
24-
# We use '?state=all' to find old/closed alerts
25-
# We use 'per_page=1' because we only need one example to test
26-
RESPONSE=$(curl -s -H "Authorization: token $GH_TOKEN" \
27-
-H "Accept: application/vnd.github+json" \
28-
"https://api.github.com/repos/${{ github.repository }}/dependabot/alerts?q=is%3Aclosed")
20+
# 1. Calculate time 65 minutes ago
21+
TIME_THRESHOLD=$(date -u -d '65 minutes ago' +'%Y-%m-%dT%H:%M:%SZ')
22+
23+
echo "Checking for alerts created after: $TIME_THRESHOLD"
2924
30-
# 2. Check for Authentication Errors
31-
if echo "$RESPONSE" | grep -q "Bad credentials"; then
32-
echo "::error::Authentication Failed! Please check your DEPENDABOT_PAT secret."
33-
exit 1
34-
fi
25+
# 2. Fetch alerts using GitHub CLI
26+
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\")")
3528
36-
# 3. Parse the result
37-
# We just grab the first alert found. No time filter. No severity filter.
38-
ALERTS=$(echo "$RESPONSE" | jq '.')
39-
40-
# Check if the list is empty (Repo has NEVER had an alert)
41-
LENGTH=$(echo "$ALERTS" | jq 'length')
42-
if [ "$LENGTH" -eq 0 ]; then
43-
echo "::warning:: No alerts found (Open or Closed). This repo has clean history!"
29+
# 3. Check if any alerts were found
30+
if [ -z "$ALERTS" ]; then
31+
echo "No new alerts found in the last hour."
4432
exit 0
4533
fi
4634
47-
echo "Found historical alert data. Sending Slack notification..."
48-
35+
echo "New alerts detected! Sending notification..."
36+
4937
# 4. Extract details from the first alert found
5038
PACKAGE=$(echo "$ALERTS" | jq -r '.[0] | .dependency.package.name')
5139
SEVERITY=$(echo "$ALERTS" | jq -r '.[0] | .security_advisory.severity')
@@ -57,8 +45,6 @@ jobs:
5745
ISSUE_USER="Dependabot"
5846
ISSUE_URL=$(echo "$ALERTS" | jq -r '.[0] | .html_url')
5947
60-
# FIX: We pass the template string as an argument (--arg template)
61-
# This prevents the "syntax error: unexpected '*'" because jq doesn't try to parse the asterisks as code.
6248
MESSAGE_TEXT=$(jq -n \
6349
--arg repo "$REPO_NAME" \
6450
--arg title "$ISSUE_TITLE" \

0 commit comments

Comments
 (0)