From 91a087aacc6465450afe661617ca1f2ce8760dd8 Mon Sep 17 00:00:00 2001 From: Mahipal <42860185+mukul975@users.noreply.github.com> Date: Wed, 15 Apr 2026 22:35:07 +0200 Subject: [PATCH] Update star.yml --- .github/workflows/star.yml | 53 ++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/.github/workflows/star.yml b/.github/workflows/star.yml index 35ca4dde..6d961eb0 100644 --- a/.github/workflows/star.yml +++ b/.github/workflows/star.yml @@ -1,4 +1,4 @@ -# .github/workflows/star-milestones.yml + name: Star Milestone Tracker on: @@ -19,21 +19,34 @@ jobs: SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }} REPO: mukul975/Anthropic-Cybersecurity-Skills run: | + # Get current star count STARS=$(curl -s -H "Authorization: token $GH_TOKEN" \ https://api.github.com/repos/$REPO | jq .stargazers_count) echo "Current stars: $STARS" - LAST=$(curl -s -H "Authorization: token $GH_TOKEN" \ - "https://api.github.com/repos/$REPO/actions/variables/LAST_STAR_MILESTONE" \ - | jq -r '.value // "0"') + # Get last notified milestone + LAST_RESPONSE=$(curl -s -w "\n%{http_code}" \ + -H "Authorization: token $GH_TOKEN" \ + "https://api.github.com/repos/$REPO/actions/variables/LAST_STAR_MILESTONE") + HTTP_STATUS=$(echo "$LAST_RESPONSE" | tail -n1) + LAST=$(echo "$LAST_RESPONSE" | head -n1 | jq -r '.value // "0"') + + # If variable doesn't exist yet, treat as 0 + if [ "$HTTP_STATUS" = "404" ]; then + LAST="0" + fi echo "Last notified milestone: $LAST" - # Highest multiple of 500 crossed but not yet notified + # Calculate highest multiple of 500 crossed NOTIFY_MILESTONE=$(( (STARS / 500) * 500 )) + NEXT=$(( (STARS / 500 + 1) * 500 )) + + echo "Current milestone: $NOTIFY_MILESTONE | Next: $NEXT ($(( NEXT - STARS )) stars to go)" if [ "$NOTIFY_MILESTONE" -gt "$LAST" ] && [ "$NOTIFY_MILESTONE" -gt 0 ]; then - echo "🎉 New milestone: $NOTIFY_MILESTONE" + echo "🎉 New milestone hit: $NOTIFY_MILESTONE" + # Send Slack notification curl -X POST "$SLACK_WEBHOOK" \ -H 'Content-type: application/json' \ -d "{ @@ -43,17 +56,31 @@ jobs: \"fields\": [ {\"title\": \"Milestone\", \"value\": \"$NOTIFY_MILESTONE stars 🎯\", \"short\": true}, {\"title\": \"Current Stars\", \"value\": \"$STARS ⭐\", \"short\": true}, - {\"title\": \"Repo\", \"value\": \"$REPO\", \"short\": false} + {\"title\": \"Repo\", \"value\": \"$REPO\", \"short\": false}, + {\"title\": \"Link\", \"value\": \"https://github.com/$REPO\", \"short\": false} ] }] }" - curl -s -X PATCH \ - -H "Authorization: token $GH_TOKEN" \ - -H "Content-type: application/json" \ - "https://api.github.com/repos/$REPO/actions/variables/LAST_STAR_MILESTONE" \ - -d "{\"name\":\"LAST_STAR_MILESTONE\",\"value\":\"$NOTIFY_MILESTONE\"}" + # Update or create the variable + if [ "$HTTP_STATUS" = "404" ]; then + # Create variable + curl -s -X POST \ + -H "Authorization: token $GH_TOKEN" \ + -H "Content-type: application/json" \ + "https://api.github.com/repos/$REPO/actions/variables" \ + -d "{\"name\":\"LAST_STAR_MILESTONE\",\"value\":\"$NOTIFY_MILESTONE\"}" + echo "Created LAST_STAR_MILESTONE = $NOTIFY_MILESTONE" + else + # Update variable + curl -s -X PATCH \ + -H "Authorization: token $GH_TOKEN" \ + -H "Content-type: application/json" \ + "https://api.github.com/repos/$REPO/actions/variables/LAST_STAR_MILESTONE" \ + -d "{\"name\":\"LAST_STAR_MILESTONE\",\"value\":\"$NOTIFY_MILESTONE\"}" + echo "Updated LAST_STAR_MILESTONE = $NOTIFY_MILESTONE" + fi + else - NEXT=$(( (STARS / 500 + 1) * 500 )) echo "No new milestone. Next at $NEXT stars ($(( NEXT - STARS )) to go)" fi