@@ -70,14 +70,13 @@ type FileKind = "test" | "definition" | "markdown" | "package-meta" | "package-m
7070export type FileInfo = {
7171 path : string ,
7272 kind : FileKind ,
73- suspect ?: string , // reason for a file being "package-meta" rather than "package-meta-ok"
74- suggestion ?: Suggestion , // The differences from the required form, as GitHub suggestions
73+ suspect ?: Explanation // reason for a file being "package-meta" rather than "package-meta-ok"
7574} ;
7675
77- export interface Suggestion {
78- readonly startLine : number ;
79- readonly endLine : number ;
80- readonly text : string ;
76+ export interface Explanation {
77+ readonly startLine ? : number ;
78+ readonly endLine ? : number ;
79+ readonly body : string ;
8180}
8281
8382export type ReviewInfo = {
@@ -206,7 +205,7 @@ export async function queryPRInfo(prNumber: number) {
206205interface Refs {
207206 readonly head : string ;
208207 readonly master : "master" ;
209- readonly latestSuggestions : string ;
208+ readonly latestExplanations : string ;
210209}
211210
212211// The GQL response => Useful data for us
@@ -241,8 +240,8 @@ export async function deriveStateForPR(
241240 const refs = {
242241 head : headCommit . oid ,
243242 master : "master" ,
244- // Exclude existing suggestions from subsequent reviews
245- latestSuggestions : max ( noNullish ( prInfo . reviews ?. nodes ) . filter ( review => ! authorNotBot ( review ) ) , ( a , b ) =>
243+ // Exclude existing explanations from subsequent reviews
244+ latestExplanations : max ( noNullish ( prInfo . reviews ?. nodes ) . filter ( review => ! authorNotBot ( review ) ) , ( a , b ) =>
246245 Date . parse ( a . submittedAt ) - Date . parse ( b . submittedAt ) ) ?. commit ?. oid ,
247246 } as const ;
248247 const pkgInfoEtc = await getPackageInfosEtc (
@@ -391,26 +390,26 @@ async function categorizeFile(path: string, getContents: GetContents): Promise<[
391390 case "md" : return [ pkg , { path, kind : "markdown" } ] ;
392391 default : {
393392 const suspect = await configSuspicious ( path , getContents ) ;
394- return [ pkg , { path, kind : suspect ? "package-meta" : "package-meta-ok" , ... suspect } ] ;
393+ return [ pkg , { path, kind : suspect ? "package-meta" : "package-meta-ok" , suspect } ] ;
395394 }
396395 }
397396}
398397
399398interface ConfigSuspicious {
400- ( path : string , getContents : GetContents ) : Promise < { suspect : string , sugestion ?: Suggestion } | undefined > ;
401- [ basename : string ] : ( newText : string , getContents : GetContents ) => Promise < { suspect : string , suggestion ?: Suggestion } | undefined > ;
399+ ( path : string , getContents : GetContents ) : Promise < Explanation | undefined > ;
400+ [ basename : string ] : ( newText : string , getContents : GetContents ) => Promise < Explanation | undefined > ;
402401}
403402const configSuspicious = < ConfigSuspicious > ( async ( path , getContents ) => {
404403 const basename = path . replace ( / .* \/ / , "" ) ;
405404 const tester = configSuspicious [ basename ] ;
406- if ( ! tester ) return { suspect : `edited` } ;
405+ if ( ! tester ) return { body : `edited` } ;
407406 const newText = await getContents ( "head" ) ;
408- if ( newText === undefined ) return { suspect : `couldn't fetch contents` } ;
407+ if ( newText === undefined ) return { body : `couldn't fetch contents` } ;
409408 return tester ( newText , getContents ) ;
410409} ) ;
411410configSuspicious [ "OTHER_FILES.txt" ] = async newText =>
412411 // not empty
413- ( newText . length === 0 ) ? { suspect : "empty" }
412+ ( newText . length === 0 ) ? { body : "empty" }
414413 : undefined ;
415414configSuspicious [ "package.json" ] = makeJsonCheckerFromCore (
416415 { private : true } ,
@@ -446,23 +445,20 @@ configSuspicious["tsconfig.json"] = makeJsonCheckerFromCore(
446445function makeJsonCheckerFromCore ( requiredForm : any , ignoredKeys : string [ ] , requiredFormUrl : string ) {
447446 return async ( newText : string , getContents : GetContents ) => {
448447 let suggestion : any ;
449- try { suggestion = JSON . parse ( newText ) ; } catch ( e ) { return { suspect : "couldn't parse json" } ; }
448+ try { suggestion = JSON . parse ( newText ) ; } catch ( e ) { return { body : "couldn't parse json" } ; }
450449 const newJson = jsonDiff . deepClone ( suggestion ) ;
451450 jsonDiff . applyPatch ( newJson , ignoredKeys . map ( path => ( { op : "remove" , path } ) ) ) ;
452451 const towardsIt = jsonDiff . deepClone ( requiredForm ) ;
453452 // Getting closer to the required form relative to master isn't
454453 // suspect
455454 const vsMaster = await ignoreExistingDiffs ( "master" ) ;
456455 if ( ! vsMaster ) return undefined ;
457- if ( vsMaster . done ) return { suspect : vsMaster . suspect } ;
456+ if ( vsMaster . done ) return { body : vsMaster . suspect } ;
458457 // whereas getting closer relative to existing suggestions means
459458 // no new suggestions
460- if ( ! await ignoreExistingDiffs ( "latestSuggestions " ) ) return { suspect : vsMaster . suspect } ;
459+ if ( ! await ignoreExistingDiffs ( "latestExplanations " ) ) return { body : vsMaster . suspect } ;
461460 jsonDiff . applyPatch ( suggestion , jsonDiff . compare ( newJson , towardsIt ) ) ;
462- return {
463- suspect : vsMaster . suspect ,
464- suggestion : makeJsonSuggestion ( ) ,
465- } ;
461+ return makeJsonSuggestion ( ) ;
466462
467463 // Apply any preexisting diffs to towardsIt
468464 async function ignoreExistingDiffs ( ref : keyof Refs ) {
@@ -508,7 +504,7 @@ function makeJsonCheckerFromCore(requiredForm: any, ignoredKeys: string[], requi
508504 return {
509505 startLine,
510506 endLine,
511- text : suggestionLines . join ( "" ) ,
507+ body : vsMaster ! . suspect + "\n```suggestion\n" + suggestionLines . join ( "" ) + "```" ,
512508 } ;
513509 }
514510 } ;
0 commit comments