@@ -3,12 +3,12 @@ import path from "node:path";
33import { execGh } from "@posthog/git/gh" ;
44import {
55 getAllBranches ,
6- getChangedFilesBetweenBranches ,
76 getChangedFilesDetailed ,
87 getCommitConventions ,
98 getCommitsBetweenBranches ,
109 getCurrentBranch ,
1110 getDefaultBranch ,
11+ getDiffAgainstRemote ,
1212 getDiffStats ,
1313 getFileAtHead ,
1414 getLatestCommit ,
@@ -909,30 +909,27 @@ ${truncatedDiff}`;
909909 ] ) ;
910910
911911 const head = currentBranch ?? undefined ;
912- const [ commits , branchFiles , uncommittedFiles ] = await Promise . all ( [
912+ const [ branchDiff , stagedDiff , unstagedDiff , commits ] = await Promise . all ( [
913+ getDiffAgainstRemote ( directoryPath , defaultBranch ) ,
914+ getStagedDiff ( directoryPath ) ,
915+ getUnstagedDiff ( directoryPath ) ,
913916 getCommitsBetweenBranches ( directoryPath , defaultBranch , head , 30 ) ,
914- getChangedFilesBetweenBranches ( directoryPath , defaultBranch , head ) ,
915- this . getChangedFilesHead ( directoryPath ) ,
916917 ] ) ;
917918
918- const seenPaths = new Set ( branchFiles . map ( ( f ) => f . path ) ) ;
919- const changedFiles = [ ...branchFiles ] ;
920- for ( const file of uncommittedFiles ) {
921- if ( ! seenPaths . has ( file . path ) ) {
922- changedFiles . push ( file ) ;
923- seenPaths . add ( file . path ) ;
924- }
925- }
926-
927- if ( commits . length === 0 && changedFiles . length === 0 ) {
919+ const uncommittedDiff = [ stagedDiff , unstagedDiff ]
920+ . filter ( Boolean )
921+ . join ( "\n" ) ;
922+ const parts = [ branchDiff , uncommittedDiff ] . filter ( Boolean ) ;
923+ const fullDiff = parts . join ( "\n" ) ;
924+ if ( commits . length === 0 && ! fullDiff ) {
928925 return { title : "" , body : "" } ;
929926 }
930-
931927 const commitsSummary = commits . map ( ( c ) => `- ${ c . message } ` ) . join ( "\n" ) ;
932-
933- const filesSummary = changedFiles
934- . map ( ( f ) => `${ f . status } : ${ f . path } ` )
935- . join ( "\n" ) ;
928+ const truncatedDiff = fullDiff
929+ ? fullDiff . length > MAX_DIFF_LENGTH
930+ ? `${ fullDiff . slice ( 0 , MAX_DIFF_LENGTH ) } \n... (diff truncated)`
931+ : fullDiff
932+ : "" ;
936933
937934 const templateHint = prTemplate . template
938935 ? `The repository has a PR template. Use it as a guide for structure but adapt the content to match the actual changes:\n${ prTemplate . template . slice (
@@ -959,6 +956,7 @@ Rules for the body:
959956- Include a "What changed?" section with bullet points describing the key changes
960957- Be thorough but concise
961958- Use markdown formatting
959+ - Only describe changes that are actually in the diff — do not invent or assume changes
962960${ templateHint }
963961
964962Do not include any explanation outside the TITLE and BODY sections.` ;
@@ -970,12 +968,12 @@ Branch: ${currentBranch ?? "unknown"} -> ${defaultBranch}
970968Commits in this PR:
971969${ commitsSummary || "(no commits yet - changes are uncommitted)" }
972970
973- Changed files :
974- ${ filesSummary || "(no file changes detected )" } `;
971+ Diff :
972+ ${ truncatedDiff || "(no diff available )" } `;
975973
976974 log . debug ( "Generating PR title and body" , {
977975 commitCount : commits . length ,
978- fileCount : changedFiles . length ,
976+ diffLength : fullDiff . length ,
979977 hasTemplate : ! ! prTemplate . template ,
980978 } ) ;
981979
0 commit comments