@@ -70,14 +70,13 @@ type FileKind = "test" | "definition" | "markdown" | "package-meta" | "package-m
70
70
export type FileInfo = {
71
71
path : string ,
72
72
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"
75
74
} ;
76
75
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 ;
81
80
}
82
81
83
82
export type ReviewInfo = {
@@ -206,7 +205,7 @@ export async function queryPRInfo(prNumber: number) {
206
205
interface Refs {
207
206
readonly head : string ;
208
207
readonly master : "master" ;
209
- readonly latestSuggestions : string ;
208
+ readonly latestExplanations : string ;
210
209
}
211
210
212
211
// The GQL response => Useful data for us
@@ -241,8 +240,8 @@ export async function deriveStateForPR(
241
240
const refs = {
242
241
head : headCommit . oid ,
243
242
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 ) =>
246
245
Date . parse ( a . submittedAt ) - Date . parse ( b . submittedAt ) ) ?. commit ?. oid ,
247
246
} as const ;
248
247
const pkgInfoEtc = await getPackageInfosEtc (
@@ -391,26 +390,26 @@ async function categorizeFile(path: string, getContents: GetContents): Promise<[
391
390
case "md" : return [ pkg , { path, kind : "markdown" } ] ;
392
391
default : {
393
392
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 } ] ;
395
394
}
396
395
}
397
396
}
398
397
399
398
interface 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 > ;
402
401
}
403
402
const configSuspicious = < ConfigSuspicious > ( async ( path , getContents ) => {
404
403
const basename = path . replace ( / .* \/ / , "" ) ;
405
404
const tester = configSuspicious [ basename ] ;
406
- if ( ! tester ) return { suspect : `edited` } ;
405
+ if ( ! tester ) return { body : `edited` } ;
407
406
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` } ;
409
408
return tester ( newText , getContents ) ;
410
409
} ) ;
411
410
configSuspicious [ "OTHER_FILES.txt" ] = async newText =>
412
411
// not empty
413
- ( newText . length === 0 ) ? { suspect : "empty" }
412
+ ( newText . length === 0 ) ? { body : "empty" }
414
413
: undefined ;
415
414
configSuspicious [ "package.json" ] = makeJsonCheckerFromCore (
416
415
{ 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 ) { if ( e instanceof SyntaxError ) return { suspect : `couldn't parse json: ${ e . message } ` } ; }
448
+ try { suggestion = JSON . parse ( newText ) ; } catch ( e ) { if ( e instanceof SyntaxError ) return { body : `couldn't parse json: ${ e . message } ` } ; }
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 ) {
@@ -508,7 +504,7 @@ function makeJsonCheckerFromCore(requiredForm: any, ignoredKeys: string[], requi
508
504
return {
509
505
startLine,
510
506
endLine,
511
- text : suggestionLines . join ( "" ) ,
507
+ body : vsMaster ! . suspect + "\n```suggestion\n" + suggestionLines . join ( "" ) + "```" ,
512
508
} ;
513
509
}
514
510
} ;
0 commit comments