Skip to content

Commit 91ca63c

Browse files
TonybynMp4claude
andcommitted
fix(gitlab): delete the revert branch when the request is interrupted
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent bea8fa0 commit 91ca63c

2 files changed

Lines changed: 19 additions & 15 deletions

File tree

‎packages/source-control-gitlab/src/server/GitLabPullRequestCli.test.ts‎

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -522,20 +522,23 @@ layer("GitLabPullRequestCli.layer", (it) => {
522522
);
523523

524524
it.effect.each([
525-
["the revert conflicts", "/revert"],
526-
["opening the merge request fails", "/merge_requests"],
527-
] as const)("deletes the revert branch when %s", ([, failingPath]) =>
525+
["the revert conflicts", "/revert", "Failure"],
526+
["opening the merge request fails", "/merge_requests", "Failure"],
527+
["the request is interrupted", "/revert", "Interrupt"],
528+
] as const)("deletes the revert branch when %s", ([, failingPath, outcome]) =>
528529
Effect.gen(function* () {
529530
mockedExecute.mockImplementation(({ args, cwd }) =>
530531
args[1]?.endsWith(failingPath) && args.includes("POST")
531-
? Effect.fail(
532-
new GitLabCli.GitLabCliCommandError({
533-
operation: "execute",
534-
command: "glab",
535-
cwd,
536-
cause: new Error("GitLab rejected the write"),
537-
}),
538-
)
532+
? outcome === "Interrupt"
533+
? Effect.interrupt
534+
: Effect.fail(
535+
new GitLabCli.GitLabCliCommandError({
536+
operation: "execute",
537+
command: "glab",
538+
cwd,
539+
cause: new Error("GitLab rejected the write"),
540+
}),
541+
)
539542
: Effect.succeed(
540543
output(
541544
mergeRequestJson({
@@ -548,7 +551,7 @@ layer("GitLabPullRequestCli.layer", (it) => {
548551
);
549552
const cli = yield* GitLabPullRequestCli.GitLabPullRequestCli;
550553

551-
const result = yield* Effect.result(
554+
const exit = yield* Effect.exit(
552555
cli.runMergeRequestAction({
553556
cwd: "/w",
554557
repository: "acme/web",
@@ -557,7 +560,7 @@ layer("GitLabPullRequestCli.layer", (it) => {
557560
}),
558561
);
559562

560-
expect(result).toMatchObject({ _tag: "Failure", failure: { _tag: "GitLabCliCommandError" } });
563+
expect(exit._tag).toBe("Failure");
561564
expect(mockedExecute.mock.calls.at(-1)?.[0].args.slice(1, 4)).toEqual([
562565
"projects/acme%2Fweb/repository/branches/revert-abc12345",
563566
"--method",

‎packages/source-control-gitlab/src/server/GitLabPullRequestCli.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,8 +1021,9 @@ export const make = Effect.gen(function* () {
10211021
remove_source_branch: true,
10221022
}),
10231023
).pipe(
1024-
// Leaving the branch behind would make every retry fail on creating it again.
1025-
Effect.tapError(() =>
1024+
// Leaving the branch behind would make every retry fail on creating it again. Runs on
1025+
// interruption too, which a cancelled request or a dropped socket causes.
1026+
Effect.onError(() =>
10261027
api({
10271028
cwd: input.cwd,
10281029
host: input.host,

0 commit comments

Comments
 (0)