@@ -181,6 +181,12 @@ export async function queryPRInfo(prNumber: number) {
181
181
} ) ;
182
182
}
183
183
184
+ interface Refs {
185
+ readonly head : string ;
186
+ readonly master : "master" ;
187
+ readonly latestSuggestions : string ;
188
+ }
189
+
184
190
// The GQL response => Useful data for us
185
191
export async function deriveStateForPR (
186
192
info : ApolloQueryResult < PRQueryResult > ,
@@ -218,7 +224,7 @@ export async function deriveStateForPR(
218
224
! latest ?. submittedAt || review . submittedAt && new Date ( review . submittedAt ) > new Date ( latest . submittedAt )
219
225
|| review . commit ?. oid === headCommit . oid )
220
226
? review : latest , null ) ?. commit ?. oid ,
221
- } ;
227
+ } as const ;
222
228
const pkgInfoEtc = await getPackageInfosEtc (
223
229
noNulls ( prInfo . files ?. nodes ) . map ( f => f . path ) . sort ( ) ,
224
230
refs , fetchFile , async name => await getDownloads ( name , lastPushDate ) ) ;
@@ -319,11 +325,11 @@ function getLastMaintainerBlessingDate(timelineItems: PR_repository_pullRequest_
319
325
}
320
326
321
327
async function getPackageInfosEtc (
322
- paths : string [ ] , refs : { [ ref : string ] : string } , fetchFile : typeof defaultFetchFile , getDownloads : typeof getMonthlyDownloadCount
328
+ paths : string [ ] , refs : Refs , fetchFile : typeof defaultFetchFile , getDownloads : typeof getMonthlyDownloadCount
323
329
) : Promise < { pkgInfo : PackageInfo [ ] , popularityLevel : PopularityLevel } | Error > {
324
330
const infos = new Map < string | null , FileInfo [ ] > ( ) ;
325
331
for ( const path of paths ) {
326
- const [ pkg , fileInfo ] = await categorizeFile ( path , async ( ref : string ) => fetchFile ( `${ refs [ ref ] } :${ path } ` ) ) ;
332
+ const [ pkg , fileInfo ] = await categorizeFile ( path , async ref => fetchFile ( `${ refs [ ref ] } :${ path } ` ) ) ;
327
333
if ( ! infos . has ( pkg ) ) infos . set ( pkg , [ ] ) ;
328
334
infos . get ( pkg ) ! . push ( fileInfo ) ;
329
335
}
@@ -354,7 +360,9 @@ async function getPackageInfosEtc(
354
360
return { pkgInfo : result , popularityLevel : downloadsToPopularityLevel ( maxDownloads ) } ;
355
361
}
356
362
357
- async function categorizeFile ( path : string , getContents : ( ref : string ) => Promise < string | undefined > ) : Promise < [ string | null , FileInfo ] > {
363
+ type GetContents = ( ref : keyof Refs ) => Promise < string | undefined > ;
364
+
365
+ async function categorizeFile ( path : string , getContents : GetContents ) : Promise < [ string | null , FileInfo ] > {
358
366
// https://regex101.com/r/eFvtrz/1
359
367
const match = / ^ t y p e s \/ ( .* ?) \/ .* ?[ ^ \/ ] (?: \. ( d \. t s | t s x ? | m d ) ) ? $ / . exec ( path ) ;
360
368
if ( ! match ) return [ null , { path, kind : "infrastructure" } ] ;
@@ -370,8 +378,8 @@ async function categorizeFile(path: string, getContents: (ref: string) => Promis
370
378
}
371
379
372
380
interface ConfigSuspicious {
373
- ( path : string , getContents : ( ref : string ) => Promise < string | undefined > ) : Promise < { suspect : string , sugestion ?: Suggestion } | undefined > ;
374
- [ basename : string ] : ( newText : string , getContents : ( ref : string ) => Promise < string | undefined > ) => Promise < { suspect : string , suggestion ?: Suggestion } | undefined > ;
381
+ ( path : string , getContents : GetContents ) : Promise < { suspect : string , sugestion ?: Suggestion } | undefined > ;
382
+ [ basename : string ] : ( newText : string , getContents : GetContents ) => Promise < { suspect : string , suggestion ?: Suggestion } | undefined > ;
375
383
} ;
376
384
const configSuspicious = < ConfigSuspicious > ( async ( path , getContents ) => {
377
385
const basename = path . replace ( / .* \/ / , "" ) ;
@@ -414,7 +422,7 @@ configSuspicious["tsconfig.json"] = makeJsonCheckerFromCore(
414
422
// to it, ignoring some keys (JSON Patch paths). The ignored properties are in most cases checked
415
423
// elsewhere (dtslint), and in some cases they are irrelevant.
416
424
function makeJsonCheckerFromCore ( requiredForm : any , ignoredKeys : string [ ] ) {
417
- return async ( newText : string , getContents : ( ref : string ) => Promise < string | undefined > ) => {
425
+ return async ( newText : string , getContents : GetContents ) => {
418
426
let suggestion : any ;
419
427
try { suggestion = JSON . parse ( newText ) ; } catch ( e ) { return { suspect : "couldn't parse json" } ; }
420
428
const newJson = jsonDiff . deepClone ( suggestion ) ;
@@ -435,7 +443,7 @@ function makeJsonCheckerFromCore(requiredForm: any, ignoredKeys: string[]) {
435
443
} ;
436
444
437
445
// Apply any preexisting diffs to towardsIt
438
- async function ignoreExistingDiffs ( ref : string ) {
446
+ async function ignoreExistingDiffs ( ref : keyof Refs ) {
439
447
const diffFromReq = ( json : any ) => jsonDiff . compare ( towardsIt , json ) ;
440
448
const newDiff = diffFromReq ( newJson ) ;
441
449
if ( newDiff . length === 0 ) return undefined ;
0 commit comments