diff --git a/apps/server/src/git/Layers/GitManager.test.ts b/apps/server/src/git/Layers/GitManager.test.ts index 65735c53ab..4ca13adbe7 100644 --- a/apps/server/src/git/Layers/GitManager.test.ts +++ b/apps/server/src/git/Layers/GitManager.test.ts @@ -574,6 +574,7 @@ function runStackedAction( actionId?: string; commitMessage?: string; featureBranch?: boolean; + prOnlyIfReady?: boolean; filePaths?: readonly string[]; }, options?: Parameters[1], @@ -1136,7 +1137,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => { kind: "run_action", label: "Create PR", action: "commit_push_pr", - forcePushOnlyProgress: true, + prOnlyIfReady: true, isDefaultBranch: false, }, }); @@ -2570,4 +2571,72 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => { ); }), ); + + it.effect("prOnlyIfReady emits only the PR phase when the branch is already pushed", () => + Effect.gen(function* () { + const repoDir = yield* makeTempDir("t3code-git-manager-"); + yield* initRepo(repoDir); + yield* runGit(repoDir, ["checkout", "-b", "feature/pr-only-follow-up"]); + const remoteDir = yield* createBareRemote(); + yield* runGit(repoDir, ["remote", "add", "origin", remoteDir]); + fs.writeFileSync(path.join(repoDir, "pr-only.txt"), "pr only\n"); + yield* runGit(repoDir, ["add", "pr-only.txt"]); + yield* runGit(repoDir, ["commit", "-m", "PR only branch"]); + yield* runGit(repoDir, ["push", "-u", "origin", "feature/pr-only-follow-up"]); + + const { manager } = yield* makeManager({ + ghScenario: { + prListSequence: [ + JSON.stringify([]), + JSON.stringify([ + { + number: 201, + title: "PR only branch", + url: "https://github.com/pingdotgg/codething-mvp/pull/201", + baseRefName: "main", + headRefName: "feature/pr-only-follow-up", + state: "OPEN", + isCrossRepository: false, + }, + ]), + ], + }, + }); + const events: GitActionProgressEvent[] = []; + + const result = yield* runStackedAction( + manager, + { + cwd: repoDir, + action: "commit_push_pr", + prOnlyIfReady: true, + }, + { + actionId: "action-pr-only", + progressReporter: { + publish: (event) => + Effect.sync(() => { + events.push(event); + }), + }, + }, + ); + + expect(result.commit.status).toBe("skipped_no_changes"); + expect(result.push.status).toBe("skipped_not_requested"); + expect(result.pr.status).toBe("created"); + expect( + events.filter( + (event): event is Extract => + event.kind === "phase_started", + ), + ).toEqual([ + expect.objectContaining({ + kind: "phase_started", + phase: "pr", + label: "Creating PR...", + }), + ]); + }), + ); }); diff --git a/apps/server/src/git/Layers/GitManager.ts b/apps/server/src/git/Layers/GitManager.ts index 95ca68cf41..e6fda25b8a 100644 --- a/apps/server/src/git/Layers/GitManager.ts +++ b/apps/server/src/git/Layers/GitManager.ts @@ -912,7 +912,7 @@ export const makeGitManager = Effect.fn("makeGitManager")(function* () { kind: "run_action" as const, label: "Create PR", action: "commit_push_pr" as const, - forcePushOnlyProgress: true, + prOnlyIfReady: true, isDefaultBranch: false, } : { @@ -1420,27 +1420,35 @@ export const makeGitManager = Effect.fn("makeGitManager")(function* () { const runStackedAction: GitManagerShape["runStackedAction"] = Effect.fn("runStackedAction")( function* (input, options) { const progress = createProgressEmitter(input, options); - const phases: GitActionProgressPhase[] = [ - ...(input.featureBranch ? (["branch"] as const) : []), - "commit", - ...(input.action !== "commit" ? (["push"] as const) : []), - ...(input.action === "commit_push_pr" ? (["pr"] as const) : []), - ]; const currentPhase = yield* Ref.make>(Option.none()); const runAction = Effect.fn("runStackedAction.runAction")(function* (): Effect.fn.Return< GitRunStackedActionResult, GitManagerServiceError > { + const initialStatus = yield* gitCore.statusDetails(input.cwd); + const prOnlyIfReady = + input.action === "commit_push_pr" && + input.prOnlyIfReady === true && + !input.featureBranch && + initialStatus.branch !== null && + !initialStatus.hasWorkingTreeChanges && + initialStatus.hasUpstream && + initialStatus.aheadCount === 0; + const wantsPush = input.action !== "commit" && !prOnlyIfReady; + const wantsPr = input.action === "commit_push_pr"; + const phases: GitActionProgressPhase[] = [ + ...(input.featureBranch ? (["branch"] as const) : []), + ...(prOnlyIfReady ? [] : (["commit"] as const)), + ...(wantsPush ? (["push"] as const) : []), + ...(wantsPr ? (["pr"] as const) : []), + ]; + yield* progress.emit({ kind: "action_started", phases, }); - const wantsPush = input.action !== "commit"; - const wantsPr = input.action === "commit_push_pr"; - - const initialStatus = yield* gitCore.statusDetails(input.cwd); if (!input.featureBranch && wantsPush && !initialStatus.branch) { return yield* gitManagerError("runStackedAction", "Cannot push from detached HEAD."); } @@ -1485,18 +1493,23 @@ export const makeGitManager = Effect.fn("makeGitManager")(function* () { const currentBranch = branchStep.name ?? initialStatus.branch; - yield* Ref.set(currentPhase, Option.some("commit")); - const commit = yield* runCommitStep( - modelSelection, - input.cwd, - input.action, - currentBranch, - commitMessageForStep, - preResolvedCommitSuggestion, - input.filePaths, - options?.progressReporter, - progress.actionId, - ); + const commit = prOnlyIfReady + ? { status: "skipped_no_changes" as const } + : yield* Ref.set(currentPhase, Option.some("commit")).pipe( + Effect.flatMap(() => + runCommitStep( + modelSelection, + input.cwd, + input.action, + currentBranch, + commitMessageForStep, + preResolvedCommitSuggestion, + input.filePaths, + options?.progressReporter, + progress.actionId, + ), + ), + ); const push = wantsPush ? yield* progress diff --git a/apps/web/src/components/GitActionsControl.logic.test.ts b/apps/web/src/components/GitActionsControl.logic.test.ts index d15414344c..4399f13040 100644 --- a/apps/web/src/components/GitActionsControl.logic.test.ts +++ b/apps/web/src/components/GitActionsControl.logic.test.ts @@ -878,6 +878,16 @@ describe("buildGitActionProgressStages", () => { assert.deepEqual(stages, ["Pushing to origin/feature/test...", "Creating PR..."]); }); + it("shows only PR progress when the follow-up action is already PR-ready", () => { + const stages = buildGitActionProgressStages({ + action: "commit_push_pr", + hasCustomCommitMessage: false, + hasWorkingTreeChanges: false, + prOnlyIfReady: true, + }); + assert.deepEqual(stages, ["Creating PR..."]); + }); + it("includes commit stages for commit+push when working tree is dirty", () => { const stages = buildGitActionProgressStages({ action: "commit_push", diff --git a/apps/web/src/components/GitActionsControl.logic.ts b/apps/web/src/components/GitActionsControl.logic.ts index 4addf687e5..f82cef615b 100644 --- a/apps/web/src/components/GitActionsControl.logic.ts +++ b/apps/web/src/components/GitActionsControl.logic.ts @@ -40,7 +40,12 @@ export function buildGitActionProgressStages(input: { forcePushOnly?: boolean; pushTarget?: string; featureBranch?: boolean; + prOnlyIfReady?: boolean; }): string[] { + if (input.action === "commit_push_pr" && input.prOnlyIfReady) { + return ["Creating PR..."]; + } + const branchStages = input.featureBranch ? ["Preparing feature branch..."] : []; const shouldIncludeCommitStages = !input.forcePushOnly && (input.action === "commit" || input.hasWorkingTreeChanges); diff --git a/apps/web/src/components/GitActionsControl.tsx b/apps/web/src/components/GitActionsControl.tsx index 8896d69bbb..0c3745da00 100644 --- a/apps/web/src/components/GitActionsControl.tsx +++ b/apps/web/src/components/GitActionsControl.tsx @@ -90,6 +90,7 @@ interface RunGitActionWithToastInput { skipDefaultBranchPrompt?: boolean; statusOverride?: GitStatusResult | null; featureBranch?: boolean; + prOnlyIfReady?: boolean; isDefaultBranchOverride?: boolean; progressToastId?: GitActionToastId; filePaths?: string[]; @@ -411,6 +412,7 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions skipDefaultBranchPrompt = false, statusOverride, featureBranch = false, + prOnlyIfReady = false, isDefaultBranchOverride, progressToastId, filePaths, @@ -448,6 +450,7 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions hasWorkingTreeChanges: !!actionStatus?.hasWorkingTreeChanges, forcePushOnly: forcePushOnlyProgress, featureBranch, + prOnlyIfReady, }); const actionId = randomUUID(); const resolvedProgressToastId = @@ -542,6 +545,7 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions action, ...(commitMessage ? { commitMessage } : {}), ...(featureBranch ? { featureBranch } : {}), + ...(prOnlyIfReady ? { prOnlyIfReady } : {}), ...(filePaths ? { filePaths } : {}), onProgress: applyProgressEvent, }); @@ -569,6 +573,9 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions ...(toastCta.forcePushOnlyProgress !== undefined ? { forcePushOnlyProgress: toastCta.forcePushOnlyProgress } : {}), + ...(toastCta.prOnlyIfReady !== undefined + ? { prOnlyIfReady: toastCta.prOnlyIfReady } + : {}), ...(toastCta.isDefaultBranch !== undefined ? { isDefaultBranchOverride: toastCta.isDefaultBranch } : {}), diff --git a/apps/web/src/lib/gitReactQuery.ts b/apps/web/src/lib/gitReactQuery.ts index d68e400257..9a801f2dbc 100644 --- a/apps/web/src/lib/gitReactQuery.ts +++ b/apps/web/src/lib/gitReactQuery.ts @@ -121,6 +121,7 @@ export function gitRunStackedActionMutationOptions(input: { action, commitMessage, featureBranch, + prOnlyIfReady, filePaths, onProgress, }: { @@ -128,6 +129,7 @@ export function gitRunStackedActionMutationOptions(input: { action: GitStackedAction; commitMessage?: string; featureBranch?: boolean; + prOnlyIfReady?: boolean; filePaths?: string[]; onProgress?: (event: GitActionProgressEvent) => void; }) => { @@ -139,6 +141,7 @@ export function gitRunStackedActionMutationOptions(input: { action, ...(commitMessage ? { commitMessage } : {}), ...(featureBranch ? { featureBranch } : {}), + ...(prOnlyIfReady ? { prOnlyIfReady } : {}), ...(filePaths ? { filePaths } : {}), }, ...(onProgress ? [{ onProgress }] : []), diff --git a/packages/contracts/src/git.test.ts b/packages/contracts/src/git.test.ts index 6f133b0528..3657bd6247 100644 --- a/packages/contracts/src/git.test.ts +++ b/packages/contracts/src/git.test.ts @@ -66,15 +66,13 @@ describe("GitRunStackedActionInput", () => { const parsed = decodeRunStackedActionInput({ actionId: "action-1", cwd: "/repo", - action: "commit", - modelSelection: { - provider: "codex", - model: "gpt-5.4-mini", - }, + action: "commit_push_pr", + prOnlyIfReady: true, }); expect(parsed.actionId).toBe("action-1"); - expect(parsed.action).toBe("commit"); + expect(parsed.action).toBe("commit_push_pr"); + expect(parsed.prOnlyIfReady).toBe(true); }); }); @@ -106,7 +104,7 @@ describe("GitRunStackedActionResult", () => { kind: "run_action", label: "Create PR", action: "commit_push_pr", - forcePushOnlyProgress: true, + prOnlyIfReady: true, isDefaultBranch: false, }, }, @@ -115,6 +113,7 @@ describe("GitRunStackedActionResult", () => { expect(parsed.toast.cta.kind).toBe("run_action"); if (parsed.toast.cta.kind === "run_action") { expect(parsed.toast.cta.action).toBe("commit_push_pr"); + expect(parsed.toast.cta.prOnlyIfReady).toBe(true); expect(parsed.toast.cta.isDefaultBranch).toBe(false); } }); diff --git a/packages/contracts/src/git.ts b/packages/contracts/src/git.ts index b89890fafb..87f6aee4da 100644 --- a/packages/contracts/src/git.ts +++ b/packages/contracts/src/git.ts @@ -48,6 +48,7 @@ const GitRunStackedActionToastCta = Schema.Union([ action: GitStackedAction, forcePushOnlyProgress: Schema.optional(Schema.Boolean), isDefaultBranch: Schema.optional(Schema.Boolean), + prOnlyIfReady: Schema.optional(Schema.Boolean), }), ]); export type GitRunStackedActionToastCta = typeof GitRunStackedActionToastCta.Type; @@ -100,6 +101,7 @@ export const GitRunStackedActionInput = Schema.Struct({ action: GitStackedAction, commitMessage: Schema.optional(TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(10_000))), featureBranch: Schema.optional(Schema.Boolean), + prOnlyIfReady: Schema.optional(Schema.Boolean), filePaths: Schema.optional( Schema.Array(TrimmedNonEmptyStringSchema).check(Schema.isMinLength(1)), ),