@@ -159,37 +159,57 @@ export function getReleases(): IDictionary {
159
159
return canals
160
160
}
161
161
162
- export async function getContributors ( ) {
162
+ export interface Contributor {
163
+ login : string ,
164
+ avatar_url : string ,
165
+ url : string ,
166
+ id : number
167
+ }
163
168
164
- interface EmailAvatar {
165
- [ index : string ] : string ;
166
- }
169
+ export async function getContributors ( ) : Promise < Contributor [ ] | undefined > {
167
170
168
- const contributorsFile = 'datapacks/contributors.json'
169
- let contributors = { } as EmailAvatar
170
171
try {
171
- let contributorsRaw = fs . readFileSync ( path . resolve ( contributorsFile ) , { encoding : 'utf8' } )
172
- contributors = JSON . parse ( contributorsRaw )
173
- } catch ( e ) {
174
- try {
175
- let avatars = { } as EmailAvatar
176
- let emails : string [ ] | undefined = process . env . CONTRIBUTORS ?. split ( ';' )
177
- if ( emails ) {
178
- for ( const email of emails ) {
179
- await axios . get ( `https://gitlab.com/api/v4/avatar?email=${ email } &size=64` )
180
- . then ( response => {
181
- avatars [ email ] = response . data . avatar_url ;
182
- } )
183
- }
184
- fs . writeFileSync ( path . resolve ( contributorsFile ) , JSON . stringify ( avatars ) ) ;
185
- contributors = avatars ;
186
- }
187
-
188
- } catch ( error ) {
189
- contributors = { }
190
- }
172
+ let contributors : Contributor [ ] = [ ]
173
+ console . log ( "query" )
174
+ const req1 = axios . get < Contributor [ ] > ( `https://api.github.com/repos/Gunivers/Glib/contributors` )
175
+ const req2 = axios . get < Contributor [ ] > ( `https://api.github.com/repos/Gunivers/Glib-Manager/contributors` )
176
+ await axios . all ( [ req1 , req2 ] )
177
+ . then ( value => contributors = [ ...value [ 0 ] . data , ...value [ 1 ] . data ] )
178
+ return Array . from ( contributors . reduce ( ( entryMap , e : Contributor ) =>
179
+ entryMap . set ( e . id , [ ...entryMap . get ( e . id ) || [ ] , e ] ) ,
180
+ new Map < number , Contributor [ ] > ( ) )
181
+ . values ( ) ) . flatMap ( contributors => contributors [ 0 ] )
182
+ . map ( contributor => { return { url : `https://github.com/${ contributor . login } ` , login : contributor . login , avatar_url : contributor . avatar_url , id : contributor . id } } )
183
+ // return contributors
184
+ } catch {
185
+ return undefined
191
186
}
192
- return contributors
187
+
188
+ // const contributorsFile = 'datapacks/contributors.json'
189
+ // //let contributors = {} as Contributor
190
+ // try {
191
+ // let contributorsRaw = fs.readFileSync(path.resolve(contributorsFile), { encoding: 'utf8' })
192
+ // contributors = JSON.parse(contributorsRaw)
193
+ // } catch (e) {
194
+ // try {
195
+ // let avatars = {} as Contributor
196
+ // let emails: string[] | undefined = process.env.CONTRIBUTORS?.split(';')
197
+ // if (emails) {
198
+ // for (const email of emails) {
199
+ // await axios.get(`https://gitlab.com/api/v4/avatar?email=${email}&size=64`)
200
+ // .then(response => {
201
+ // avatars[email] = response.data.avatar_url;
202
+ // })
203
+ // }
204
+ // fs.writeFileSync(path.resolve(contributorsFile), JSON.stringify(avatars));
205
+ // contributors = avatars;
206
+ // }
207
+ //
208
+ // } catch (error) {
209
+ // contributors = {}
210
+ // }
211
+ // }
212
+ // return contributors
193
213
}
194
214
195
215
export async function getGlib ( ) {
0 commit comments