Skip to content

Commit a27b8da

Browse files
committed
send full diff to PR title/body generator
1 parent 12fe24e commit a27b8da

2 files changed

Lines changed: 33 additions & 22 deletions

File tree

apps/code/src/main/services/git/service.ts

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import path from "node:path";
33
import { execGh } from "@posthog/git/gh";
44
import {
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
964962
Do not include any explanation outside the TITLE and BODY sections.`;
@@ -970,12 +968,12 @@ Branch: ${currentBranch ?? "unknown"} -> ${defaultBranch}
970968
Commits 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

packages/git/src/queries.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,19 @@ export async function getUnstagedDiff(
935935
});
936936
}
937937

938+
export async function getDiffAgainstRemote(
939+
baseDir: string,
940+
baseBranch: string,
941+
options?: CreateGitClientOptions,
942+
): Promise<string> {
943+
const manager = getGitOperationManager();
944+
return manager.executeRead(
945+
baseDir,
946+
(git) => git.diff([`origin/${baseBranch}...HEAD`]),
947+
{ signal: options?.abortSignal },
948+
);
949+
}
950+
938951
export async function isCommitOnRemote(
939952
baseDir: string,
940953
commit: string,

0 commit comments

Comments
 (0)