-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
225 lines (201 loc) · 6.26 KB
/
index.html
File metadata and controls
225 lines (201 loc) · 6.26 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>HSSoC Contributor Leaderboard</title>
<style>
body {
font-family: 'Segoe UI', sans-serif;
margin: 0;
padding: 2rem;
background-color: #f9f9f9;
}
h1 {
text-align: center;
color: #222;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 2rem;
}
th, td {
padding: 12px;
border: 1px solid #ddd;
text-align: left;
}
th {
background-color: #007acc;
color: white;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
input[type="text"] {
width: 100%;
padding: 10px;
margin-top: 1rem;
margin-bottom: 1rem;
font-size: 1rem;
border: 1px solid #ccc;
}
.loading {
text-align: center;
padding: 20px;
font-style: italic;
color: #666;
}
.error {
color: #d9534f;
text-align: center;
padding: 20px;
}
</style>
</head>
<body>
<h1>🚀 HSSoC Contributor Leaderboard</h1>
<input type="text" id="searchInput" placeholder="Search by GitHub username..." />
<table id="leaderboard">
<thead>
<tr>
<th>Rank</th>
<th>Username</th>
<th>Total Contributions</th>
<th>Repositories Contributed</th>
<th>Profile</th>
</tr>
</thead>
<tbody id="leaderboardBody">
<tr>
<td colspan="5" class="loading">Loading repositories and contributor data from GitHub...</td>
</tr>
</tbody>
</table>
<script>
// Configuration
const ORGANIZATION = "HashSlap-Summer-of-Code";
const MAX_REPOS = 3; // Limit to 3 most active repos to avoid rate limits
// Store aggregated contributor data
let contributors = [];
// Function to fetch organization repositories
async function fetchOrganizationRepos() {
try {
const response = await fetch(
`https://api.github.com/orgs/${ORGANIZATION}/repos?sort=updated&per_page=${MAX_REPOS}`
);
if (!response.ok) {
if (response.status === 403) {
throw new Error("GitHub API rate limit exceeded - try again later");
}
throw new Error(`Failed to fetch repositories: ${response.status}`);
}
const repos = await response.json();
return repos.map(repo => repo.full_name);
} catch (error) {
console.error("Error fetching repositories:", error);
throw error;
}
}
// Function to fetch contributors from a repository
async function fetchRepoContributors(repo) {
try {
const response = await fetch(`https://api.github.com/repos/${repo}/contributors`);
if (!response.ok) {
if (response.status === 403) {
throw new Error("GitHub API rate limit exceeded");
}
console.warn(`Skipping ${repo} (may be private)`);
return [];
}
return await response.json();
} catch (error) {
console.error(`Error fetching contributors for ${repo}:`, error);
return [];
}
}
// Main function to get all contributors
async function fetchAllContributors() {
const allContributors = {};
try {
// Get repositories (limited to MAX_REPOS most recently updated)
const repos = await fetchOrganizationRepos();
if (repos.length === 0) {
throw new Error("No repositories found");
}
// Get contributors for each repo
for (const repo of repos) {
const repoContributors = await fetchRepoContributors(repo);
repoContributors.forEach(contributor => {
const username = contributor.login;
if (!allContributors[username]) {
allContributors[username] = {
username: username,
contributions: 0,
repos: new Set(),
profile: contributor.html_url
};
}
allContributors[username].contributions += contributor.contributions;
allContributors[username].repos.add(repo.split('/')[1]);
});
}
// Convert to sorted array
return Object.values(allContributors)
.map(c => ({
...c,
repos: Array.from(c.repos)
}))
.sort((a, b) => b.contributions - a.contributions);
} catch (error) {
console.error("Error in fetchAllContributors:", error);
throw error;
}
}
// Render the table
function renderTable(data) {
tbody.innerHTML = "";
if (!data || data.length === 0) {
tbody.innerHTML = `
<tr>
<td colspan="5" class="error">No contributor data available</td>
</tr>
`;
return;
}
data.forEach((contributor, index) => {
const row = document.createElement("tr");
row.innerHTML = `
<td>${index + 1}</td>
<td>${contributor.username}</td>
<td>${contributor.contributions}</td>
<td>${contributor.repos.join(", ")}</td>
<td><a href="${contributor.profile}" target="_blank">View Profile</a></td>
`;
tbody.appendChild(row);
});
}
// Initialize
async function init() {
try {
contributors = await fetchAllContributors();
renderTable(contributors);
searchInput.addEventListener("input", (e) => {
const term = e.target.value.toLowerCase();
const filtered = contributors.filter(c =>
c.username.toLowerCase().includes(term)
);
renderTable(filtered);
});
} catch (error) {
tbody.innerHTML = `
<tr>
<td colspan="5" class="error">Error: ${error.message}</td>
</tr>
`;
}
}
init();
</script>
</body>
</html>