@@ -55,14 +55,13 @@ type FileKind = "test" | "definition" | "markdown" | "package-meta" | "package-m
5555export type FileInfo = {
5656 path : string ,
5757 kind : FileKind ,
58- suspect ?: string , // reason for a file being "package-meta" rather than "package-meta-ok"
59- suggestion ?: Suggestion , // The differences from the expected form, as GitHub suggestions
58+ suspect ?: Explanation // reason for a file being "package-meta" rather than "package-meta-ok"
6059} ;
6160
62- export interface Suggestion {
63- readonly startLine : number ;
64- readonly endLine : number ;
65- readonly text : string ;
61+ export interface Explanation {
62+ readonly startLine ? : number ;
63+ readonly endLine ? : number ;
64+ readonly body : string ;
6665}
6766
6867export type ReviewInfo = {
@@ -185,7 +184,7 @@ export async function queryPRInfo(prNumber: number) {
185184interface Refs {
186185 readonly head : string ;
187186 readonly master : "master" ;
188- readonly latestSuggestions : string ;
187+ readonly latestExplanations : string ;
189188}
190189
191190// The GQL response => Useful data for us
@@ -217,8 +216,8 @@ export async function deriveStateForPR(
217216 const refs = {
218217 head : prInfo . headRefOid ,
219218 master : "master" ,
220- // Exclude existing suggestions from subsequent reviews
221- latestSuggestions : max ( noNullish ( prInfo . reviews ?. nodes ) . filter ( review => ! authorNotBot ( review ) ) , ( a , b ) =>
219+ // Exclude existing explanations from subsequent reviews
220+ latestExplanations : max ( noNullish ( prInfo . reviews ?. nodes ) . filter ( review => ! authorNotBot ( review ) ) , ( a , b ) =>
222221 Date . parse ( a . submittedAt ) - Date . parse ( b . submittedAt ) ) ?. commit ?. oid ,
223222 } as const ;
224223 const pkgInfoEtc = await getPackageInfosEtc (
@@ -352,19 +351,19 @@ async function categorizeFile(path: string, getContents: GetContents): Promise<[
352351 case "md" : return [ pkg , { path, kind : "markdown" } ] ;
353352 default : {
354353 const suspect = await configSuspicious ( path , getContents ) ;
355- return [ pkg , { path, kind : suspect ? "package-meta" : "package-meta-ok" , ... suspect } ] ;
354+ return [ pkg , { path, kind : suspect ? "package-meta" : "package-meta-ok" , suspect } ] ;
356355 }
357356 }
358357}
359358
360359interface ConfigSuspicious {
361- ( path : string , getContents : GetContents ) : Promise < { suspect : string , sugestion ?: Suggestion } | undefined > ;
362- [ basename : string ] : ( newText : string , getContents : GetContents ) => Promise < { suspect : string , suggestion ?: Suggestion } | undefined > ;
360+ ( path : string , getContents : GetContents ) : Promise < Explanation | undefined > ;
361+ [ basename : string ] : ( newText : string , getContents : GetContents ) => Promise < Explanation | undefined > ;
363362}
364363const configSuspicious = < ConfigSuspicious > ( async ( path , getContents ) => {
365364 const basename = path . replace ( / .* \/ / , "" ) ;
366365 const checker = configSuspicious [ basename ] ;
367- if ( ! checker ) return { suspect : `edited` } ;
366+ if ( ! checker ) return { body : `edited` } ;
368367 const newText = await getContents ( "head" ) ;
369368 // Removing tslint.json, tsconfig.json, package.json and
370369 // OTHER_FILES.txt is checked by the CI. Specifics are in my commit
@@ -423,7 +422,7 @@ function makeChecker(expectedForm: any, expectedFormUrl: string, options?: { par
423422 if ( options && "parse" in options ) {
424423 suggestion = options . parse ( newText ) ;
425424 } else {
426- try { suggestion = JSON . parse ( newText ) ; } catch ( e ) { if ( e instanceof SyntaxError ) return { suspect : `couldn't parse json: ${ e . message } ` } ; }
425+ try { suggestion = JSON . parse ( newText ) ; } catch ( e ) { if ( e instanceof SyntaxError ) return { body : `couldn't parse json: ${ e . message } ` } ; }
427426 }
428427 const newData = jsonDiff . deepClone ( suggestion ) ;
429428 if ( options && "ignore" in options ) options . ignore ( newData ) ;
@@ -432,15 +431,12 @@ function makeChecker(expectedForm: any, expectedFormUrl: string, options?: { par
432431 // suspect
433432 const vsMaster = await ignoreExistingDiffs ( "master" ) ;
434433 if ( ! vsMaster ) return undefined ;
435- if ( vsMaster . done ) return { suspect : vsMaster . suspect } ;
434+ if ( vsMaster . done ) return { body : vsMaster . suspect } ;
436435 // whereas getting closer relative to existing suggestions means
437436 // no new suggestions
438- if ( ! await ignoreExistingDiffs ( "latestSuggestions " ) ) return { suspect : vsMaster . suspect } ;
437+ if ( ! await ignoreExistingDiffs ( "latestExplanations " ) ) return { body : vsMaster . suspect } ;
439438 jsonDiff . applyPatch ( suggestion , jsonDiff . compare ( newData , towardsIt ) ) ;
440- return {
441- suspect : vsMaster . suspect ,
442- suggestion : makeSuggestion ( ) ,
443- } ;
439+ return makeSuggestion ( ) ;
444440
445441 // Apply any preexisting diffs to towardsIt
446442 async function ignoreExistingDiffs ( ref : keyof Refs ) {
@@ -490,7 +486,7 @@ function makeChecker(expectedForm: any, expectedFormUrl: string, options?: { par
490486 return {
491487 startLine,
492488 endLine,
493- text : suggestionLines . join ( "" ) ,
489+ body : vsMaster ! . suspect + "\n```suggestion\n" + suggestionLines . join ( "" ) + "```" ,
494490 } ;
495491 }
496492 } ;
0 commit comments