@@ -74,14 +74,13 @@ type FileKind = "test" | "definition" | "markdown" | "package-meta" | "package-m
74
74
export type FileInfo = {
75
75
path : string ,
76
76
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"
79
78
} ;
80
79
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 ;
85
84
}
86
85
87
86
export type ReviewInfo = {
@@ -201,7 +200,7 @@ export async function queryPRInfo(prNumber: number) {
201
200
interface Refs {
202
201
readonly head : string ;
203
202
readonly master : "master" ;
204
- readonly latestSuggestions : string ;
203
+ readonly latestExplanations : string ;
205
204
}
206
205
207
206
// The GQL response => Useful data for us
@@ -236,8 +235,8 @@ export async function deriveStateForPR(
236
235
const refs = {
237
236
head : headCommit . oid ,
238
237
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 ) =>
241
240
review && ! authorNotBot ( review ) && (
242
241
! latest ?. submittedAt || review . submittedAt && new Date ( review . submittedAt ) > new Date ( latest . submittedAt ) )
243
242
? review : latest , null ) ?. commit ?. oid ,
@@ -393,26 +392,26 @@ async function categorizeFile(path: string, getContents: GetContents): Promise<[
393
392
case "md" : return [ pkg , { path, kind : "markdown" } ] ;
394
393
default : {
395
394
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 } ] ;
397
396
}
398
397
}
399
398
}
400
399
401
400
interface ConfigSuspicious {
402
- ( path : string , getContents : GetContents ) : Promise < { suspect : string , sugestion ?: Suggestion } | undefined > ;
403
- [ basename : string ] : ( newText : string , getContents : GetContents ) => Promise < { suspect : string , suggestion ?: Suggestion } | undefined > ;
401
+ ( path : string , getContents : GetContents ) : Promise < Explanation | undefined > ;
402
+ [ basename : string ] : ( newText : string , getContents : GetContents ) => Promise < Explanation | undefined > ;
404
403
}
405
404
const configSuspicious = < ConfigSuspicious > ( async ( path , getContents ) => {
406
405
const basename = path . replace ( / .* \/ / , "" ) ;
407
406
const tester = configSuspicious [ basename ] ;
408
- if ( ! tester ) return { suspect : `edited` } ;
407
+ if ( ! tester ) return { body : `edited` } ;
409
408
const newText = await getContents ( "head" ) ;
410
- if ( newText === undefined ) return { suspect : `couldn't fetch contents` } ;
409
+ if ( newText === undefined ) return { body : `couldn't fetch contents` } ;
411
410
return tester ( newText , getContents ) ;
412
411
} ) ;
413
412
configSuspicious [ "OTHER_FILES.txt" ] = async newText =>
414
413
// not empty
415
- ( newText . length === 0 ) ? { suspect : "empty" }
414
+ ( newText . length === 0 ) ? { body : "empty" }
416
415
: undefined ;
417
416
configSuspicious [ "package.json" ] = makeJsonCheckerFromCore (
418
417
{ private : true } ,
@@ -446,23 +445,20 @@ configSuspicious["tsconfig.json"] = makeJsonCheckerFromCore(
446
445
function makeJsonCheckerFromCore ( requiredForm : any , ignoredKeys : string [ ] , requiredFormUrl ?: string ) {
447
446
return async ( newText : string , getContents : GetContents ) => {
448
447
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" } ; }
450
449
const newJson = jsonDiff . deepClone ( suggestion ) ;
451
450
jsonDiff . applyPatch ( newJson , ignoredKeys . map ( path => ( { op : "remove" , path } ) ) ) ;
452
451
const towardsIt = jsonDiff . deepClone ( requiredForm ) ;
453
452
// Getting closer to the required form relative to master isn't
454
453
// suspect
455
454
const vsMaster = await ignoreExistingDiffs ( "master" ) ;
456
455
if ( ! vsMaster ) return undefined ;
457
- if ( vsMaster . done ) return { suspect : vsMaster . suspect } ;
456
+ if ( vsMaster . done ) return { body : vsMaster . suspect } ;
458
457
// whereas getting closer relative to existing suggestions means
459
458
// no new suggestions
460
- if ( ! await ignoreExistingDiffs ( "latestSuggestions " ) ) return { suspect : vsMaster . suspect } ;
459
+ if ( ! await ignoreExistingDiffs ( "latestExplanations " ) ) return { body : vsMaster . suspect } ;
461
460
jsonDiff . applyPatch ( suggestion , jsonDiff . compare ( newJson , towardsIt ) ) ;
462
- return {
463
- suspect : vsMaster . suspect ,
464
- suggestion : makeJsonSuggestion ( ) ,
465
- } ;
461
+ return makeJsonSuggestion ( ) ;
466
462
467
463
// Apply any preexisting diffs to towardsIt
468
464
async function ignoreExistingDiffs ( ref : keyof Refs ) {
@@ -511,7 +507,7 @@ function makeJsonCheckerFromCore(requiredForm: any, ignoredKeys: string[], requi
511
507
return {
512
508
startLine,
513
509
endLine,
514
- text : suggestionLines . join ( "" ) ,
510
+ body : vsMaster ! . suspect + "\n```suggestion\n" + suggestionLines . join ( "" ) + "```" ,
515
511
} ;
516
512
}
517
513
} ;
0 commit comments