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