@@ -198,6 +198,12 @@ export async function queryPRInfo(prNumber: number) {
198198 }
199199}
200200
201+ interface Refs {
202+ readonly head : string ;
203+ readonly master : "master" ;
204+ readonly latestSuggestions : string ;
205+ }
206+
201207// The GQL response => Useful data for us
202208export async function deriveStateForPR (
203209 info : ApolloQueryResult < PRQueryResult > ,
@@ -234,7 +240,7 @@ export async function deriveStateForPR(
234240 review && ! authorNotBot ( review ) && (
235241 ! latest ?. submittedAt || review . submittedAt && new Date ( review . submittedAt ) > new Date ( latest . submittedAt ) )
236242 ? review : latest , null ) ?. commit ?. oid ,
237- } ;
243+ } as const ;
238244 const pkgInfoEtc = await getPackageInfosEtc (
239245 noNullish ( prInfo . files ?. nodes ) . map ( f => f . path ) . sort ( ) ,
240246 refs , fetchFile , async name => await getDownloads ( name , lastPushDate ) ) ;
@@ -334,11 +340,11 @@ function getLastMaintainerBlessingDate(timelineItems: PR_repository_pullRequest_
334340}
335341
336342async function getPackageInfosEtc (
337- paths : string [ ] , refs : { [ ref : string ] : string } , fetchFile : typeof defaultFetchFile , getDownloads : typeof getMonthlyDownloadCount
343+ paths : string [ ] , refs : Refs , fetchFile : typeof defaultFetchFile , getDownloads : typeof getMonthlyDownloadCount
338344) : Promise < { pkgInfo : PackageInfo [ ] , popularityLevel : PopularityLevel } | Error > {
339345 const infos = new Map < string | null , FileInfo [ ] > ( ) ;
340346 for ( const path of paths ) {
341- const [ pkg , fileInfo ] = await categorizeFile ( path , async ( ref : string ) => fetchFile ( `${ refs [ ref ] } :${ path } ` ) ) ;
347+ const [ pkg , fileInfo ] = await categorizeFile ( path , async ref => fetchFile ( `${ refs [ ref ] } :${ path } ` ) ) ;
342348 if ( ! infos . has ( pkg ) ) infos . set ( pkg , [ ] ) ;
343349 infos . get ( pkg ) ! . push ( fileInfo ) ;
344350 }
@@ -373,7 +379,9 @@ async function getPackageInfosEtc(
373379 return { pkgInfo : result , popularityLevel : downloadsToPopularityLevel ( maxDownloads ) } ;
374380}
375381
376- async function categorizeFile ( path : string , getContents : ( ref : string ) => Promise < string | undefined > ) : Promise < [ string | null , FileInfo ] > {
382+ type GetContents = ( ref : keyof Refs ) => Promise < string | undefined > ;
383+
384+ async function categorizeFile ( path : string , getContents : GetContents ) : Promise < [ string | null , FileInfo ] > {
377385 // https://regex101.com/r/eFvtrz/1
378386 const match = / ^ t y p e s \/ ( .* ?) \/ .* ?[ ^ \/ ] (?: \. ( d \. t s | t s x ? | m d ) ) ? $ / . exec ( path ) ;
379387 if ( ! match ) return [ null , { path, kind : "infrastructure" } ] ;
@@ -389,8 +397,8 @@ async function categorizeFile(path: string, getContents: (ref: string) => Promis
389397}
390398
391399interface 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 > ;
394402}
395403const configSuspicious = < ConfigSuspicious > ( async ( path , getContents ) => {
396404 const basename = path . replace ( / .* \/ / , "" ) ;
@@ -434,7 +442,7 @@ configSuspicious["tsconfig.json"] = makeJsonCheckerFromCore(
434442// to it, ignoring some keys (JSON Patch paths). The ignored properties are in most cases checked
435443// elsewhere (dtslint), and in some cases they are irrelevant.
436444function makeJsonCheckerFromCore ( requiredForm : any , ignoredKeys : string [ ] , requiredFormUrl ?: string ) {
437- return async ( newText : string , getContents : ( ref : string ) => Promise < string | undefined > ) => {
445+ return async ( newText : string , getContents : GetContents ) => {
438446 let suggestion : any ;
439447 try { suggestion = JSON . parse ( newText ) ; } catch ( e ) { return { suspect : "couldn't parse json" } ; }
440448 const newJson = jsonDiff . deepClone ( suggestion ) ;
@@ -455,7 +463,7 @@ function makeJsonCheckerFromCore(requiredForm: any, ignoredKeys: string[], requi
455463 } ;
456464
457465 // Apply any preexisting diffs to towardsIt
458- async function ignoreExistingDiffs ( ref : string ) {
466+ async function ignoreExistingDiffs ( ref : keyof Refs ) {
459467 const theRequiredForm = requiredFormUrl
460468 ? `[the required form](${ requiredFormUrl } )`
461469 : "the required form" ;
0 commit comments