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