Skip to content

Commit a65bcbd

Browse files
committed
api: add more logging
1 parent 92f30d9 commit a65bcbd

2 files changed

Lines changed: 25 additions & 5 deletions

File tree

.github/workflows/update-contributors.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,21 @@ name: Update Top Contributors
33
on:
44
schedule:
55
- cron: '5 0 * * *' # Runs at 00:05 UTC every day
6-
workflow_dispatch: # Allows manual trigger
6+
workflow_dispatch:
77

88
jobs:
99
update-contributors:
1010
runs-on: ubuntu-latest
11-
11+
1212
steps:
1313
- name: Update Contributors
1414
run: |
15-
curl -X POST ${{ secrets.VERCEL_DEPLOYMENT_URL }}/api/updateTopContributors \
15+
response=$(curl -X POST ${{ secrets.VERCEL_DEPLOYMENT_URL }}/api/updateTopContributors \
1616
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
17-
-H "Content-Type: application/json"
17+
-H "Content-Type: application/json" \
18+
-w "\n%{http_code}")
19+
echo "Response: $response"
20+
if [[ $(echo "$response" | tail -n1) != 2* ]]; then
21+
echo "Error: API call failed"
22+
exit 1
23+
fi

pages/api/updateTopContributors.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,36 @@ import { fetchTopThreeUsersByPullRequests } from '../../utils/fetchTopThreeUsers
22
import { storeTopThreeUsersInDb } from '../../utils/fetchTopUsersFromDb';
33

44
export default async function handler(req, res) {
5+
console.log('Update contributors API called');
6+
57
const authHeader = req.headers.authorization;
8+
if (!authHeader) {
9+
console.error('No authorization header provided');
10+
return res.status(401).json({ error: 'No authorization header' });
11+
}
12+
613
if (authHeader !== `Bearer ${process.env.GITHUB_TOKEN}`) {
14+
console.error('Invalid authorization token');
715
return res.status(401).json({ error: 'Unauthorized' });
816
}
917

1018
try {
19+
console.log('Fetching top three users...');
1120
const data = await fetchTopThreeUsersByPullRequests('fork-commit-merge/fork-commit-merge');
21+
console.log('Fetched data:', data);
1222

1323
if (data && data.length > 0) {
24+
console.log('Storing data in DB...');
1425
await storeTopThreeUsersInDb(data);
26+
console.log('Data stored successfully');
1527
return res.status(200).json({ success: true, message: 'Contributors updated successfully' });
1628
}
1729

30+
console.error('No data retrieved from GitHub');
1831
return res.status(400).json({ error: 'No data retrieved' });
1932
} catch (error) {
2033
console.error('Update contributors error:', error);
21-
return res.status(500).json({ error: 'Internal server error' });
34+
return res.status(500).json({ error: 'Internal server error', details: error.message });
2235
}
2336
}
37+

0 commit comments

Comments
 (0)