Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions apps/server/src/git/Layers/GitManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,16 @@ function createGitHubCliWithFakeGh(scenario: FakeGhScenario = {}): {
});
}

if (args[0] === "pr" && args[1] === "edit") {
return Effect.succeed({
stdout: "",
stderr: "",
code: 0,
signal: null,
timedOut: false,
});
}

if (args[0] === "repo" && args[1] === "view") {
const repository = args[2];
if (typeof repository === "string" && args.includes("nameWithOwner,url,sshUrl")) {
Expand Down Expand Up @@ -464,6 +474,17 @@ function createGitHubCliWithFakeGh(scenario: FakeGhScenario = {}): {
cwd: input.cwd,
args: ["pr", "checkout", input.reference, ...(input.force ? ["--force"] : [])],
}).pipe(Effect.asVoid),
editPullRequest: (input) =>
execute({
cwd: input.cwd,
args: [
"pr",
"edit",
String(input.number),
...(input.title ? ["--title", input.title] : []),
...(input.bodyFile ? ["--body-file", input.bodyFile] : []),
],
}).pipe(Effect.asVoid),
},
ghCalls,
};
Expand Down
33 changes: 22 additions & 11 deletions apps/server/src/git/Layers/GitManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -889,19 +889,9 @@ export const makeGitManager = Effect.fn("makeGitManager")(function* () {
upstreamRef: details.upstreamRef,
});

const baseBranch = yield* resolveBaseBranch(cwd, branch, details.upstreamRef, headContext);
const existing = yield* findOpenPr(cwd, headContext.headSelectors);
if (existing) {
return {
status: "opened_existing" as const,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Content generated against wrong base for retargeted PRs

Medium Severity

When an existing PR is found, baseBranch from resolveBaseBranch is used to compute the range context and generate the new title/body, but the existing PR on GitHub may target a different branch (existing.baseRefName). The readRangeContext diff is computed as baseBranch..HEAD using the locally-resolved base, while the PR's "Files changed" tab on GitHub shows the diff against existing.baseRefName. If someone retargets the PR on GitHub (or local config changes), the regenerated description would describe changes against the wrong base branch. Using existing.baseRefName for content generation when an existing PR is found would keep the description consistent with what GitHub displays.

Additional Locations (1)
Fix in Cursor Fix in Web

url: existing.url,
number: existing.number,
baseBranch: existing.baseRefName,
headBranch: existing.headRefName,
title: existing.title,
};
}

const baseBranch = yield* resolveBaseBranch(cwd, branch, details.upstreamRef, headContext);
const rangeContext = yield* gitCore.readRangeContext(cwd, baseBranch);

const generated = yield* textGeneration.generatePrContent({
Expand All @@ -922,6 +912,27 @@ export const makeGitManager = Effect.fn("makeGitManager")(function* () {
gitManagerError("runPrStep", "Failed to write pull request body temp file.", cause),
),
);

if (existing) {
yield* gitHubCli
.editPullRequest({
cwd,
number: existing.number,
title: generated.title,
bodyFile,
})
.pipe(Effect.ensuring(fileSystem.remove(bodyFile).pipe(Effect.catch(() => Effect.void))));

return {
status: "opened_existing" as const,
url: existing.url,
number: existing.number,
baseBranch: existing.baseRefName,
headBranch: existing.headRefName,
title: generated.title,
};
}

yield* gitHubCli
.createPullRequest({
cwd,
Expand Down
Loading