@@ -58,14 +58,13 @@ type FileKind = "test" | "definition" | "markdown" | "package-meta" | "package-m
5858export type FileInfo = {
5959 path : string ,
6060 kind : FileKind ,
61- suspect ?: string , // reason for a file being "package-meta" rather than "package-meta-ok"
62- suggestion ?: Suggestion , // The differences from the expected form, as GitHub suggestions
61+ suspect ?: Explanation // reason for a file being "package-meta" rather than "package-meta-ok"
6362} ;
6463
65- export interface Suggestion {
66- readonly startLine : number ;
67- readonly endLine : number ;
68- readonly text : string ;
64+ export interface Explanation {
65+ readonly startLine ? : number ;
66+ readonly endLine ? : number ;
67+ readonly body : string ;
6968}
7069
7170export type ReviewInfo = {
@@ -188,7 +187,7 @@ export async function queryPRInfo(prNumber: number) {
188187interface Refs {
189188 readonly head : string ;
190189 readonly master : "master" ;
191- readonly latestSuggestions : string ;
190+ readonly latestExplanations : string ;
192191}
193192
194193// The GQL response => Useful data for us
@@ -220,8 +219,8 @@ export async function deriveStateForPR(
220219 const refs = {
221220 head : prInfo . headRefOid ,
222221 master : "master" ,
223- // Exclude existing suggestions from subsequent reviews
224- latestSuggestions : max ( noNullish ( prInfo . reviews ?. nodes ) . filter ( review => ! authorNotBot ( review ) ) , ( a , b ) =>
222+ // Exclude existing explanations from subsequent reviews
223+ latestExplanations : max ( noNullish ( prInfo . reviews ?. nodes ) . filter ( review => ! authorNotBot ( review ) ) , ( a , b ) =>
225224 Date . parse ( a . submittedAt ) - Date . parse ( b . submittedAt ) ) ?. commit ?. oid ,
226225 } as const ;
227226 const pkgInfoEtc = await getPackageInfosEtc (
@@ -355,19 +354,19 @@ async function categorizeFile(path: string, getContents: GetContents): Promise<[
355354 case "md" : return [ pkg , { path, kind : "markdown" } ] ;
356355 default : {
357356 const suspect = await configSuspicious ( path , getContents ) ;
358- return [ pkg , { path, kind : suspect ? "package-meta" : "package-meta-ok" , ... suspect } ] ;
357+ return [ pkg , { path, kind : suspect ? "package-meta" : "package-meta-ok" , suspect } ] ;
359358 }
360359 }
361360}
362361
363362interface ConfigSuspicious {
364- ( path : string , getContents : GetContents ) : Promise < { suspect : string , sugestion ?: Suggestion } | undefined > ;
365- [ basename : string ] : ( newText : string , getContents : GetContents ) => Promise < { suspect : string , suggestion ?: Suggestion } | undefined > ;
363+ ( path : string , getContents : GetContents ) : Promise < Explanation | undefined > ;
364+ [ basename : string ] : ( newText : string , getContents : GetContents ) => Promise < Explanation | undefined > ;
366365}
367366const configSuspicious = < ConfigSuspicious > ( async ( path , getContents ) => {
368367 const basename = path . replace ( / .* \/ / , "" ) ;
369368 const checker = configSuspicious [ basename ] ;
370- if ( ! checker ) return { suspect : `edited` } ;
369+ if ( ! checker ) return { body : `edited` } ;
371370 const newText = await getContents ( "head" ) ;
372371 // Removing tslint.json, tsconfig.json, package.json and
373372 // OTHER_FILES.txt is checked by the CI. Specifics are in my commit
@@ -426,7 +425,7 @@ function makeChecker(expectedForm: any, expectedFormUrl: string, options?: { par
426425 if ( options && "parse" in options ) {
427426 suggestion = options . parse ( newText ) ;
428427 } else {
429- try { suggestion = JSON . parse ( newText ) ; } catch ( e ) { if ( e instanceof SyntaxError ) return { suspect : `couldn't parse json: ${ e . message } ` } ; }
428+ try { suggestion = JSON . parse ( newText ) ; } catch ( e ) { if ( e instanceof SyntaxError ) return { body : `couldn't parse json: ${ e . message } ` } ; }
430429 }
431430 const newData = jsonDiff . deepClone ( suggestion ) ;
432431 if ( options && "ignore" in options ) options . ignore ( newData ) ;
@@ -435,15 +434,12 @@ function makeChecker(expectedForm: any, expectedFormUrl: string, options?: { par
435434 // suspect
436435 const vsMaster = await ignoreExistingDiffs ( "master" ) ;
437436 if ( ! vsMaster ) return undefined ;
438- if ( vsMaster . done ) return { suspect : vsMaster . suspect } ;
437+ if ( vsMaster . done ) return { body : vsMaster . suspect } ;
439438 // whereas getting closer relative to existing suggestions means
440439 // no new suggestions
441- if ( ! await ignoreExistingDiffs ( "latestSuggestions " ) ) return { suspect : vsMaster . suspect } ;
440+ if ( ! await ignoreExistingDiffs ( "latestExplanations " ) ) return { body : vsMaster . suspect } ;
442441 jsonDiff . applyPatch ( suggestion , jsonDiff . compare ( newData , towardsIt ) ) ;
443- return {
444- suspect : vsMaster . suspect ,
445- suggestion : makeSuggestion ( ) ,
446- } ;
442+ return makeSuggestion ( ) ;
447443
448444 // Apply any preexisting diffs to towardsIt
449445 async function ignoreExistingDiffs ( ref : keyof Refs ) {
@@ -493,7 +489,7 @@ function makeChecker(expectedForm: any, expectedFormUrl: string, options?: { par
493489 return {
494490 startLine,
495491 endLine,
496- text : suggestionLines . join ( "" ) ,
492+ body : vsMaster ! . suspect + "\n```suggestion\n" + suggestionLines . join ( "" ) + "```" ,
497493 } ;
498494 }
499495 } ;
0 commit comments