@@ -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 ,
@@ -636,8 +636,12 @@ export class GitService extends TypedEventEmitter<GitServiceEvents> {
636636 draft ?: boolean ,
637637 ) : Promise < CreatePrOutput > {
638638 const args = [ "pr" , "create" ] ;
639- if ( title ) args . push ( "--title" , title ) ;
640- if ( body ) args . push ( "--body" , body ) ;
639+ if ( title ) {
640+ args . push ( "--title" , title ) ;
641+ args . push ( "--body" , body || "" ) ;
642+ } else {
643+ args . push ( "--fill" ) ;
644+ }
641645 if ( draft ) args . push ( "--draft" ) ;
642646
643647 const result = await execGh ( args , { cwd : directoryPath } ) ;
@@ -909,30 +913,27 @@ ${truncatedDiff}`;
909913 ] ) ;
910914
911915 const head = currentBranch ?? undefined ;
912- const [ commits , branchFiles , uncommittedFiles ] = await Promise . all ( [
916+ const [ branchDiff , stagedDiff , unstagedDiff , commits ] = await Promise . all ( [
917+ getDiffAgainstRemote ( directoryPath , defaultBranch ) ,
918+ getStagedDiff ( directoryPath ) ,
919+ getUnstagedDiff ( directoryPath ) ,
913920 getCommitsBetweenBranches ( directoryPath , defaultBranch , head , 30 ) ,
914- getChangedFilesBetweenBranches ( directoryPath , defaultBranch , head ) ,
915- this . getChangedFilesHead ( directoryPath ) ,
916921 ] ) ;
917922
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 ) {
923+ const uncommittedDiff = [ stagedDiff , unstagedDiff ]
924+ . filter ( Boolean )
925+ . join ( "\n" ) ;
926+ const parts = [ branchDiff , uncommittedDiff ] . filter ( Boolean ) ;
927+ const fullDiff = parts . join ( "\n" ) ;
928+ if ( commits . length === 0 && ! fullDiff ) {
928929 return { title : "" , body : "" } ;
929930 }
930-
931931 const commitsSummary = commits . map ( ( c ) => `- ${ c . message } ` ) . join ( "\n" ) ;
932-
933- const filesSummary = changedFiles
934- . map ( ( f ) => `${ f . status } : ${ f . path } ` )
935- . join ( "\n" ) ;
932+ const truncatedDiff = fullDiff
933+ ? fullDiff . length > MAX_DIFF_LENGTH
934+ ? `${ fullDiff . slice ( 0 , MAX_DIFF_LENGTH ) } \n... (diff truncated)`
935+ : fullDiff
936+ : "" ;
936937
937938 const templateHint = prTemplate . template
938939 ? `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 +960,7 @@ Rules for the body:
959960- Include a "What changed?" section with bullet points describing the key changes
960961- Be thorough but concise
961962- Use markdown formatting
963+ - Only describe changes that are actually in the diff — do not invent or assume changes
962964${ templateHint }
963965
964966Do not include any explanation outside the TITLE and BODY sections.` ;
@@ -970,12 +972,12 @@ Branch: ${currentBranch ?? "unknown"} -> ${defaultBranch}
970972Commits in this PR:
971973${ commitsSummary || "(no commits yet - changes are uncommitted)" }
972974
973- Changed files :
974- ${ filesSummary || "(no file changes detected )" } `;
975+ Diff :
976+ ${ truncatedDiff || "(no diff available )" } `;
975977
976978 log . debug ( "Generating PR title and body" , {
977979 commitCount : commits . length ,
978- fileCount : changedFiles . length ,
980+ diffLength : fullDiff . length ,
979981 hasTemplate : ! ! prTemplate . template ,
980982 } ) ;
981983
0 commit comments