@@ -40,6 +40,7 @@ import {
4040 type PullRequestDiffFileContentsResult ,
4141 type PullRequestDiffStat ,
4242 type PullRequestDiffInput ,
43+ type PullRequestChangeBreakdown ,
4344 type PullRequestFilesViewedResult ,
4445 type PullRequestDiffResult ,
4546 type PullRequestInvalidateInput ,
@@ -95,6 +96,7 @@ import {
9596import * as PullRequestReadCache from "./PullRequestReadCache.ts" ;
9697import * as PullRequestProviderRegistry from "./PullRequestProviderRegistry.ts" ;
9798import * as ViewedFiles from "./pullRequestViewedFiles.ts" ;
99+ import { toChangeBreakdown } from "./pullRequestChangeBreakdown.ts" ;
98100
99101export interface PullRequestMergeEvent extends PullRequestRef {
100102 readonly mergedAt : string ;
@@ -230,6 +232,9 @@ export class PullRequestService extends Context.Service<
230232 readonly setFilesViewed : (
231233 input : PullRequestSetFilesViewedInput ,
232234 ) => Effect . Effect < void , PullRequestError > ;
235+ readonly changeBreakdown : (
236+ input : PullRequestRef ,
237+ ) => Effect . Effect < PullRequestChangeBreakdown , PullRequestError > ;
233238 readonly runAction : ( input : PullRequestActionInput ) => Effect . Effect < void , PullRequestError > ;
234239 readonly update : ( input : PullRequestUpdateInput ) => Effect . Effect < void , PullRequestError > ;
235240 readonly comment : ( input : PullRequestCommentInput ) => Effect . Effect < void , PullRequestError > ;
@@ -535,6 +540,9 @@ function withRateLimitBackoff(
535540 ...( api . getFilesViewed === undefined
536541 ? { }
537542 : { getFilesViewed : wrap ( "getFilesViewed" , api . getFilesViewed ) } ) ,
543+ ...( api . getFileStats === undefined
544+ ? { }
545+ : { getFileStats : wrap ( "getFileStats" , api . getFileStats ) } ) ,
538546 ...( api . setFilesViewed === undefined
539547 ? { }
540548 : { setFilesViewed : interactive ( "setFilesViewed" , api . setFilesViewed ) } ) ,
@@ -2958,6 +2966,32 @@ export const make = Effect.gen(function* () {
29582966 } ,
29592967 ) ;
29602968
2969+ const changeBreakdownCache = yield * Cache . makeWith (
2970+ ( key : string ) => {
2971+ const ref = refOfCacheKey ( key ) ;
2972+ return requireProject ( ref ) . pipe (
2973+ Effect . flatMap ( ( project ) => {
2974+ const read = project . api . getFileStats ;
2975+ if ( read === undefined ) return Effect . succeed ( null ) ;
2976+ return read ( {
2977+ cwd : project . project . workspaceRoot ,
2978+ repository : project . repository ,
2979+ host : project . host ,
2980+ number : ref . number ,
2981+ } ) . pipe (
2982+ Effect . map ( toChangeBreakdown ) ,
2983+ Effect . mapError ( toPullRequestError ( "changeBreakdown" ) ) ,
2984+ ) ;
2985+ } ) ,
2986+ ) ;
2987+ } ,
2988+ {
2989+ capacity : DETAIL_CACHE_CAPACITY ,
2990+ timeToLive : ( exit , key ) =>
2991+ Exit . isSuccess ( exit ) ? detailTimeToLive ( lastGoodSummary . peek ( key ) ?. state ) : Duration . zero ,
2992+ } ,
2993+ ) ;
2994+
29612995 const previewCache = yield * Cache . makeWith (
29622996 ( key : string ) => {
29632997 return previewUncached ( refOfCacheKey ( key ) ) ;
@@ -3366,6 +3400,9 @@ export const make = Effect.gen(function* () {
33663400 diffFileContents,
33673401 filesViewed : credentialCached ( filesViewed ) ,
33683402 setFilesViewed,
3403+ changeBreakdown : credentialCached ( ( input ) =>
3404+ Cache . get ( changeBreakdownCache , refCacheKey ( input ) ) ,
3405+ ) ,
33693406 runAction : runActionAndInvalidate ,
33703407 update : invalidatedByMutation ( update ) ,
33713408 comment : invalidatedByMutation ( comment ) ,
0 commit comments