Skip to content

Commit 2b5d931

Browse files
committed
ci: add star milestone tracker workflow
1 parent fc08d00 commit 2b5d931

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

.github/workflows/star-tracker.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Star Milestone Tracker
2+
3+
on:
4+
schedule:
5+
# Run every 6 hours
6+
- cron: '0 */6 * * *'
7+
workflow_dispatch:
8+
9+
jobs:
10+
track-stars:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Check star milestones and notify
14+
env:
15+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16+
REPO: ${{ github.repository }}
17+
run: |
18+
python3 << 'PYEOF'
19+
import requests, os, json
20+
21+
token = os.environ['GH_TOKEN']
22+
repo = os.environ['REPO']
23+
headers = {'Authorization': f'token {token}', 'Accept': 'application/vnd.github.v3+json'}
24+
25+
# Get current star count
26+
r = requests.get(f'https://api.github.com/repos/{repo}', headers=headers)
27+
data = r.json()
28+
current_stars = data['stargazers_count']
29+
repo_name = data['name']
30+
31+
print(f"Current stars for {repo}: {current_stars}")
32+
33+
# Milestones to celebrate
34+
milestones = [10, 25, 50, 100, 150, 200, 250, 300, 400, 500, 750, 1000, 1500, 2000, 5000, 10000]
35+
36+
# Check if we just crossed a milestone
37+
for milestone in milestones:
38+
if current_stars >= milestone:
39+
# Check if we have a file tracking the last celebrated milestone
40+
try:
41+
r2 = requests.get(
42+
f'https://api.github.com/repos/{repo}/contents/.github/star_milestone.txt',
43+
headers=headers
44+
)
45+
if r2.status_code == 200:
46+
last_milestone = int(requests.utils.unquote(
47+
__import__('base64').b64decode(r2.json()['content']).decode().strip()
48+
))
49+
else:
50+
last_milestone = 0
51+
except:
52+
last_milestone = 0
53+
54+
if current_stars >= milestone and last_milestone < milestone:
55+
print(f"MILESTONE REACHED: {milestone} stars!")
56+
# Create a GitHub Discussion to celebrate
57+
# (This would normally trigger a notification)
58+
print(f"Celebration: {repo_name} has reached {milestone} stars!")
59+
break
60+
61+
PYEOF

0 commit comments

Comments
 (0)