@@ -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,25 +392,25 @@ 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
interface 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 > ;
403
402
}
404
403
const configSuspicious = < ConfigSuspicious > ( async ( path , getContents ) => {
405
404
const basename = path . replace ( / .* \/ / , "" ) ;
406
405
const tester = configSuspicious [ basename ] ;
407
- if ( ! tester ) return { suspect : `edited` } ;
406
+ if ( ! tester ) return { body : `edited` } ;
408
407
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` } ;
410
409
return tester ( newText , getContents ) ;
411
410
} ) ;
412
411
configSuspicious [ "OTHER_FILES.txt" ] = async newText =>
413
412
// not empty
414
- ( newText . length === 0 ) ? { suspect : "empty" }
413
+ ( newText . length === 0 ) ? { body : "empty" }
415
414
: undefined ;
416
415
configSuspicious [ "package.json" ] = makeJsonCheckerFromCore (
417
416
{ private : true } ,
@@ -445,23 +444,20 @@ configSuspicious["tsconfig.json"] = makeJsonCheckerFromCore(
445
444
function makeJsonCheckerFromCore ( requiredForm : any , ignoredKeys : string [ ] , requiredFormUrl ?: string ) {
446
445
return async ( newText : string , getContents : GetContents ) => {
447
446
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" } ; }
449
448
const newJson = jsonDiff . deepClone ( suggestion ) ;
450
449
jsonDiff . applyPatch ( newJson , ignoredKeys . map ( path => ( { op : "remove" , path } ) ) ) ;
451
450
const towardsIt = jsonDiff . deepClone ( requiredForm ) ;
452
451
// Getting closer to the required form relative to master isn't
453
452
// suspect
454
453
const vsMaster = await ignoreExistingDiffs ( "master" ) ;
455
454
if ( ! vsMaster ) return undefined ;
456
- if ( vsMaster . done ) return { suspect : vsMaster . suspect } ;
455
+ if ( vsMaster . done ) return { body : vsMaster . suspect } ;
457
456
// whereas getting closer relative to existing suggestions means
458
457
// no new suggestions
459
- if ( ! await ignoreExistingDiffs ( "latestSuggestions " ) ) return { suspect : vsMaster . suspect } ;
458
+ if ( ! await ignoreExistingDiffs ( "latestExplanations " ) ) return { body : vsMaster . suspect } ;
460
459
jsonDiff . applyPatch ( suggestion , jsonDiff . compare ( newJson , towardsIt ) ) ;
461
- return {
462
- suspect : vsMaster . suspect ,
463
- suggestion : makeJsonSuggestion ( ) ,
464
- } ;
460
+ return makeJsonSuggestion ( ) ;
465
461
466
462
// Apply any preexisting diffs to towardsIt
467
463
async function ignoreExistingDiffs ( ref : keyof Refs ) {
@@ -510,7 +506,7 @@ function makeJsonCheckerFromCore(requiredForm: any, ignoredKeys: string[], requi
510
506
return {
511
507
startLine,
512
508
endLine,
513
- text : suggestionLines . join ( "" ) ,
509
+ body : vsMaster ! . suspect + "\n```suggestion\n" + suggestionLines . join ( "" ) + "```" ,
514
510
} ;
515
511
}
516
512
} ;
0 commit comments