@@ -626,6 +626,63 @@ export class AIProviderService implements Disposable {
626626 return result != null ? { ...result , parsed : parseSummarizeResult ( result . content ) } : undefined ;
627627 }
628628
629+ async prepareCompareDataForAIRequest (
630+ repo : Repository ,
631+ headRef : string ,
632+ baseRef : string ,
633+ options ?: {
634+ cancellation ?: CancellationToken ;
635+ reportNoDiffService ?: ( ) => void ;
636+ reportNoCommitsService ?: ( ) => void ;
637+ reportNoChanges ?: ( ) => void ;
638+ } ,
639+ ) : Promise < { diff : string ; logMessages : string } | undefined > {
640+ const { cancellation, reportNoDiffService, reportNoCommitsService, reportNoChanges } = options ?? { } ;
641+ const diffService = repo . git . diff ( ) ;
642+ if ( diffService ?. getDiff === undefined ) {
643+ if ( reportNoDiffService ) {
644+ reportNoDiffService ( ) ;
645+ return ;
646+ }
647+ }
648+
649+ const commitsService = repo . git . commits ( ) ;
650+ if ( commitsService ?. getLog === undefined ) {
651+ if ( reportNoCommitsService ) {
652+ reportNoCommitsService ( ) ;
653+ return ;
654+ }
655+ }
656+
657+ const [ diffResult , logResult ] = await Promise . allSettled ( [
658+ diffService . getDiff ?.( headRef , baseRef , { notation : '...' } ) ,
659+ commitsService . getLog ( `${ baseRef } ..${ headRef } ` ) ,
660+ ] ) ;
661+ const diff = getSettledValue ( diffResult ) ;
662+ const log = getSettledValue ( logResult ) ;
663+
664+ if ( ! diff ?. contents || ! log ?. commits ?. size ) {
665+ reportNoChanges ?.( ) ;
666+ return undefined ;
667+ }
668+
669+ if ( cancellation ?. isCancellationRequested ) throw new CancellationError ( ) ;
670+
671+ const commitMessages : string [ ] = [ ] ;
672+ for ( const commit of [ ...log . commits . values ( ) ] . sort ( ( a , b ) => a . date . getTime ( ) - b . date . getTime ( ) ) ) {
673+ const message = commit . message ?? commit . summary ;
674+ if ( message ) {
675+ commitMessages . push (
676+ `<commit-message ${ commit . date . toISOString ( ) } >\n${
677+ commit . message ?? commit . summary
678+ } \n<end-of-commit-message>`,
679+ ) ;
680+ }
681+ }
682+
683+ return { diff : diff . contents , logMessages : commitMessages . join ( '\n\n' ) } ;
684+ }
685+
629686 async generateCreatePullRequest (
630687 repo : Repository ,
631688 baseRef : string ,
@@ -641,31 +698,21 @@ export class AIProviderService implements Disposable {
641698 const result = await this . sendRequest (
642699 'generate-create-pullRequest' ,
643700 async ( model , reporting , cancellation , maxInputTokens , retries ) => {
644- const [ diffResult , logResult ] = await Promise . allSettled ( [
645- repo . git . diff ( ) . getDiff ?.( headRef , baseRef , { notation : '...' } ) ,
646- repo . git . commits ( ) . getLog ( `${ baseRef } ..${ headRef } ` ) ,
647- ] ) ;
648-
649- const diff = getSettledValue ( diffResult ) ;
650- const log = getSettledValue ( logResult ) ;
701+ const compareData = await this . prepareCompareDataForAIRequest ( repo , headRef , baseRef , {
702+ cancellation : cancellation ,
703+ } ) ;
651704
652- if ( ! diff ?. contents || ! log ?. commits ?. size ) {
705+ if ( ! compareData ?. diff || ! compareData ?. logMessages ) {
653706 throw new AINoRequestDataError ( 'No changes to generate a pull request from.' ) ;
654707 }
655708
656- if ( cancellation . isCancellationRequested ) throw new CancellationError ( ) ;
657-
658- const commitMessages : string [ ] = [ ] ;
659- for ( const commit of [ ...log . commits . values ( ) ] . sort ( ( a , b ) => a . date . getTime ( ) - b . date . getTime ( ) ) ) {
660- commitMessages . push ( commit . message ?? commit . summary ) ;
661- }
662-
709+ const { diff, logMessages } = compareData ;
663710 const { prompt } = await this . getPrompt (
664711 'generate-create-pullRequest' ,
665712 model ,
666713 {
667- diff : diff . contents ,
668- data : commitMessages . join ( '\n' ) ,
714+ diff : diff ,
715+ data : logMessages ,
669716 context : options ?. context ,
670717 instructions : configuration . get ( 'ai.generateCreatePullRequest.customInstructions' ) ,
671718 } ,
0 commit comments