@@ -56,14 +56,13 @@ type FileKind = "test" | "definition" | "markdown" | "package-meta" | "package-m
56
56
export type FileInfo = {
57
57
path : string ,
58
58
kind : FileKind ,
59
- suspect ?: string , // reason for a file being "package-meta" rather than "package-meta-ok"
60
- suggestion ?: Suggestion , // The differences from the expected form, as GitHub suggestions
59
+ suspect ?: Explanation // reason for a file being "package-meta" rather than "package-meta-ok"
61
60
} ;
62
61
63
- export interface Suggestion {
64
- readonly startLine : number ;
65
- readonly endLine : number ;
66
- readonly text : string ;
62
+ export interface Explanation {
63
+ readonly startLine ? : number ;
64
+ readonly endLine ? : number ;
65
+ readonly body : string ;
67
66
}
68
67
69
68
export type ReviewInfo = {
@@ -186,7 +185,7 @@ export async function queryPRInfo(prNumber: number) {
186
185
interface Refs {
187
186
readonly head : string ;
188
187
readonly master : "master" ;
189
- readonly latestSuggestions : string ;
188
+ readonly latestExplanations : string ;
190
189
}
191
190
192
191
// The GQL response => Useful data for us
@@ -218,8 +217,8 @@ export async function deriveStateForPR(
218
217
const refs = {
219
218
head : prInfo . headRefOid ,
220
219
master : "master" ,
221
- // Exclude existing suggestions from subsequent reviews
222
- latestSuggestions : max ( noNullish ( prInfo . reviews ?. nodes ) . filter ( review => ! authorNotBot ( review ) ) , ( a , b ) =>
220
+ // Exclude existing explanations from subsequent reviews
221
+ latestExplanations : max ( noNullish ( prInfo . reviews ?. nodes ) . filter ( review => ! authorNotBot ( review ) ) , ( a , b ) =>
223
222
Date . parse ( a . submittedAt ) - Date . parse ( b . submittedAt ) ) ?. commit ?. oid ,
224
223
} as const ;
225
224
const pkgInfoEtc = await getPackageInfosEtc (
@@ -353,19 +352,19 @@ async function categorizeFile(path: string, getContents: GetContents): Promise<[
353
352
case "md" : return [ pkg , { path, kind : "markdown" } ] ;
354
353
default : {
355
354
const suspect = await configSuspicious ( path , getContents ) ;
356
- return [ pkg , { path, kind : suspect ? "package-meta" : "package-meta-ok" , ... suspect } ] ;
355
+ return [ pkg , { path, kind : suspect ? "package-meta" : "package-meta-ok" , suspect } ] ;
357
356
}
358
357
}
359
358
}
360
359
361
360
interface ConfigSuspicious {
362
- ( path : string , getContents : GetContents ) : Promise < { suspect : string , sugestion ?: Suggestion } | undefined > ;
363
- [ basename : string ] : ( newText : string , getContents : GetContents ) => Promise < { suspect : string , suggestion ?: Suggestion } | undefined > ;
361
+ ( path : string , getContents : GetContents ) : Promise < Explanation | undefined > ;
362
+ [ basename : string ] : ( newText : string , getContents : GetContents ) => Promise < Explanation | undefined > ;
364
363
}
365
364
const configSuspicious = < ConfigSuspicious > ( async ( path , getContents ) => {
366
365
const basename = path . replace ( / .* \/ / , "" ) ;
367
366
const checker = configSuspicious [ basename ] ;
368
- if ( ! checker ) return { suspect : `edited` } ;
367
+ if ( ! checker ) return { body : `edited` } ;
369
368
const newText = await getContents ( "head" ) ;
370
369
// Removing tslint.json, tsconfig.json, package.json and
371
370
// OTHER_FILES.txt is checked by the CI. Specifics are in my commit
@@ -424,7 +423,7 @@ function makeChecker(expectedForm: any, expectedFormUrl: string, options?: { par
424
423
if ( options && "parse" in options ) {
425
424
suggestion = options . parse ( newText ) ;
426
425
} else {
427
- try { suggestion = JSON . parse ( newText ) ; } catch ( e ) { if ( e instanceof SyntaxError ) return { suspect : `couldn't parse json: ${ e . message } ` } ; }
426
+ try { suggestion = JSON . parse ( newText ) ; } catch ( e ) { if ( e instanceof SyntaxError ) return { body : `couldn't parse json: ${ e . message } ` } ; }
428
427
}
429
428
const newData = jsonDiff . deepClone ( suggestion ) ;
430
429
if ( options && "ignore" in options ) options . ignore ( newData ) ;
@@ -433,15 +432,12 @@ function makeChecker(expectedForm: any, expectedFormUrl: string, options?: { par
433
432
// suspect
434
433
const vsMaster = await ignoreExistingDiffs ( "master" ) ;
435
434
if ( ! vsMaster ) return undefined ;
436
- if ( vsMaster . done ) return { suspect : vsMaster . suspect } ;
435
+ if ( vsMaster . done ) return { body : vsMaster . suspect } ;
437
436
// whereas getting closer relative to existing suggestions means
438
437
// no new suggestions
439
- if ( ! await ignoreExistingDiffs ( "latestSuggestions " ) ) return { suspect : vsMaster . suspect } ;
438
+ if ( ! await ignoreExistingDiffs ( "latestExplanations " ) ) return { body : vsMaster . suspect } ;
440
439
jsonDiff . applyPatch ( suggestion , jsonDiff . compare ( newData , towardsIt ) ) ;
441
- return {
442
- suspect : vsMaster . suspect ,
443
- suggestion : makeSuggestion ( ) ,
444
- } ;
440
+ return makeSuggestion ( ) ;
445
441
446
442
// Apply any preexisting diffs to towardsIt
447
443
async function ignoreExistingDiffs ( ref : keyof Refs ) {
@@ -491,7 +487,7 @@ function makeChecker(expectedForm: any, expectedFormUrl: string, options?: { par
491
487
return {
492
488
startLine,
493
489
endLine,
494
- text : suggestionLines . join ( "" ) ,
490
+ body : vsMaster ! . suspect + "\n```suggestion\n" + suggestionLines . join ( "" ) + "```" ,
495
491
} ;
496
492
}
497
493
} ;
0 commit comments