Skip to content

Commit ccfa732

Browse files
committed
api: add extra logging for debugging
1 parent c1792eb commit ccfa732

2 files changed

Lines changed: 23 additions & 8 deletions

File tree

.github/workflows/update-contributors.yml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Update Top Contributors
22

33
on:
44
schedule:
5-
- cron: '5 0 * * *' # Runs at 00:05 UTC every day
5+
- cron: '5 0 * * *'
66
workflow_dispatch:
77

88
jobs:
@@ -12,14 +12,26 @@ jobs:
1212
steps:
1313
- name: Update Contributors
1414
run: |
15-
response=$(curl -X POST ${{ secrets.VERCEL_DEPLOYMENT_URL }}/api/updateTopContributors \
15+
echo "Making request to: ${{ secrets.VERCEL_DEPLOYMENT_URL }}/api/updateTopContributors"
16+
echo "Token present: ${{ secrets.FCM_GITHUB_TOKEN != '' }}"
17+
18+
response=$(curl -v -X POST ${{ secrets.VERCEL_DEPLOYMENT_URL }}/api/updateTopContributors \
1619
-H "Authorization: Bearer ${{ secrets.FCM_GITHUB_TOKEN }}" \
1720
-H "Content-Type: application/json" \
1821
-w "\n%{http_code}")
19-
echo "Response: $response"
20-
if [[ $(echo "$response" | tail -n1) != 2* ]]; then
21-
echo "Error: API call failed"
22+
23+
echo "Full response:"
24+
echo "$response"
25+
26+
status_code=$(echo "$response" | tail -n1)
27+
body=$(echo "$response" | head -n1)
28+
29+
echo "Status code: $status_code"
30+
echo "Response body: $body"
31+
32+
if [[ $status_code != 2* ]]; then
33+
echo "Error: API call failed with status: $status_code"
2234
exit 1
2335
fi
2436
env:
25-
GITHUB_TOKEN: ${{ secrets.FCM_GITHUB_TOKEN }}
37+
FCM_GITHUB_TOKEN: ${{ secrets.FCM_GITHUB_TOKEN }}

pages/api/updateTopContributors.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { storeTopThreeUsersInDb } from '../../utils/fetchTopUsersFromDb';
33

44
export default async function handler(req, res) {
55
console.log('Update contributors API called');
6+
console.log('Auth header present:', !!req.headers.authorization);
7+
console.log('Expected token:', process.env.FCM_GITHUB_TOKEN?.substring(0, 5) + '...');
68

79
const authHeader = req.headers.authorization;
810
if (!authHeader) {
@@ -11,8 +13,11 @@ export default async function handler(req, res) {
1113
}
1214

1315
const token = authHeader.split(' ')[1];
16+
console.log('Received token:', token?.substring(0, 5) + '...');
17+
1418
if (!token || token !== process.env.FCM_GITHUB_TOKEN) {
1519
console.error('Invalid authorization token');
20+
console.log('Token match:', token === process.env.FCM_GITHUB_TOKEN);
1621
return res.status(401).json({ error: 'Unauthorized' });
1722
}
1823

@@ -35,5 +40,3 @@ export default async function handler(req, res) {
3540
return res.status(500).json({ error: 'Internal server error', details: error.message });
3641
}
3742
}
38-
39-

0 commit comments

Comments
 (0)