Skip commit and push for ready PR branches
- Detect PR-ready branches before running stacked actions - Emit only PR progress and thread prOnlyIfReady through UI and contracts
This commit is contained in:
1 parent
e7b7f48246
commit
54154bec17
8 files changed
+139
-31
No files matched your search
@@ -574,6 +574,7 @@ function runStackedAction(
|
||||
actionId?: string;
|
||||
commitMessage?: string;
|
||||
featureBranch?: boolean;
|
||||
prOnlyIfReady?: boolean;
|
||||
filePaths?: readonly string[];
|
||||
},
|
||||
options?: Parameters<GitManagerShape["runStackedAction"]>[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<GitActionProgressEvent, { kind: "phase_started" }> =>
|
||||
event.kind === "phase_started",
|
||||
),
|
||||
).toEqual([
|
||||
expect.objectContaining({
|
||||
kind: "phase_started",
|
||||
phase: "pr",
|
||||
label: "Creating PR...",
|
||||
}),
|
||||
]);
|
||||
}),
|
||||
);
|
||||
});
|
||||
@@ -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.Option<GitActionProgressPhase>>(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
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 }
|
||||
: {}),
|
||||
|
||||
@@ -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 }] : []),
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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)),
|
||||
),
|
||||
|
||||
Reference in new issue
Block a user