@@ -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 > ,
@@ -240,7 +246,7 @@ export async function deriveStateForPR(
240
246
review && ! authorNotBot ( review ) && (
241
247
! latest ?. submittedAt || review . submittedAt && new Date ( review . submittedAt ) > new Date ( latest . submittedAt ) )
242
248
? review : latest , null ) ?. commit ?. oid ,
243
- } ;
249
+ } as const ;
244
250
const pkgInfoEtc = await getPackageInfosEtc (
245
251
noNullish ( prInfo . files ?. nodes ) . map ( f => f . path ) . sort ( ) ,
246
252
refs , fetchFile , async name => await getDownloads ( name , lastPushDate ) ) ;
@@ -335,11 +341,11 @@ function getLastMaintainerBlessingDate(timelineItems: PR_repository_pullRequest_
335
341
}
336
342
337
343
async function getPackageInfosEtc (
338
- paths : string [ ] , refs : { [ ref : string ] : string } , fetchFile : typeof defaultFetchFile , getDownloads : typeof getMonthlyDownloadCount
344
+ paths : string [ ] , refs : Refs , fetchFile : typeof defaultFetchFile , getDownloads : typeof getMonthlyDownloadCount
339
345
) : Promise < { pkgInfo : PackageInfo [ ] , popularityLevel : PopularityLevel } | Error > {
340
346
const infos = new Map < string | null , FileInfo [ ] > ( ) ;
341
347
for ( const path of paths ) {
342
- const [ pkg , fileInfo ] = await categorizeFile ( path , async ( ref : string ) => fetchFile ( `${ refs [ ref ] } :${ path } ` ) ) ;
348
+ const [ pkg , fileInfo ] = await categorizeFile ( path , async ref => fetchFile ( `${ refs [ ref ] } :${ path } ` ) ) ;
343
349
if ( ! infos . has ( pkg ) ) infos . set ( pkg , [ ] ) ;
344
350
infos . get ( pkg ) ! . push ( fileInfo ) ;
345
351
}
@@ -374,7 +380,9 @@ async function getPackageInfosEtc(
374
380
return { pkgInfo : result , popularityLevel : downloadsToPopularityLevel ( maxDownloads ) } ;
375
381
}
376
382
377
- async function categorizeFile ( path : string , getContents : ( ref : string ) => Promise < string | undefined > ) : Promise < [ string | null , FileInfo ] > {
383
+ type GetContents = ( ref : keyof Refs ) => Promise < string | undefined > ;
384
+
385
+ async function categorizeFile ( path : string , getContents : GetContents ) : Promise < [ string | null , FileInfo ] > {
378
386
// https://regex101.com/r/eFvtrz/1
379
387
const match = / ^ t y p e s \/ ( .* ?) \/ .* ?[ ^ \/ ] (?: \. ( d \. t s | t s x ? | m d ) ) ? $ / . exec ( path ) ;
380
388
if ( ! match ) return [ null , { path, kind : "infrastructure" } ] ;
@@ -391,8 +399,8 @@ async function categorizeFile(path: string, getContents: (ref: string) => Promis
391
399
}
392
400
393
401
interface ConfigSuspicious {
394
- ( path : string , getContents : ( ref : string ) => Promise < string | undefined > ) : Promise < { suspect : string , sugestion ?: Suggestion } | undefined > ;
395
- [ basename : string ] : ( newText : string , getContents : ( ref : string ) => Promise < string | undefined > ) => Promise < { suspect : string , suggestion ?: Suggestion } | undefined > ;
402
+ ( path : string , getContents : GetContents ) : Promise < { suspect : string , sugestion ?: Suggestion } | undefined > ;
403
+ [ basename : string ] : ( newText : string , getContents : GetContents ) => Promise < { suspect : string , suggestion ?: Suggestion } | undefined > ;
396
404
}
397
405
const configSuspicious = < ConfigSuspicious > ( async ( path , getContents ) => {
398
406
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 ) { return { suspect : "couldn't parse json" } ; }
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 = requiredFormUrl
462
470
? `[the required form](${ requiredFormUrl } )`
463
471
: "the required form" ;
0 commit comments