@@ -56,14 +56,13 @@ type FileKind = "test" | "definition" | "markdown" | "package-meta" | "package-m
5656export type FileInfo = {
5757 path : string ,
5858 kind : FileKind ,
59- suspect ?: string , // reason for a file being "package-meta" rather than "package-meta-ok"
60- suggestion ?: Suggestion , // The differences from the expected form, as GitHub suggestions
59+ suspect ?: Explanation // reason for a file being "package-meta" rather than "package-meta-ok"
6160} ;
6261
63- export interface Suggestion {
64- readonly startLine : number ;
65- readonly endLine : number ;
66- readonly text : string ;
62+ export interface Explanation {
63+ readonly startLine ? : number ;
64+ readonly endLine ? : number ;
65+ readonly body : string ;
6766}
6867
6968export type ReviewInfo = {
@@ -186,7 +185,7 @@ export async function queryPRInfo(prNumber: number) {
186185interface Refs {
187186 readonly head : string ;
188187 readonly master : "master" ;
189- readonly latestSuggestions : string ;
188+ readonly latestExplanations : string ;
190189}
191190
192191// The GQL response => Useful data for us
@@ -218,8 +217,8 @@ export async function deriveStateForPR(
218217 const refs = {
219218 head : prInfo . headRefOid ,
220219 master : "master" ,
221- // Exclude existing suggestions from subsequent reviews
222- latestSuggestions : max ( noNullish ( prInfo . reviews ?. nodes ) . filter ( review => ! authorNotBot ( review ) ) , ( a , b ) =>
220+ // Exclude existing explanations from subsequent reviews
221+ latestExplanations : max ( noNullish ( prInfo . reviews ?. nodes ) . filter ( review => ! authorNotBot ( review ) ) , ( a , b ) =>
223222 Date . parse ( a . submittedAt ) - Date . parse ( b . submittedAt ) ) ?. commit ?. oid ,
224223 } as const ;
225224 const pkgInfoEtc = await getPackageInfosEtc (
@@ -353,19 +352,19 @@ async function categorizeFile(path: string, getContents: GetContents): Promise<[
353352 case "md" : return [ pkg , { path, kind : "markdown" } ] ;
354353 default : {
355354 const suspect = await configSuspicious ( path , getContents ) ;
356- return [ pkg , { path, kind : suspect ? "package-meta" : "package-meta-ok" , ... suspect } ] ;
355+ return [ pkg , { path, kind : suspect ? "package-meta" : "package-meta-ok" , suspect } ] ;
357356 }
358357 }
359358}
360359
361360interface ConfigSuspicious {
362- ( path : string , getContents : GetContents ) : Promise < { suspect : string , sugestion ?: Suggestion } | undefined > ;
363- [ basename : string ] : ( newText : string , getContents : GetContents ) => Promise < { suspect : string , suggestion ?: Suggestion } | undefined > ;
361+ ( path : string , getContents : GetContents ) : Promise < Explanation | undefined > ;
362+ [ basename : string ] : ( newText : string , getContents : GetContents ) => Promise < Explanation | undefined > ;
364363}
365364const configSuspicious = < ConfigSuspicious > ( async ( path , getContents ) => {
366365 const basename = path . replace ( / .* \/ / , "" ) ;
367366 const checker = configSuspicious [ basename ] ;
368- if ( ! checker ) return { suspect : `edited` } ;
367+ if ( ! checker ) return { body : `edited` } ;
369368 const newText = await getContents ( "head" ) ;
370369 // Removing tslint.json, tsconfig.json, package.json and
371370 // OTHER_FILES.txt is checked by the CI. Specifics are in my commit
@@ -424,7 +423,7 @@ function makeChecker(expectedForm: any, expectedFormUrl: string, options?: { par
424423 if ( options && "parse" in options ) {
425424 suggestion = options . parse ( newText ) ;
426425 } else {
427- try { suggestion = JSON . parse ( newText ) ; } catch ( e ) { if ( e instanceof SyntaxError ) return { suspect : `couldn't parse json: ${ e . message } ` } ; }
426+ try { suggestion = JSON . parse ( newText ) ; } catch ( e ) { if ( e instanceof SyntaxError ) return { body : `couldn't parse json: ${ e . message } ` } ; }
428427 }
429428 const newData = jsonDiff . deepClone ( suggestion ) ;
430429 if ( options && "ignore" in options ) options . ignore ( newData ) ;
@@ -433,15 +432,12 @@ function makeChecker(expectedForm: any, expectedFormUrl: string, options?: { par
433432 // suspect
434433 const vsMaster = await ignoreExistingDiffs ( "master" ) ;
435434 if ( ! vsMaster ) return undefined ;
436- if ( vsMaster . done ) return { suspect : vsMaster . suspect } ;
435+ if ( vsMaster . done ) return { body : vsMaster . suspect } ;
437436 // whereas getting closer relative to existing suggestions means
438437 // no new suggestions
439- if ( ! await ignoreExistingDiffs ( "latestSuggestions " ) ) return { suspect : vsMaster . suspect } ;
438+ if ( ! await ignoreExistingDiffs ( "latestExplanations " ) ) return { body : vsMaster . suspect } ;
440439 jsonDiff . applyPatch ( suggestion , jsonDiff . compare ( newData , towardsIt ) ) ;
441- return {
442- suspect : vsMaster . suspect ,
443- suggestion : makeSuggestion ( ) ,
444- } ;
440+ return makeSuggestion ( ) ;
445441
446442 // Apply any preexisting diffs to towardsIt
447443 async function ignoreExistingDiffs ( ref : keyof Refs ) {
@@ -491,7 +487,7 @@ function makeChecker(expectedForm: any, expectedFormUrl: string, options?: { par
491487 return {
492488 startLine,
493489 endLine,
494- text : suggestionLines . join ( "" ) ,
490+ body : vsMaster ! . suspect + "\n```suggestion\n" + suggestionLines . join ( "" ) + "```" ,
495491 } ;
496492 }
497493 } ;
0 commit comments