1
1
import fs from 'fs' ;
2
2
import path from 'path' ;
3
3
import { fileURLToPath } from 'url' ;
4
- import fetch from 'node-fetch' ;
4
+ import { fetchGitHubRepoData } from './merge.js' ; // Import the function to fetch GitHub data
5
5
6
6
// Get directory name in ES modules
7
7
const __filename = fileURLToPath ( import . meta. url ) ;
@@ -11,61 +11,6 @@ const __dirname = path.dirname(__filename);
11
11
const rootDir = path . resolve ( __dirname , '..' ) ;
12
12
const dataDir = path . join ( rootDir , 'data' ) ;
13
13
14
- // Helper function to extract GitHub info from URL
15
- function extractGitHubInfo ( url ) {
16
- if ( ! url || ! url . includes ( 'github.com' ) ) return null ;
17
-
18
- try {
19
- const urlObj = new URL ( url ) ;
20
- if ( urlObj . hostname !== 'github.com' ) return null ;
21
-
22
- const path = urlObj . pathname . replace ( / ^ \/ | \/ $ / g, '' ) ;
23
- const [ owner , repo ] = path . split ( '/' ) ;
24
-
25
- if ( ! owner || ! repo ) return null ;
26
-
27
- return { owner, repo } ;
28
- } catch ( e ) {
29
- return null ;
30
- }
31
- }
32
-
33
- // Function to fetch GitHub repository data
34
- async function fetchGitHubRepoData ( url ) {
35
- try {
36
- const repoInfo = extractGitHubInfo ( url ) ;
37
- if ( ! repoInfo ) return null ;
38
-
39
- const { owner, repo } = repoInfo ;
40
-
41
- // Add a small random delay to avoid hitting rate limits
42
- await new Promise ( resolve => setTimeout ( resolve , 500 + Math . random ( ) * 500 ) ) ;
43
-
44
- console . log ( `Fetching GitHub data for ${ owner } /${ repo } ...` ) ;
45
- const response = await fetch ( `https://api.github.com/repos/${ owner } /${ repo } ` ) ;
46
-
47
- if ( ! response . ok ) {
48
- if ( response . status === 403 ) {
49
- console . warn ( 'GitHub API rate limit exceeded' ) ;
50
- }
51
- console . error ( `Error fetching data for ${ owner } /${ repo } : HTTP ${ response . status } ` ) ;
52
- return null ;
53
- }
54
-
55
- const data = await response . json ( ) ;
56
-
57
- return {
58
- authorName : data . owner ?. login || owner ,
59
- authorLink : data . owner ?. html_url || `https://github.com/${ owner } ` ,
60
- stars : data . stargazers_count || 0 ,
61
- forks : data . forks_count || 0
62
- } ;
63
- } catch ( error ) {
64
- console . error ( 'Error fetching GitHub repo data:' , error ) ;
65
- return null ;
66
- }
67
- }
68
-
69
14
// Get all JSON files in the data directory (excluding index.json and _template.json)
70
15
const jsonFiles = fs . readdirSync ( dataDir )
71
16
. filter ( file => file . endsWith ( '.json' ) && file !== 'index.json' && file !== '_template.json' ) ;
0 commit comments