@@ -74,14 +74,13 @@ type FileKind = "test" | "definition" | "markdown" | "package-meta" | "package-m
7474export type FileInfo = {
7575 path : string ,
7676 kind : FileKind ,
77- suspect ?: string , // reason for a file being "package-meta" rather than "package-meta-ok"
78- suggestion ?: Suggestion , // The differences from the required form, as GitHub suggestions
77+ suspect ?: Explanation // reason for a file being "package-meta" rather than "package-meta-ok"
7978} ;
8079
81- export interface Suggestion {
82- readonly startLine : number ;
83- readonly endLine : number ;
84- readonly text : string ;
80+ export interface Explanation {
81+ readonly startLine ? : number ;
82+ readonly endLine ? : number ;
83+ readonly body : string ;
8584}
8685
8786export type ReviewInfo = {
@@ -201,7 +200,7 @@ export async function queryPRInfo(prNumber: number) {
201200interface Refs {
202201 readonly head : string ;
203202 readonly master : "master" ;
204- readonly latestSuggestions : string ;
203+ readonly latestExplanations : string ;
205204}
206205
207206// The GQL response => Useful data for us
@@ -236,8 +235,8 @@ export async function deriveStateForPR(
236235 const refs = {
237236 head : headCommit . oid ,
238237 master : "master" ,
239- // Exclude existing suggestions from subsequent reviews
240- latestSuggestions : prInfo . reviews ?. nodes ?. reduce ( ( latest , review ) =>
238+ // Exclude existing explanations from subsequent reviews
239+ latestExplanations : prInfo . reviews ?. nodes ?. reduce ( ( latest , review ) =>
241240 review && ! authorNotBot ( review ) && (
242241 ! latest ?. submittedAt || review . submittedAt && new Date ( review . submittedAt ) > new Date ( latest . submittedAt ) )
243242 ? review : latest , null ) ?. commit ?. oid ,
@@ -393,25 +392,25 @@ async function categorizeFile(path: string, getContents: GetContents): Promise<[
393392 case "md" : return [ pkg , { path, kind : "markdown" } ] ;
394393 default :
395394 const suspect = await configSuspicious ( path , getContents ) ;
396- return [ pkg , { path, kind : suspect ? "package-meta" : "package-meta-ok" , ... suspect } ] ;
395+ return [ pkg , { path, kind : suspect ? "package-meta" : "package-meta-ok" , suspect } ] ;
397396 }
398397}
399398
400399interface ConfigSuspicious {
401- ( path : string , getContents : GetContents ) : Promise < { suspect : string , sugestion ?: Suggestion } | undefined > ;
402- [ basename : string ] : ( newText : string , getContents : GetContents ) => Promise < { suspect : string , suggestion ?: Suggestion } | undefined > ;
400+ ( path : string , getContents : GetContents ) : Promise < Explanation | undefined > ;
401+ [ basename : string ] : ( newText : string , getContents : GetContents ) => Promise < Explanation | undefined > ;
403402}
404403const configSuspicious = < ConfigSuspicious > ( async ( path , getContents ) => {
405404 const basename = path . replace ( / .* \/ / , "" ) ;
406405 const tester = configSuspicious [ basename ] ;
407- if ( ! tester ) return { suspect : `edited` } ;
406+ if ( ! tester ) return { body : `edited` } ;
408407 const newText = await getContents ( "head" ) ;
409- if ( newText === undefined ) return { suspect : `couldn't fetch contents` } ;
408+ if ( newText === undefined ) return { body : `couldn't fetch contents` } ;
410409 return tester ( newText , getContents ) ;
411410} ) ;
412411configSuspicious [ "OTHER_FILES.txt" ] = async newText =>
413412 // not empty
414- ( newText . length === 0 ) ? { suspect : "empty" }
413+ ( newText . length === 0 ) ? { body : "empty" }
415414 : undefined ;
416415configSuspicious [ "package.json" ] = makeJsonCheckerFromCore (
417416 { private : true } ,
@@ -445,23 +444,20 @@ configSuspicious["tsconfig.json"] = makeJsonCheckerFromCore(
445444function makeJsonCheckerFromCore ( requiredForm : any , ignoredKeys : string [ ] , requiredFormUrl ?: string ) {
446445 return async ( newText : string , getContents : GetContents ) => {
447446 let suggestion : any ;
448- try { suggestion = JSON . parse ( newText ) ; } catch ( e ) { return { suspect : "couldn't parse json" } ; }
447+ try { suggestion = JSON . parse ( newText ) ; } catch ( e ) { return { body : "couldn't parse json" } ; }
449448 const newJson = jsonDiff . deepClone ( suggestion ) ;
450449 jsonDiff . applyPatch ( newJson , ignoredKeys . map ( path => ( { op : "remove" , path } ) ) ) ;
451450 const towardsIt = jsonDiff . deepClone ( requiredForm ) ;
452451 // Getting closer to the required form relative to master isn't
453452 // suspect
454453 const vsMaster = await ignoreExistingDiffs ( "master" ) ;
455454 if ( ! vsMaster ) return undefined ;
456- if ( vsMaster . done ) return { suspect : vsMaster . suspect } ;
455+ if ( vsMaster . done ) return { body : vsMaster . suspect } ;
457456 // whereas getting closer relative to existing suggestions means
458457 // no new suggestions
459- if ( ! await ignoreExistingDiffs ( "latestSuggestions " ) ) return { suspect : vsMaster . suspect } ;
458+ if ( ! await ignoreExistingDiffs ( "latestExplanations " ) ) return { body : vsMaster . suspect } ;
460459 jsonDiff . applyPatch ( suggestion , jsonDiff . compare ( newJson , towardsIt ) ) ;
461- return {
462- suspect : vsMaster . suspect ,
463- suggestion : makeJsonSuggestion ( ) ,
464- } ;
460+ return makeJsonSuggestion ( ) ;
465461
466462 // Apply any preexisting diffs to towardsIt
467463 async function ignoreExistingDiffs ( ref : keyof Refs ) {
@@ -510,7 +506,7 @@ function makeJsonCheckerFromCore(requiredForm: any, ignoredKeys: string[], requi
510506 return {
511507 startLine,
512508 endLine,
513- text : suggestionLines . join ( "" ) ,
509+ body : vsMaster ! . suspect + "\n```suggestion\n" + suggestionLines . join ( "" ) + "```" ,
514510 } ;
515511 }
516512 } ;
0 commit comments