@@ -11,15 +11,15 @@ import fs from 'fs';
1111import path from 'path' ;
1212import { fileURLToPath } from 'url' ;
1313import fetch from 'node-fetch' ;
14- import dotenv from 'dotenv' ;
14+ import * as dotenv from 'dotenv' ;
1515import config from '../src/config.js' ;
1616
1717// Load environment variables
18- dotenv . config ( ) ;
19-
20- // Constants
2118const __filename = fileURLToPath ( import . meta. url ) ;
2219const __dirname = path . dirname ( __filename ) ;
20+ dotenv . config ( { path : path . resolve ( __dirname , '../.env' ) } ) ;
21+
22+ // Constants
2323const OUTPUT_PATH = path . join ( __dirname , '../public/projects.json' ) ;
2424
2525// GitHub API URLs
@@ -78,20 +78,23 @@ async function getTopRepositories(org, topic, limit = 3) {
7878 try {
7979 while ( true ) {
8080 const params = new URLSearchParams ( {
81- 'q' : `org:${ org } topic:${ topic } ` ,
81+ 'q' : `org:${ org } topic:"${ topic } "` ,
82+ 'sort' : 'stars' ,
83+ 'order' : 'desc' ,
8284 'per_page' : '100' ,
8385 'page' : page . toString ( )
8486 } ) ;
8587
8688 const headers = {
8789 'Accept' : 'application/vnd.github.v3+json' ,
88- 'Authorization' : `token ${ GITHUB_TOKEN } `
90+ 'Authorization' : `Bearer ${ GITHUB_TOKEN } `
8991 } ;
9092
9193 const response = await fetch ( `${ GITHUB_API_SEARCH_URL } ?${ params } ` , { headers } ) ;
9294
9395 if ( ! response . ok ) {
94- throw new Error ( `HTTP error! Status: ${ response . status } ` ) ;
96+ const errorData = await response . json ( ) ;
97+ throw new Error ( `HTTP error! Status: ${ response . status } , Message: ${ JSON . stringify ( errorData ) } ` ) ;
9598 }
9699
97100 const data = await response . json ( ) ;
0 commit comments