@@ -197,6 +197,12 @@ export async function queryPRInfo(prNumber: number) {
197
197
}
198
198
}
199
199
200
+ interface Refs {
201
+ readonly head : string ;
202
+ readonly master : "master" ;
203
+ readonly latestSuggestions : string ;
204
+ }
205
+
200
206
// The GQL response => Useful data for us
201
207
export async function deriveStateForPR (
202
208
info : ApolloQueryResult < PRQueryResult > ,
@@ -233,7 +239,7 @@ export async function deriveStateForPR(
233
239
review && ! authorNotBot ( review ) && (
234
240
! latest ?. submittedAt || review . submittedAt && new Date ( review . submittedAt ) > new Date ( latest . submittedAt ) )
235
241
? review : latest , null ) ?. commit ?. oid ,
236
- } ;
242
+ } as const ;
237
243
const pkgInfoEtc = await getPackageInfosEtc (
238
244
noNullish ( prInfo . files ?. nodes ) . map ( f => f . path ) . sort ( ) ,
239
245
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
}
@@ -369,7 +375,9 @@ async function getPackageInfosEtc(
369
375
return { pkgInfo : result , popularityLevel : downloadsToPopularityLevel ( maxDownloads ) } ;
370
376
}
371
377
372
- async function categorizeFile ( path : string , getContents : ( ref : string ) => Promise < string | undefined > ) : Promise < [ string | null , FileInfo ] > {
378
+ type GetContents = ( ref : keyof Refs ) => Promise < string | undefined > ;
379
+
380
+ async function categorizeFile ( path : string , getContents : GetContents ) : Promise < [ string | null , FileInfo ] > {
373
381
// https://regex101.com/r/eFvtrz/1
374
382
const match = / ^ t y p e s \/ ( .* ?) \/ .* ?[ ^ \/ ] (?: \. ( d \. t s | t s x ? | m d ) ) ? $ / . exec ( path ) ;
375
383
if ( ! match ) return [ null , { path, kind : "infrastructure" } ] ;
@@ -385,8 +393,8 @@ async function categorizeFile(path: string, getContents: (ref: string) => Promis
385
393
}
386
394
387
395
interface ConfigSuspicious {
388
- ( path : string , getContents : ( ref : string ) => Promise < string | undefined > ) : Promise < { suspect : string , sugestion ?: Suggestion } | undefined > ;
389
- [ basename : string ] : ( newText : string , getContents : ( ref : string ) => Promise < string | undefined > ) => Promise < { suspect : string , suggestion ?: Suggestion } | undefined > ;
396
+ ( path : string , getContents : GetContents ) : Promise < { suspect : string , sugestion ?: Suggestion } | undefined > ;
397
+ [ basename : string ] : ( newText : string , getContents : GetContents ) => Promise < { suspect : string , suggestion ?: Suggestion } | undefined > ;
390
398
} ;
391
399
const configSuspicious = < ConfigSuspicious > ( async ( path , getContents ) => {
392
400
const basename = path . replace ( / .* \/ / , "" ) ;
@@ -429,7 +437,7 @@ configSuspicious["tsconfig.json"] = makeJsonCheckerFromCore(
429
437
// to it, ignoring some keys (JSON Patch paths). The ignored properties are in most cases checked
430
438
// elsewhere (dtslint), and in some cases they are irrelevant.
431
439
function makeJsonCheckerFromCore ( requiredForm : any , ignoredKeys : string [ ] ) {
432
- return async ( newText : string , getContents : ( ref : string ) => Promise < string | undefined > ) => {
440
+ return async ( newText : string , getContents : GetContents ) => {
433
441
let suggestion : any ;
434
442
try { suggestion = JSON . parse ( newText ) ; } catch ( e ) { return { suspect : "couldn't parse json" } ; }
435
443
const newJson = jsonDiff . deepClone ( suggestion ) ;
@@ -450,7 +458,7 @@ function makeJsonCheckerFromCore(requiredForm: any, ignoredKeys: string[]) {
450
458
} ;
451
459
452
460
// Apply any preexisting diffs to towardsIt
453
- async function ignoreExistingDiffs ( ref : string ) {
461
+ async function ignoreExistingDiffs ( ref : keyof Refs ) {
454
462
const diffFromReq = ( json : any ) => jsonDiff . compare ( towardsIt , json ) ;
455
463
const newDiff = diffFromReq ( newJson ) ;
456
464
if ( newDiff . length === 0 ) return undefined ;
0 commit comments