10
10
let path = require ( 'path' ) ;
11
11
12
12
const data = require ( './impl/data' ) ;
13
+ const db = require ( './impl/db' ) ;
13
14
const DbFile = require ( './impl/dbFile' ) ;
14
15
const fetchJson = require ( './impl/fetchJson' ) ;
15
16
const github = require ( './impl/github' ) ;
@@ -67,34 +68,21 @@ optional arguments:
67
68
}
68
69
69
70
if ( cli . input . length === 1 ) {
70
- await fetchUserDetailsAndContribs ( `${ cli . input [ 0 ] . toLowerCase ( ) } .json` ) ;
71
+ const userFilePath = path . join ( data . users , `${ cli . input [ 0 ] . toLowerCase ( ) } .json` ) ;
72
+ const user = new DbFile ( userFilePath ) ;
73
+ await fetchUserDetailsAndContribs ( user ) ; //LA_TODO to be tested
71
74
} else {
72
- for ( const file of fs . readdirSync ( data . users ) ) {
73
- if ( file . endsWith ( '.json' ) ) {
74
- await fetchUserDetailsAndContribs ( file ) ;
75
- }
75
+ for await ( const user of db . asyncNonRemovedUsers ( ) ) {
76
+ await fetchUserDetailsAndContribs ( user ) ; //LA_TODO to be tested
76
77
}
77
78
}
78
79
79
80
return ;
80
81
81
- async function fetchUserDetailsAndContribs ( userFileName ) {
82
- let spinner ;
83
-
84
- const userFilePath = path . join ( data . users , userFileName ) ;
85
- const userFile = new DbFile ( userFilePath ) ;
82
+ async function fetchUserDetailsAndContribs ( userFile ) {
86
83
if ( ! userFile . login ) {
87
84
throw `${ userFilePath } is malformed. Did you run ./addUser.js ?` ;
88
85
}
89
- if ( userFile . ghuser_deleted_because ) {
90
- console . log ( `${ userFile . login } has been deleted, skipping...` ) ;
91
- return ;
92
- }
93
- if ( userFile . removed_from_github ) {
94
- // For now ok, but maybe some day we'll have to deal with resurrected users.
95
- console . log ( `${ userFile . login } was removed from GitHub in the past, skipping...` ) ;
96
- return ;
97
- }
98
86
99
87
{
100
88
const now = new Date ;
@@ -117,7 +105,7 @@ optional arguments:
117
105
118
106
async function fetchDetails ( userFile ) {
119
107
const ghUserUrl = `https://api.github.com/users/${ userFile . login } ` ;
120
- spinner = ora ( `Fetching ${ ghUserUrl } ...` ) . start ( ) ;
108
+ const spinner = ora ( `Fetching ${ ghUserUrl } ...` ) . start ( ) ;
121
109
const ghDataJson = await github . fetchGHJson (
122
110
ghUserUrl , spinner , [ 304 , 404 ] ,
123
111
userFile . contribs && userFile . contribs . fetched_at && new Date ( userFile . contribs . fetched_at )
@@ -151,7 +139,7 @@ optional arguments:
151
139
152
140
async function fetchOrgs ( userFile ) {
153
141
const orgsUrl = userFile . organizations_url ;
154
- spinner = ora ( `Fetching ${ orgsUrl } ...` ) . start ( ) ;
142
+ const spinner = ora ( `Fetching ${ orgsUrl } ...` ) . start ( ) ;
155
143
const orgsDataJson = await github . fetchGHJson ( orgsUrl , spinner ) ;
156
144
spinner . succeed ( `Fetched ${ orgsUrl } ` ) ;
157
145
@@ -194,7 +182,7 @@ optional arguments:
194
182
// fetchUserContribs() won't find forks as they are not considered to be contributions. But
195
183
// the user might well have popular forks.
196
184
197
- spinner = ora ( `Fetching ${ userFile . login } 's popular forks...` ) . start ( ) ;
185
+ const spinner = ora ( `Fetching ${ userFile . login } 's popular forks...` ) . start ( ) ;
198
186
199
187
const perPage = 100 ;
200
188
for ( let page = 1 ; page <= 5 ; ++ page ) {
@@ -219,7 +207,7 @@ optional arguments:
219
207
220
208
async function fetchSettings ( userFile ) {
221
209
const url = `https://raw.githubusercontent.com/${ userFile . login } /ghuser.io.settings/master/ghuser.io.json` ;
222
- spinner = ora ( `Fetching ${ userFile . login } 's settings...` ) . start ( ) ;
210
+ const spinner = ora ( `Fetching ${ userFile . login } 's settings...` ) . start ( ) ;
223
211
224
212
const dataJson = await fetchJson ( url , spinner , [ 404 ] ) ;
225
213
if ( dataJson == 404 ) {
0 commit comments