Skip to content

Commit 0d6a8b7

Browse files
.
1 parent 7fd23b2 commit 0d6a8b7

File tree

2 files changed

+76
-6
lines changed

2 files changed

+76
-6
lines changed

contributors.html

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -829,15 +829,32 @@ <h4>Connect With Us</h4>
829829
while (true) {
830830
try {
831831
const url = `https://api.github.com/repos/${owner}/${repo}/contributors?per_page=${perPage}&page=${page}`;
832-
const response = await fetch(url, { headers: getApiHeaders() });
832+
const headers = getApiHeaders();
833+
834+
// Debug: Log request details (remove token from log)
835+
console.log(`Fetching contributors page ${page}`);
836+
console.log('Headers:', { ...headers, Authorization: 'token ***' });
837+
838+
const response = await fetch(url, {
839+
method: 'GET',
840+
headers: headers,
841+
mode: 'cors',
842+
cache: 'no-cache'
843+
});
833844

834845
// Check rate limit
835846
const remaining = response.headers.get('X-RateLimit-Remaining');
836847
const resetTime = response.headers.get('X-RateLimit-Reset');
837848

838849
if (response.status === 401) {
839850
const errorData = await response.json().catch(() => ({}));
840-
throw new Error(`GitHub API authentication failed (401). Token may be invalid or expired. ${errorData.message || 'Please check your token.'}`);
851+
console.error('401 Error Details:', errorData);
852+
console.error('Response Headers:', {
853+
'X-RateLimit-Remaining': remaining,
854+
'X-RateLimit-Reset': resetTime,
855+
'X-GitHub-Media-Type': response.headers.get('X-GitHub-Media-Type')
856+
});
857+
throw new Error(`GitHub API authentication failed (401). ${errorData.message || 'Bad credentials. Token may be invalid, expired, or missing required scopes.'}`);
841858
}
842859

843860
if (response.status === 403) {

leaderboard.html

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,15 +2030,44 @@ <h4>Connect With Us</h4>
20302030
let filteredData = null;
20312031

20322032
// GitHub API headers with hardcoded token
2033+
const GITHUB_TOKEN = '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';
2034+
20332035
function getApiHeaders() {
2034-
const token = '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';
20352036
return {
20362037
'Accept': 'application/vnd.github.v3+json',
20372038
'User-Agent': 'AnimateItNow-Leaderboard',
20382039
// Classic tokens use 'token' prefix
2039-
'Authorization': `token ${token}`
2040+
'Authorization': `token ${GITHUB_TOKEN}`
20402041
};
20412042
}
2043+
2044+
// Validate token by making a test request
2045+
async function validateToken() {
2046+
try {
2047+
const response = await fetch('https://api.github.com/user', {
2048+
method: 'GET',
2049+
headers: getApiHeaders(),
2050+
mode: 'cors'
2051+
});
2052+
2053+
if (response.status === 401) {
2054+
const errorData = await response.json().catch(() => ({}));
2055+
console.error('Token validation failed:', errorData);
2056+
return { valid: false, error: errorData.message || 'Bad credentials' };
2057+
}
2058+
2059+
if (response.ok) {
2060+
const userData = await response.json().catch(() => ({}));
2061+
console.log('✅ Token validated successfully. Authenticated as:', userData.login || 'Unknown');
2062+
return { valid: true, user: userData.login };
2063+
}
2064+
2065+
return { valid: false, error: `Unexpected status: ${response.status}` };
2066+
} catch (error) {
2067+
console.error('Token validation error:', error);
2068+
return { valid: false, error: error.message };
2069+
}
2070+
}
20422071

20432072
// --- UTILITY FUNCTIONS ---
20442073
function scrollToTop() {
@@ -2060,15 +2089,32 @@ <h4>Connect With Us</h4>
20602089
while (page <= maxPages) {
20612090
try {
20622091
const pageUrl = url.includes('?') ? `${url}&page=${page}` : `${url}?page=${page}`;
2063-
const response = await fetch(pageUrl, { headers: getApiHeaders() });
2092+
const headers = getApiHeaders();
2093+
2094+
// Debug: Log request details (remove token from log)
2095+
console.log(`Fetching: ${pageUrl}`);
2096+
console.log('Headers:', { ...headers, Authorization: 'token ***' });
2097+
2098+
const response = await fetch(pageUrl, {
2099+
method: 'GET',
2100+
headers: headers,
2101+
mode: 'cors',
2102+
cache: 'no-cache'
2103+
});
20642104

20652105
// Check rate limit
20662106
const remaining = response.headers.get('X-RateLimit-Remaining');
20672107
const resetTime = response.headers.get('X-RateLimit-Reset');
20682108

20692109
if (response.status === 401) {
20702110
const errorData = await response.json().catch(() => ({}));
2071-
throw new Error(`GitHub API authentication failed (401). Token may be invalid or expired. ${errorData.message || 'Please check your token.'}`);
2111+
console.error('401 Error Details:', errorData);
2112+
console.error('Response Headers:', {
2113+
'X-RateLimit-Remaining': remaining,
2114+
'X-RateLimit-Reset': resetTime,
2115+
'X-GitHub-Media-Type': response.headers.get('X-GitHub-Media-Type')
2116+
});
2117+
throw new Error(`GitHub API authentication failed (401). ${errorData.message || 'Bad credentials. Token may be invalid, expired, or missing required scopes.'}`);
20722118
}
20732119

20742120
if (response.status === 403) {
@@ -2290,6 +2336,13 @@ <h4>Connect With Us</h4>
22902336
}
22912337

22922338
try {
2339+
// Validate token first
2340+
console.log("🔍 Validating GitHub token...");
2341+
const tokenValidation = await validateToken();
2342+
if (!tokenValidation.valid) {
2343+
throw new Error(`Token validation failed: ${tokenValidation.error}. Please check your GitHub token has the 'public_repo' scope.`);
2344+
}
2345+
22932346
console.log("🔄 Fetching fresh data with token...");
22942347

22952348
// Fetch merged pull requests

0 commit comments

Comments
 (0)