fix(server): generate PR diffs from branch changes (#13170)
This commit is contained in:
1 parent
5821b778fd
commit
f22331240e
2 files changed
+22
-5
No files matched your search
@@ -4071,7 +4071,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("generates PR content against the remote base when the local base is stale", () =>
|
||||
it.effect("generates PR content from branch changes when the remote base advances", () =>
|
||||
Effect.gen(function* () {
|
||||
const repoDir = yield* makeTempDir("t3code-git-manager-");
|
||||
yield* initRepo(repoDir);
|
||||
@@ -4103,7 +4103,15 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
yield* runGit(repoDir, ["push", "-u", "origin", "feature/remote-base"]);
|
||||
yield* runGit(repoDir, ["config", "branch.feature/remote-base.gh-merge-base", "main"]);
|
||||
|
||||
NodeFS.writeFileSync(NodePath.join(peerDir, "later-main.txt"), "unrelated\n");
|
||||
yield* runGit(peerDir, ["add", "later-main.txt"]);
|
||||
yield* runGit(peerDir, ["commit", "-m", "Later main commit"]);
|
||||
yield* runGit(peerDir, ["push", "origin", "main"]);
|
||||
yield* runGit(repoDir, ["fetch", "origin"]);
|
||||
|
||||
let generatedCommitSummary = "";
|
||||
let generatedDiffSummary = "";
|
||||
let generatedDiffPatch = "";
|
||||
const { manager } = yield* makeManager({
|
||||
ghScenario: {
|
||||
prListSequence: ["[]", "[]"],
|
||||
@@ -4111,6 +4119,8 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
textGeneration: {
|
||||
generatePrContent: (input) => {
|
||||
generatedCommitSummary = input.commitSummary;
|
||||
generatedDiffSummary = input.diffSummary;
|
||||
generatedDiffPatch = input.diffPatch;
|
||||
return Effect.succeed({ title: "Feature PR", body: "Feature body" });
|
||||
},
|
||||
},
|
||||
@@ -4124,6 +4134,11 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
expect(result.pr.status).toBe("created");
|
||||
expect(generatedCommitSummary).toContain("Feature commit");
|
||||
expect(generatedCommitSummary).not.toContain("Remote base commit");
|
||||
expect(generatedCommitSummary).not.toContain("Later main commit");
|
||||
expect(generatedDiffSummary).toContain("feature.txt");
|
||||
expect(generatedDiffSummary).not.toContain("later-main.txt");
|
||||
expect(generatedDiffPatch).toContain("feature.txt");
|
||||
expect(generatedDiffPatch).not.toContain("later-main.txt");
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
@@ -2285,13 +2285,15 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
|
||||
const readRangeContext: GitVcsDriver.GitVcsDriver["Service"]["readRangeContext"] = Effect.fn(
|
||||
"readRangeContext",
|
||||
)(function* (cwd, baseRef) {
|
||||
const range = `${baseRef}..HEAD`;
|
||||
const commitRange = `${baseRef}..HEAD`;
|
||||
// PR diffs start at the common ancestor when the base branch has advanced.
|
||||
const diffRange = `${baseRef}...HEAD`;
|
||||
const [commitSummary, diffSummary, diffPatch] = yield* Effect.all(
|
||||
[
|
||||
runGitStdoutWithOptions(
|
||||
"GitVcsDriver.readRangeContext.log",
|
||||
cwd,
|
||||
["log", "--oneline", range],
|
||||
["log", "--oneline", commitRange],
|
||||
{
|
||||
maxOutputBytes: RANGE_COMMIT_SUMMARY_MAX_OUTPUT_BYTES,
|
||||
appendTruncationMarker: true,
|
||||
@@ -2300,7 +2302,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
|
||||
runGitStdoutWithOptions(
|
||||
"GitVcsDriver.readRangeContext.diffStat",
|
||||
cwd,
|
||||
["diff", "--stat", range],
|
||||
["diff", "--stat", diffRange],
|
||||
{
|
||||
maxOutputBytes: RANGE_DIFF_SUMMARY_MAX_OUTPUT_BYTES,
|
||||
appendTruncationMarker: true,
|
||||
@@ -2309,7 +2311,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
|
||||
runGitStdoutWithOptions(
|
||||
"GitVcsDriver.readRangeContext.diffPatch",
|
||||
cwd,
|
||||
["diff", "--no-ext-diff", "--patch", "--minimal", range],
|
||||
["diff", "--no-ext-diff", "--patch", "--minimal", diffRange],
|
||||
{
|
||||
maxOutputBytes: RANGE_DIFF_PATCH_MAX_OUTPUT_BYTES,
|
||||
appendTruncationMarker: true,
|
||||
|
||||
Reference in new issue
Block a user