@@ -2,22 +2,36 @@ import { fetchTopThreeUsersByPullRequests } from '../../utils/fetchTopThreeUsers
22import { storeTopThreeUsersInDb } from '../../utils/fetchTopUsersFromDb' ;
33
44export 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