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
11 changes: 11 additions & 0 deletions apps/server/src/git/Layers/GitHubCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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,
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
10 changes: 10 additions & 0 deletions apps/server/src/git/Services/GitHubCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ export interface GitHubCliShape {
readonly reference: string;
readonly force?: boolean;
}) => Effect.Effect<void, GitHubCliError>;

/**
* 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<void, GitHubCliError>;
}

/**
Expand Down
Loading