-
Notifications
You must be signed in to change notification settings - Fork 147
133 lines (110 loc) · 4.07 KB
/
ecwoc26-daily-leaderboard.yml
File metadata and controls
133 lines (110 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
name: 🏆 ECWoC'26 Daily Contributor Leaderboard
on:
schedule:
- cron: "30 13 * * *" # Runs daily at 7:00 PM IST (13:30 UTC)
workflow_dispatch:
permissions:
issues: write
pull-requests: read
contents: read
jobs:
leaderboard:
runs-on: ubuntu-latest
steps:
- name: Generate ECWoC'26 Daily Contributor Leaderboard
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const DAYS = 1; // Daily leaderboard
console.log(`🏆 Generating ECWoC'26 leaderboard for last ${DAYS} day(s)`);
const since = new Date();
since.setDate(since.getDate() - DAYS);
const stats = {};
const isValidUser = (user) =>
user &&
!user.endsWith('[bot]') &&
user !== owner;
const add = (user, type) => {
if (!isValidUser(user)) return;
if (!stats[user]) {
stats[user] = { prs: 0, merged: 0, issues: 0 };
}
stats[user][type]++;
};
// Fetch Pull Requests
const prs = await github.paginate(
github.rest.pulls.list,
{ owner, repo, state: "all", per_page: 100 }
);
prs.forEach(pr => {
if (new Date(pr.created_at) >= since) {
add(pr.user.login, "prs");
if (pr.merged_at) add(pr.user.login, "merged");
}
});
// Fetch Issues
const issues = await github.paginate(
github.rest.issues.listForRepo,
{ owner, repo, state: "all", per_page: 100 }
);
issues.forEach(issue => {
if (!issue.pull_request && new Date(issue.created_at) >= since) {
add(issue.user.login, "issues");
}
});
const leaderboard = Object.entries(stats)
.map(([user, data]) => ({
user,
...data,
total: data.prs + data.merged + data.issues
}))
.sort((a, b) => b.total - a.total)
.slice(0, 10);
if (leaderboard.length === 0) {
console.log("⚠️ No ECWoC'26 contributors found today.");
return;
}
const medals = ["🥇", "🥈", "🥉"];
const rows = leaderboard.map((c, i) => {
const rank = medals[i] || `#${i + 1}`;
return `| ${rank} | @${c.user} | ${c.prs} | ${c.merged} | ${c.issues} | ${c.total} |`;
});
const body = `
## 🏆 ECWoC'26 Daily Contributor Leaderboard
⏱ **Last ${DAYS} Day**
| Rank | Contributor | PRs | Merged | Issues | Total |
|------|-------------|-----|--------|--------|-------|
${rows.join("\n")}
🎉 **Keep contributing!**
Every PR & Issue counts towards **ECWoC'26** 🚀
---
🤖 _Auto-generated daily for ECWoC'26_
`;
// Check existing leaderboard issue
const existing = await github.rest.issues.listForRepo({
owner,
repo,
labels: "ECWoC26,leaderboard",
state: "open"
});
if (existing.data.length > 0) {
await github.rest.issues.update({
owner,
repo,
issue_number: existing.data[0].number,
body
});
console.log("♻️ Updated ECWoC'26 leaderboard issue");
} else {
await github.rest.issues.create({
owner,
repo,
title: "🏆 ECWoC'26 Daily Contributor Leaderboard",
body,
labels: ["ECWoC26", "leaderboard", "automated"]
});
console.log("✅ Created ECWoC'26 leaderboard issue");
}