The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
fix(server): pull_request_create opens a draft PR as a draft on GitHub and Azure (#39772)
Julius Marminge committed
Nov 20, 2026 at 07:29 UTC
f08272f965525e21ace4af1eddd308cb3d3d6de6
9 files changed
+72
-4
apps/server/src/git/GitManager.test.ts
+31
-1
@@ -84,6 +84,8 @@ interface FakeProviderScenario {
84
};
85
/** The kind the fake host reports itself as. */
86
kind?: string;
87
+ /** False for a host that opens every change request ready for review. */
88
+ createsDraftChangeRequests?: boolean;
89
/** Answers to successive change request listings, whatever their head selector. */
90
prListSequence?: ReadonlyArray<ReadonlyArray<FakeChangeRequest>>;
91
prListByHeadSelector?: Record<string, ReadonlyArray<FakeChangeRequest>>;
@@ -119,6 +121,7 @@ type FakeProviderCall =
121
readonly baseRefName: string;
122
readonly headSelector: string;
123
readonly title: string;
124
+ readonly draft: unknown;
125
}
126
| { readonly operation: "getChangeRequest"; readonly reference: string }
127
| {
@@ -477,6 +480,7 @@ function createFakeSourceControlProvider(scenario: FakeProviderScenario = {}): {
480
return {
481
service: {
482
kind,
483
+ createsDraftChangeRequests: scenario.createsDraftChangeRequests ?? true,
484
...headBranchProbe,
485
listChangeRequests: (input) =>
486
record(input.cwd, {
@@ -509,6 +513,7 @@ function createFakeSourceControlProvider(scenario: FakeProviderScenario = {}): {
513
baseRefName: input.baseRefName,
514
headSelector: input.headSelector,
515
title: input.title,
516
+ draft: "draft" in input ? input.draft : undefined,
517
}),
518
getDefaultBranch: (input) =>
519
record(input.cwd, { operation: "getDefaultBranch" }).pipe(
@@ -4488,7 +4493,9 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
4493
4494
// A draft of a PR the host does not list yet fails, so a retry drafts it.
4495
yield* runGit(repoDir, ["push"]);
4491
- const unlisted = yield* makeManager({ providerScenario: { prListSequence: [[], []] } });
4496
+ const unlisted = yield* makeManager({
4497
+ providerScenario: { prListSequence: [[], []], createsDraftChangeRequests: false },
4498
+ });
4499
const notListed = yield* Effect.flip(
4500
unlisted.manager.createPullRequest({
4501
cwd: repoDir,
@@ -4500,6 +4507,29 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
4507
);
4508
expect(notListed.message).toContain("does not list it yet");
4509
expect(created(unlisted.providerCalls)).toHaveLength(1);
4510
+
4511
+ // A new PR asked for as a draft is opened as one, never ready first.
4512
+ const newActions: Array<PullRequestActionInput> = [];
4513
+ const fresh = yield* makeManager({
4514
+ providerScenario: { prListSequence: [[], [open]] },
4515
+ pullRequests: {
4516
+ summary: () => Effect.succeed({ isDraft: false } as never),
4517
+ runAction: (action) => Effect.sync(() => void newActions.push(action)),
4518
+ },
4519
+ });
4520
+ yield* fresh.manager.createPullRequest({
4521
+ cwd: repoDir,
4522
+ projectId: ProjectId.make("project-1"),
4523
+ title: "Feature",
4524
+ body: "Body",
4525
+ draft: true,
4526
+ });
4527
+ expect(
4528
+ fresh.providerCalls.flatMap((call) =>
4529
+ call.operation === "createChangeRequest" ? [call.draft] : [],
4530
+ ),
4531
+ ).toEqual([true]);
4532
+ expect(newActions).toEqual([]);
4533
}),
4534
);
4535
apps/server/src/git/GitManager.ts
+8
-1
@@ -2465,6 +2465,7 @@ export const make = Effect.gen(function* () {
2465
emit: GitActionProgressEmitter,
2466
pushRemoteRef: { readonly remoteName: string; readonly upstreamRef: string } | undefined,
2467
requestedBase: string | undefined,
2468
+ draft: boolean,
2469
content: (input: {
2470
readonly provider: SourceControlProvider.SourceControlProvider["Service"];
2471
readonly baseBranch: string;
@@ -2563,6 +2564,7 @@ export const make = Effect.gen(function* () {
2564
: {}),
2565
title: generated.title,
2566
bodyFile,
2567
+ ...(draft ? { draft: true } : {}),
2568
})
2569
.pipe(Effect.ensuring(fileSystem.remove(bodyFile).pipe(Effect.ignore)));
2570
@@ -2608,6 +2610,7 @@ export const make = Effect.gen(function* () {
2610
emit,
2611
pushRemoteRef,
2612
undefined,
2613
+ false,
2614
({ provider, baseBranch, baseRef, headBranch }) =>
2615
Effect.gen(function* () {
2616
const terms = sourceControlDefinitions.get(provider.kind).changeRequest;
@@ -2652,11 +2655,15 @@ export const make = Effect.gen(function* () {
2655
() => Effect.void,
2656
undefined,
2657
input.baseBranch,
2658
+ input.draft === true,
2659
() => Effect.succeed({ title: input.title, body: input.body }),
2660
);
2661
// The thread's branch PR comes from status, which may hold the lookup from before.
2662
if (result.status === "created") yield* invalidateStatus(input.cwd);
2659
- if (input.draft === true && !(yield* draftOpened(input, result))) {
2663
+ const openedAsDraft =
2664
+ result.status === "created" &&
2665
+ (yield* sourceControlProvider(input.cwd)).createsDraftChangeRequests === true;
2666
+ if (input.draft === true && !openedAsDraft && !(yield* draftOpened(input, result))) {
2667
// A retry finds the open PR and drafts it then.
2668
return yield* new GitManagerError({
2669
operation: "createPullRequest",
packages/source-control-azure-devops/src/server/AzureDevOpsCli.test.ts
+11
@@ -314,6 +314,17 @@ describe("AzureDevOpsCli.layer", () => {
314
// az expands a separate `@file` value a second time, so a body of `@notes.txt` read notes.txt.
315
expect(mockRun.mock.calls.at(-1)?.[0].args).toContain("--description=@/tmp/body.md");
316
}
317
+
318
+ mockRun.mockReturnValueOnce(Effect.succeed(processOutput("{}")));
319
+ yield* az.createPullRequest({
320
+ cwd: "/somewhere",
321
+ baseBranch: "main",
322
+ headSelector: "feature",
323
+ title: "Draft",
324
+ bodyFile: "/tmp/body.md",
325
+ draft: true,
326
+ });
327
+ expect(mockRun.mock.calls.at(-1)?.[0].args.join(" ")).toContain("--draft true");
328
}).pipe(Effect.provide(layer)),
329
);
330
packages/source-control-azure-devops/src/server/AzureDevOpsCli.ts
+2
@@ -261,6 +261,7 @@ export class AzureDevOpsCli extends Context.Service<
261
readonly target?: SourceControlProvider.SourceControlRefSelector;
262
readonly title: string;
263
readonly bodyFile: string;
264
+ readonly draft?: boolean;
265
readonly remoteUrl?: string;
266
}) => Effect.Effect<void, AzureDevOpsCliError>;
267
@@ -746,6 +747,7 @@ export const make = Effect.gen(function* () {
747
title.arg,
748
// Joined: az expands a separate `@file` value again, so a body of `@path` read that file.
749
`--description=@${input.bodyFile}`,
750
+ ...(input.draft === true ? ["--draft", "true"] : []),
751
],
752
...(title.stdin === undefined ? {} : { stdin: title.stdin }),
753
}).pipe(Effect.asVoid);
packages/source-control-azure-devops/src/server/AzureDevOpsSourceControlProvider.ts
+2
@@ -178,6 +178,7 @@ export const make = Effect.gen(function* () {
178
);
179
},
180
),
181
+ createsDraftChangeRequests: true,
182
createChangeRequest: Effect.fn("AzureDevOpsSourceControlProvider.createChangeRequest")(
183
function (input) {
184
const source = SourceControlProvider.sourceControlRefFromInput(input);
@@ -191,6 +192,7 @@ export const make = Effect.gen(function* () {
192
...(input.target !== undefined ? { target: input.target } : {}),
193
title: input.title,
194
bodyFile: input.bodyFile,
195
+ ...(input.draft === true ? { draft: true } : {}),
196
})
197
.pipe(
198
Effect.mapError(
packages/source-control-core/src/server/SourceControlProvider.ts
+4
@@ -171,6 +171,8 @@ export class SourceControlProvider extends Context.Service<
171
readonly branch: string;
172
readonly baseBranch: string;
173
}) => Effect.Effect<void>;
174
+ /** True when `createChangeRequest` opens the change request as a draft when asked. */
175
+ readonly createsDraftChangeRequests?: boolean;
176
readonly listChangeRequests: (input: {
177
readonly cwd: string;
178
readonly context?: SourceControlProviderContext;
@@ -193,6 +195,8 @@ export class SourceControlProvider extends Context.Service<
195
readonly headSelector: string;
196
readonly title: string;
197
readonly bodyFile: string;
198
+ /** Honored only by a provider with `createsDraftChangeRequests`. */
199
+ readonly draft?: boolean;
200
}) => Effect.Effect<void, SourceControlProviderError>;
201
readonly getRepositoryCloneUrls: (input: {
202
readonly cwd: string;
packages/source-control-cursor-origin/src/server/OriginSourceControlProvider.ts
+3
-2
@@ -193,10 +193,11 @@ export const make = Effect.gen(function* () {
193
effect.pipe(mapError("getChangeRequest", input.cwd, { reference: input.reference })),
194
),
195
196
+ createsDraftChangeRequests: true,
197
createChangeRequest: Effect.fn("OriginSourceControlProvider.createChangeRequest")(
198
function* (input) {
199
const repository = input.target?.repository ?? (yield* cli.resolveRepository(input));
199
- // Origin creates drafts unless told otherwise; T3 asks for draft explicitly elsewhere.
200
+ // Origin creates drafts unless told otherwise, so `draft` is always sent.
201
yield* cli.api(
202
{
203
cwd: input.cwd,
@@ -208,7 +209,7 @@ export const make = Effect.gen(function* () {
209
body: yield* fs.readFileString(input.bodyFile),
210
head: SourceControlProvider.sourceBranch(input),
211
base: input.target?.refName ?? input.baseRefName,
211
- draft: false,
212
+ draft: input.draft === true,
213
},
214
},
215
Schema.Unknown,
packages/source-control-github/src/server/GitHubSourceControlProvider.test.ts
+9
@@ -612,6 +612,15 @@ describe("GitHubSourceControlProvider writes", () => {
612
body: "Body",
613
maintainer_can_modify: true,
614
});
615
+ yield* gh.createChangeRequest({
616
+ cwd: "/repo",
617
+ baseRefName: "main",
618
+ headSelector: "me:feature",
619
+ title: "Title",
620
+ bodyFile,
621
+ draft: true,
622
+ });
623
+ assert.strictEqual((requests[1]!.body as { draft?: unknown }).draft, true);
624
}).pipe(Effect.provide(Layer.merge(layer, NodeServices.layer)));
625
});
626
packages/source-control-github/src/server/GitHubSourceControlProvider.ts
+2
@@ -1101,6 +1101,7 @@ export const make = Effect.gen(function* () {
1101
),
1102
);
1103
}),
1104
+ createsDraftChangeRequests: true,
1105
createChangeRequest: Effect.fn("GitHubSourceControlProvider.createChangeRequest")(
1106
function* (input) {
1107
const locator = yield* resolveRepository(input);
@@ -1124,6 +1125,7 @@ export const make = Effect.gen(function* () {
1125
title: input.title,
1126
body,
1127
maintainer_can_modify: true,
1128
+ ...(input.draft === true ? { draft: true } : {}),
1129
},
1130
});
1131
},