Skip to content

Commit cb79cfb

Browse files
only21milclaudemaria-rcks
authored
fix(server): report a created PR as created when its lookup fails (#23242)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent cd04747 commit cb79cfb

2 files changed

Lines changed: 59 additions & 1 deletion

File tree

‎apps/server/src/git/GitManager.test.ts‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3091,6 +3091,56 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
30913091
}),
30923092
);
30933093

3094+
it.effect("create_pr reports a created PR when the lookup after creation fails", () =>
3095+
Effect.gen(function* () {
3096+
const repoDir = yield* makeTempDir("t3code-git-manager-");
3097+
yield* initRepo(repoDir);
3098+
yield* runGit(repoDir, ["checkout", "-b", "feature/lookup-after-create"]);
3099+
const remoteDir = yield* createBareRemote();
3100+
yield* runGit(repoDir, ["remote", "add", "origin", remoteDir]);
3101+
NodeFS.writeFileSync(NodePath.join(repoDir, "lookup.txt"), "lookup\n");
3102+
yield* runGit(repoDir, ["add", "lookup.txt"]);
3103+
yield* runGit(repoDir, ["commit", "-m", "Lookup after create"]);
3104+
yield* runGit(repoDir, ["push", "-u", "origin", "feature/lookup-after-create"]);
3105+
3106+
const { service: github } = createFakeSourceControlProvider();
3107+
let created = false;
3108+
const { manager } = yield* makeManager({
3109+
sourceControlProvider: {
3110+
...github,
3111+
createChangeRequest: (input) =>
3112+
github.createChangeRequest(input).pipe(
3113+
Effect.tap(() =>
3114+
Effect.sync(() => {
3115+
created = true;
3116+
}),
3117+
),
3118+
),
3119+
listChangeRequests: (input) =>
3120+
created
3121+
? Effect.fail(
3122+
new SourceControlProviderFailure({
3123+
provider: github.kind,
3124+
operation: "listChangeRequests",
3125+
cwd: input.cwd,
3126+
detail: "GitHub API rate limit exceeded.",
3127+
}),
3128+
)
3129+
: github.listChangeRequests(input),
3130+
},
3131+
});
3132+
3133+
const result = yield* runStackedAction(manager, { cwd: repoDir, action: "create_pr" });
3134+
3135+
expect(created).toBe(true);
3136+
expect(result.pr).toMatchObject({
3137+
status: "created",
3138+
headBranch: "feature/lookup-after-create",
3139+
});
3140+
expect(result.pr.url).toBeUndefined();
3141+
}),
3142+
);
3143+
30943144
it.effect("returns existing PR metadata for commit/push/pr action", () =>
30953145
Effect.gen(function* () {
30963146
const repoDir = yield* makeTempDir("t3code-git-manager-");

‎apps/server/src/git/GitManager.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2339,7 +2339,15 @@ export const make = Effect.gen(function* () {
23392339
})
23402340
.pipe(Effect.ensuring(fileSystem.remove(bodyFile).pipe(Effect.ignore)));
23412341

2342-
const created = yield* findOpenPr(cwd, headContext);
2342+
// The PR already exists at this point, so a failed lookup only loses its metadata.
2343+
const created = yield* findOpenPr(cwd, headContext).pipe(
2344+
Effect.catch((error) =>
2345+
Effect.logWarning("GitManager.runPrStep lookup after create failed", {
2346+
provider: provider.kind,
2347+
errorTag: error._tag,
2348+
}).pipe(Effect.as(null)),
2349+
),
2350+
);
23432351
if (!created) {
23442352
return {
23452353
status: "created" as const,

0 commit comments

Comments
 (0)