@@ -184,6 +184,12 @@ export async function queryPRInfo(prNumber: number) {
184
184
}
185
185
}
186
186
187
+ interface Refs {
188
+ readonly head : string ;
189
+ readonly master : "master" ;
190
+ readonly latestSuggestions : string ;
191
+ }
192
+
187
193
// The GQL response => Useful data for us
188
194
export async function deriveStateForPR (
189
195
prInfo : PR_repository_pullRequest ,
@@ -215,7 +221,7 @@ export async function deriveStateForPR(
215
221
master : "master" ,
216
222
latestSuggestions : max ( noNullish ( prInfo . reviews ?. nodes ) . filter ( review => ! authorNotBot ( review ) ) , ( a , b ) =>
217
223
Date . parse ( a . submittedAt ) - Date . parse ( b . submittedAt ) ) ?. commit ?. oid ,
218
- } ;
224
+ } as const ;
219
225
const pkgInfoEtc = await getPackageInfosEtc (
220
226
noNullish ( prInfo . files ?. nodes ) . map ( f => f . path ) . sort ( ) ,
221
227
refs , fetchFile , async name => await getDownloads ( name , lastPushDate ) ) ;
@@ -294,11 +300,11 @@ function getLastMaintainerBlessingDate(timelineItems: PR_repository_pullRequest_
294
300
}
295
301
296
302
async function getPackageInfosEtc (
297
- paths : string [ ] , refs : { [ ref : string ] : string } , fetchFile : typeof defaultFetchFile , getDownloads : typeof getMonthlyDownloadCount
303
+ paths : string [ ] , refs : Refs , fetchFile : typeof defaultFetchFile , getDownloads : typeof getMonthlyDownloadCount
298
304
) : Promise < { pkgInfo : PackageInfo [ ] , popularityLevel : PopularityLevel } | Error > {
299
305
const infos = new Map < string | null , FileInfo [ ] > ( ) ;
300
306
for ( const path of paths ) {
301
- const [ pkg , fileInfo ] = await categorizeFile ( path , async ( ref : string ) => fetchFile ( `${ refs [ ref ] } :${ path } ` ) ) ;
307
+ const [ pkg , fileInfo ] = await categorizeFile ( path , async ref => fetchFile ( `${ refs [ ref ] } :${ path } ` ) ) ;
302
308
if ( ! infos . has ( pkg ) ) infos . set ( pkg , [ ] ) ;
303
309
infos . get ( pkg ) ! . push ( fileInfo ) ;
304
310
}
@@ -333,7 +339,9 @@ async function getPackageInfosEtc(
333
339
return { pkgInfo : result , popularityLevel : downloadsToPopularityLevel ( maxDownloads ) } ;
334
340
}
335
341
336
- async function categorizeFile ( path : string , getContents : ( ref : string ) => Promise < string | undefined > ) : Promise < [ string | null , FileInfo ] > {
342
+ type GetContents = ( ref : keyof Refs ) => Promise < string | undefined > ;
343
+
344
+ async function categorizeFile ( path : string , getContents : GetContents ) : Promise < [ string | null , FileInfo ] > {
337
345
// https://regex101.com/r/eFvtrz/1
338
346
const match = / ^ t y p e s \/ ( .* ?) \/ .* ?[ ^ \/ ] (?: \. ( d \. t s | t s x ? | m d ) ) ? $ / . exec ( path ) ;
339
347
if ( ! match ) return [ null , { path, kind : "infrastructure" } ] ;
@@ -351,8 +359,8 @@ async function categorizeFile(path: string, getContents: (ref: string) => Promis
351
359
}
352
360
353
361
interface ConfigSuspicious {
354
- ( path : string , getContents : ( ref : string ) => Promise < string | undefined > ) : Promise < { suspect : string , sugestion ?: Suggestion } | undefined > ;
355
- [ basename : string ] : ( newText : string , getContents : ( ref : string ) => Promise < string | undefined > ) => Promise < { suspect : string , suggestion ?: Suggestion } | undefined > ;
362
+ ( path : string , getContents : GetContents ) : Promise < { suspect : string , sugestion ?: Suggestion } | undefined > ;
363
+ [ basename : string ] : ( newText : string , getContents : GetContents ) => Promise < { suspect : string , suggestion ?: Suggestion } | undefined > ;
356
364
}
357
365
const configSuspicious = < ConfigSuspicious > ( async ( path , getContents ) => {
358
366
const basename = path . replace ( / .* \/ / , "" ) ;
@@ -411,7 +419,7 @@ configSuspicious["tsconfig.json"] = makeChecker(
411
419
// to it, ignoring some keys. The ignored properties are in most cases checked
412
420
// elsewhere (dtslint), and in some cases they are irrelevant.
413
421
function makeChecker ( expectedForm : any , expectedFormUrl : string , options ?: { parse : ( text : string ) => unknown } | { ignore : ( data : any ) => void } ) {
414
- return async ( newText : string , getContents : ( ref : string ) => Promise < string | undefined > ) => {
422
+ return async ( newText : string , getContents : GetContents ) => {
415
423
let suggestion : any ;
416
424
if ( options && "parse" in options ) {
417
425
suggestion = options . parse ( newText ) ;
@@ -436,7 +444,7 @@ function makeChecker(expectedForm: any, expectedFormUrl: string, options?: { par
436
444
} ;
437
445
438
446
// Apply any preexisting diffs to towardsIt
439
- async function ignoreExistingDiffs ( ref : string ) {
447
+ async function ignoreExistingDiffs ( ref : keyof Refs ) {
440
448
const theExpectedForm = `[the expected form](${ expectedFormUrl } )` ;
441
449
const diffFromExpected = ( data : any ) => jsonDiff . compare ( towardsIt , data ) ;
442
450
const newDiff = diffFromExpected ( newData ) ;
0 commit comments