diff --git a/apps/server/src/git/Layers/GitHubCli.ts b/apps/server/src/git/Layers/GitHubCli.ts index 80ce43659e..d2d56bafa7 100644 --- a/apps/server/src/git/Layers/GitHubCli.ts +++ b/apps/server/src/git/Layers/GitHubCli.ts @@ -272,6 +272,17 @@ const makeGitHubCli = Effect.sync(() => { 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), } satisfies GitHubCliShape; return service; diff --git a/apps/server/src/git/Layers/GitManager.ts b/apps/server/src/git/Layers/GitManager.ts index dc082674b7..64d0ee8952 100644 --- a/apps/server/src/git/Layers/GitManager.ts +++ b/apps/server/src/git/Layers/GitManager.ts @@ -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, - 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({ @@ -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, diff --git a/apps/server/src/git/Services/GitHubCli.ts b/apps/server/src/git/Services/GitHubCli.ts index f10339af47..092e59ed53 100644 --- a/apps/server/src/git/Services/GitHubCli.ts +++ b/apps/server/src/git/Services/GitHubCli.ts @@ -93,6 +93,16 @@ export interface GitHubCliShape { readonly reference: string; readonly force?: boolean; }) => Effect.Effect; + + /** + * Edit an existing pull request's title and/or body. + */ + readonly editPullRequest: (input: { + readonly cwd: string; + readonly number: number; + readonly title?: string; + readonly bodyFile?: string; + }) => Effect.Effect; } /**