@@ -204,6 +204,12 @@ export async function queryPRInfo(prNumber: number) {
204
204
}
205
205
}
206
206
207
+ interface Refs {
208
+ readonly head : string ;
209
+ readonly master : "master" ;
210
+ readonly latestSuggestions : string ;
211
+ }
212
+
207
213
// The GQL response => Useful data for us
208
214
export async function deriveStateForPR (
209
215
info : ApolloQueryResult < PRQueryResult > ,
@@ -238,7 +244,7 @@ export async function deriveStateForPR(
238
244
master : "master" ,
239
245
latestSuggestions : max ( noNullish ( prInfo . reviews ?. nodes ) . filter ( review => ! authorNotBot ( review ) ) , ( a , b ) =>
240
246
Date . parse ( a . submittedAt ) - Date . parse ( b . submittedAt ) ) ?. commit ?. oid ,
241
- } ;
247
+ } as const ;
242
248
const pkgInfoEtc = await getPackageInfosEtc (
243
249
noNullish ( prInfo . files ?. nodes ) . map ( f => f . path ) . sort ( ) ,
244
250
refs , fetchFile , async name => await getDownloads ( name , lastPushDate ) ) ;
@@ -333,11 +339,11 @@ function getLastMaintainerBlessingDate(timelineItems: PR_repository_pullRequest_
333
339
}
334
340
335
341
async function getPackageInfosEtc (
336
- paths : string [ ] , refs : { [ ref : string ] : string } , fetchFile : typeof defaultFetchFile , getDownloads : typeof getMonthlyDownloadCount
342
+ paths : string [ ] , refs : Refs , fetchFile : typeof defaultFetchFile , getDownloads : typeof getMonthlyDownloadCount
337
343
) : Promise < { pkgInfo : PackageInfo [ ] , popularityLevel : PopularityLevel } | Error > {
338
344
const infos = new Map < string | null , FileInfo [ ] > ( ) ;
339
345
for ( const path of paths ) {
340
- const [ pkg , fileInfo ] = await categorizeFile ( path , async ( ref : string ) => fetchFile ( `${ refs [ ref ] } :${ path } ` ) ) ;
346
+ const [ pkg , fileInfo ] = await categorizeFile ( path , async ref => fetchFile ( `${ refs [ ref ] } :${ path } ` ) ) ;
341
347
if ( ! infos . has ( pkg ) ) infos . set ( pkg , [ ] ) ;
342
348
infos . get ( pkg ) ! . push ( fileInfo ) ;
343
349
}
@@ -372,7 +378,9 @@ async function getPackageInfosEtc(
372
378
return { pkgInfo : result , popularityLevel : downloadsToPopularityLevel ( maxDownloads ) } ;
373
379
}
374
380
375
- async function categorizeFile ( path : string , getContents : ( ref : string ) => Promise < string | undefined > ) : Promise < [ string | null , FileInfo ] > {
381
+ type GetContents = ( ref : keyof Refs ) => Promise < string | undefined > ;
382
+
383
+ async function categorizeFile ( path : string , getContents : GetContents ) : Promise < [ string | null , FileInfo ] > {
376
384
// https://regex101.com/r/eFvtrz/1
377
385
const match = / ^ t y p e s \/ ( .* ?) \/ .* ?[ ^ \/ ] (?: \. ( d \. t s | t s x ? | m d ) ) ? $ / . exec ( path ) ;
378
386
if ( ! match ) return [ null , { path, kind : "infrastructure" } ] ;
@@ -389,8 +397,8 @@ async function categorizeFile(path: string, getContents: (ref: string) => Promis
389
397
}
390
398
391
399
interface ConfigSuspicious {
392
- ( path : string , getContents : ( ref : string ) => Promise < string | undefined > ) : Promise < { suspect : string , sugestion ?: Suggestion } | undefined > ;
393
- [ basename : string ] : ( newText : string , getContents : ( ref : string ) => Promise < string | undefined > ) => Promise < { suspect : string , suggestion ?: Suggestion } | undefined > ;
400
+ ( path : string , getContents : GetContents ) : Promise < { suspect : string , sugestion ?: Suggestion } | undefined > ;
401
+ [ basename : string ] : ( newText : string , getContents : GetContents ) => Promise < { suspect : string , suggestion ?: Suggestion } | undefined > ;
394
402
}
395
403
const configSuspicious = < ConfigSuspicious > ( async ( path , getContents ) => {
396
404
const basename = path . replace ( / .* \/ / , "" ) ;
@@ -436,7 +444,7 @@ configSuspicious["tsconfig.json"] = makeJsonCheckerFromCore(
436
444
// to it, ignoring some keys (JSON Patch paths). The ignored properties are in most cases checked
437
445
// elsewhere (dtslint), and in some cases they are irrelevant.
438
446
function makeJsonCheckerFromCore ( requiredForm : any , ignoredKeys : string [ ] , requiredFormUrl : string ) {
439
- return async ( newText : string , getContents : ( ref : string ) => Promise < string | undefined > ) => {
447
+ return async ( newText : string , getContents : GetContents ) => {
440
448
let suggestion : any ;
441
449
try { suggestion = JSON . parse ( newText ) ; } catch ( e ) { if ( e instanceof SyntaxError ) return { suspect : `couldn't parse json: ${ e . message } ` } ; }
442
450
const newJson = jsonDiff . deepClone ( suggestion ) ;
@@ -457,7 +465,7 @@ function makeJsonCheckerFromCore(requiredForm: any, ignoredKeys: string[], requi
457
465
} ;
458
466
459
467
// Apply any preexisting diffs to towardsIt
460
- async function ignoreExistingDiffs ( ref : string ) {
468
+ async function ignoreExistingDiffs ( ref : keyof Refs ) {
461
469
const theRequiredForm = `[the required form](${ requiredFormUrl } )` ;
462
470
const diffFromReq = ( json : any ) => jsonDiff . compare ( towardsIt , json ) ;
463
471
const newDiff = diffFromReq ( newJson ) ;
0 commit comments