Add Git action modal with custom commit message support
- Add a Git action confirmation modal with live commit/push/PR progress states - Accept optional `commitMessage` input and skip AI message generation when provided - Expand server and contracts tests for custom commit message handling Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
3c939e8e69
commit
36bc85f54d
5 files changed
+540
-46
No files matched your search
@@ -248,6 +248,40 @@ describe("GitManager", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("uses custom commit message when provided", async () => {
|
||||
const repoDir = makeTempDir("t3code-git-manager-");
|
||||
await initRepo(repoDir);
|
||||
fs.writeFileSync(path.join(repoDir, "README.md"), "hello\ncustom\n");
|
||||
let generatedCount = 0;
|
||||
|
||||
const manager = new GitManager({
|
||||
textGenerator: createTextGenerator({
|
||||
generateCommitMessage: async () => {
|
||||
generatedCount += 1;
|
||||
return {
|
||||
subject: "this should not be used",
|
||||
body: "",
|
||||
};
|
||||
},
|
||||
}),
|
||||
});
|
||||
const result = await manager.runStackedAction({
|
||||
cwd: repoDir,
|
||||
action: "commit",
|
||||
commitMessage: "feat: custom summary line\n\n- details from user",
|
||||
});
|
||||
|
||||
expect(result.commit.status).toBe("created");
|
||||
expect(result.commit.subject).toBe("feat: custom summary line");
|
||||
expect(generatedCount).toBe(0);
|
||||
expect(await runGitStdout(repoDir, ["log", "-1", "--pretty=%s"])).toBe(
|
||||
"feat: custom summary line",
|
||||
);
|
||||
expect(await runGitStdout(repoDir, ["log", "-1", "--pretty=%b"])).toContain(
|
||||
"- details from user",
|
||||
);
|
||||
});
|
||||
|
||||
it("skips commit when there are no uncommitted changes", async () => {
|
||||
const repoDir = makeTempDir("t3code-git-manager-");
|
||||
await initRepo(repoDir);
|
||||
|
||||
@@ -106,6 +106,24 @@ function sanitizeCommitMessage(
|
||||
};
|
||||
}
|
||||
|
||||
function parseCustomCommitMessage(raw: string): CommitMessageGenerationResult | null {
|
||||
const normalized = raw.replace(/\r\n/g, "\n").trim();
|
||||
if (normalized.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const [firstLine, ...rest] = normalized.split("\n");
|
||||
const subject = firstLine?.trim() ?? "";
|
||||
if (subject.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
subject,
|
||||
body: rest.join("\n").trim(),
|
||||
};
|
||||
}
|
||||
|
||||
function extractBranchFromRef(ref: string): string {
|
||||
const normalized = ref.trim();
|
||||
|
||||
@@ -222,7 +240,11 @@ export class GitManager {
|
||||
throw new Error("Cannot create a pull request from detached HEAD.");
|
||||
}
|
||||
|
||||
const commit = await this.runCommitStep(input.cwd, initialStatus.branch);
|
||||
const commit = await this.runCommitStep(
|
||||
input.cwd,
|
||||
initialStatus.branch,
|
||||
input.commitMessage,
|
||||
);
|
||||
|
||||
const push = wantsPush
|
||||
? await this.gitCore.pushCurrentBranch(input.cwd, initialStatus.branch)
|
||||
@@ -243,6 +265,7 @@ export class GitManager {
|
||||
private async runCommitStep(
|
||||
cwd: string,
|
||||
branch: string | null,
|
||||
commitMessage?: string,
|
||||
): Promise<{
|
||||
status: "created" | "skipped_no_changes";
|
||||
commitSha?: string | undefined;
|
||||
@@ -253,18 +276,23 @@ export class GitManager {
|
||||
return { status: "skipped_no_changes" };
|
||||
}
|
||||
|
||||
let generated: CommitMessageGenerationResult;
|
||||
try {
|
||||
generated = sanitizeCommitMessage(
|
||||
await this.textGenerator.generateCommitMessage({
|
||||
cwd,
|
||||
branch,
|
||||
stagedSummary: limitContext(context.stagedSummary, 8_000),
|
||||
stagedPatch: limitContext(context.stagedPatch, 50_000),
|
||||
}),
|
||||
);
|
||||
} catch (error) {
|
||||
throw asCommandNotFound("codex", error) ?? error;
|
||||
let generated: CommitMessageGenerationResult | null = parseCustomCommitMessage(
|
||||
commitMessage ?? "",
|
||||
);
|
||||
|
||||
if (!generated) {
|
||||
try {
|
||||
generated = sanitizeCommitMessage(
|
||||
await this.textGenerator.generateCommitMessage({
|
||||
cwd,
|
||||
branch,
|
||||
stagedSummary: limitContext(context.stagedSummary, 8_000),
|
||||
stagedPatch: limitContext(context.stagedPatch, 50_000),
|
||||
}),
|
||||
);
|
||||
} catch (error) {
|
||||
throw asCommandNotFound("codex", error) ?? error;
|
||||
}
|
||||
}
|
||||
|
||||
const { commitSha } = await this.gitCore.commit(cwd, generated.subject, generated.body);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
PROVIDER_SEND_TURN_MAX_INPUT_CHARS,
|
||||
type GitRunStackedActionResult,
|
||||
type GitStackedAction,
|
||||
type GitStatusResult,
|
||||
type ProviderApprovalDecision,
|
||||
@@ -40,7 +41,16 @@ import BranchToolbar from "./BranchToolbar";
|
||||
import { isTerminalToggleShortcut } from "../terminal-shortcuts";
|
||||
import ChatMarkdown from "./ChatMarkdown";
|
||||
import ThreadTerminalDrawer from "./ThreadTerminalDrawer";
|
||||
import { CloudUploadIcon, GitCommitIcon, GithubIcon } from "lucide-react";
|
||||
import {
|
||||
CheckIcon,
|
||||
CircleIcon,
|
||||
CloudUploadIcon,
|
||||
GitCommitIcon,
|
||||
GithubIcon,
|
||||
Loader2Icon,
|
||||
MinusIcon,
|
||||
XIcon,
|
||||
} from "lucide-react";
|
||||
|
||||
function formatMessageMeta(createdAt: string, duration: string | null): string {
|
||||
if (!duration) return formatTimestamp(createdAt);
|
||||
@@ -81,6 +91,88 @@ function GitActionIcon(props: { icon: GitActionMenuItem["icon"]; disabled: boole
|
||||
return <GithubIcon className={`h-5 w-5 shrink-0 ${toneClass}`} />;
|
||||
}
|
||||
|
||||
type GitProgressStepStatus =
|
||||
| "pending"
|
||||
| "running"
|
||||
| "completed"
|
||||
| "skipped"
|
||||
| "failed";
|
||||
|
||||
interface GitProgressStep {
|
||||
id: "generate" | "commit" | "push" | "pr";
|
||||
label: string;
|
||||
status: GitProgressStepStatus;
|
||||
detail?: string;
|
||||
}
|
||||
|
||||
function gitActionModalTitle(action: GitStackedAction): string {
|
||||
if (action === "commit") return "Commit your changes";
|
||||
if (action === "commit_push") return "Commit and push changes";
|
||||
return "Commit, push and open PR";
|
||||
}
|
||||
|
||||
function initialGitProgressSteps(
|
||||
action: GitStackedAction,
|
||||
commitMessage: string,
|
||||
): GitProgressStep[] {
|
||||
const hasCustomMessage = commitMessage.trim().length > 0;
|
||||
const steps: GitProgressStep[] = [];
|
||||
|
||||
if (!hasCustomMessage) {
|
||||
steps.push({
|
||||
id: "generate",
|
||||
label: "Generate commit message",
|
||||
status: "pending",
|
||||
});
|
||||
}
|
||||
|
||||
steps.push({
|
||||
id: "commit",
|
||||
label: "Commit changes",
|
||||
status: "pending",
|
||||
});
|
||||
|
||||
if (action !== "commit") {
|
||||
steps.push({
|
||||
id: "push",
|
||||
label: "Push branch",
|
||||
status: "pending",
|
||||
});
|
||||
}
|
||||
|
||||
if (action === "commit_push_pr") {
|
||||
steps.push({
|
||||
id: "pr",
|
||||
label: "Create or open PR",
|
||||
status: "pending",
|
||||
});
|
||||
}
|
||||
|
||||
return steps;
|
||||
}
|
||||
|
||||
function updateProgressStep(
|
||||
steps: GitProgressStep[],
|
||||
id: GitProgressStep["id"],
|
||||
status: GitProgressStepStatus,
|
||||
detail?: string,
|
||||
): GitProgressStep[] {
|
||||
return steps.map((step) => {
|
||||
if (step.id !== id) return step;
|
||||
return {
|
||||
...step,
|
||||
status,
|
||||
...(detail ? { detail } : {}),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function runActionLabel(action: GitStackedAction): string {
|
||||
if (action === "commit") return "Commit";
|
||||
if (action === "commit_push") return "Commit & Push";
|
||||
return "Commit, Push & Open PR";
|
||||
}
|
||||
|
||||
function workToneClass(tone: "thinking" | "tool" | "info" | "error"): string {
|
||||
if (tone === "error") return "text-rose-300/50 dark:text-rose-300/50";
|
||||
if (tone === "tool") return "text-muted-foreground/70";
|
||||
@@ -166,6 +258,11 @@ export default function ChatView() {
|
||||
const [isGitActionRunning, setIsGitActionRunning] = useState(false);
|
||||
const [gitStatus, setGitStatus] = useState<GitStatusResult | null>(null);
|
||||
const [gitActionError, setGitActionError] = useState<string | null>(null);
|
||||
const [gitModalAction, setGitModalAction] = useState<GitStackedAction | null>(null);
|
||||
const [gitModalCommitMessage, setGitModalCommitMessage] = useState("");
|
||||
const [gitModalProgress, setGitModalProgress] = useState<GitProgressStep[]>([]);
|
||||
const [gitModalError, setGitModalError] = useState<string | null>(null);
|
||||
const [gitModalResult, setGitModalResult] = useState<GitRunStackedActionResult | null>(null);
|
||||
const [lastEditor, setLastEditor] = useState<EditorId>(() => {
|
||||
const stored = localStorage.getItem(LAST_EDITOR_KEY);
|
||||
return EDITORS.some((e) => e.id === stored) ? (stored as EditorId) : EDITORS[0].id;
|
||||
@@ -325,6 +422,16 @@ export default function ChatView() {
|
||||
},
|
||||
];
|
||||
}, [gitBaseDisabled, gitStatus]);
|
||||
const isGitModalOpen = gitModalAction !== null;
|
||||
const gitModalPreviewSteps = useMemo(
|
||||
() =>
|
||||
gitModalAction
|
||||
? initialGitProgressSteps(gitModalAction, gitModalCommitMessage)
|
||||
: ([] as GitProgressStep[]),
|
||||
[gitModalAction, gitModalCommitMessage],
|
||||
);
|
||||
const gitModalSteps =
|
||||
gitModalProgress.length > 0 ? gitModalProgress : gitModalPreviewSteps;
|
||||
|
||||
useEffect(() => {
|
||||
latestGitCwdRef.current = gitCwd;
|
||||
@@ -343,34 +450,161 @@ export default function ChatView() {
|
||||
setGitActionError(null);
|
||||
}, [api, gitCwd]);
|
||||
|
||||
const runGitAction = useCallback(
|
||||
async (action: GitStackedAction) => {
|
||||
if (!api || !gitCwd) return;
|
||||
const actionCwd = gitCwd;
|
||||
const openGitActionModal = useCallback((action: GitStackedAction) => {
|
||||
setIsGitMenuOpen(false);
|
||||
setGitModalAction(action);
|
||||
setGitModalCommitMessage("");
|
||||
setGitModalProgress([]);
|
||||
setGitModalError(null);
|
||||
setGitModalResult(null);
|
||||
setGitActionError(null);
|
||||
}, []);
|
||||
|
||||
setIsGitMenuOpen(false);
|
||||
setIsGitActionRunning(true);
|
||||
setGitActionError(null);
|
||||
try {
|
||||
await api.git.runStackedAction({
|
||||
cwd: actionCwd,
|
||||
action,
|
||||
});
|
||||
} catch (error) {
|
||||
setGitActionError(error instanceof Error ? error.message : "Git action failed.");
|
||||
} finally {
|
||||
setIsGitActionRunning(false);
|
||||
try {
|
||||
if (latestGitCwdRef.current === actionCwd) {
|
||||
await refreshGitStatus();
|
||||
}
|
||||
} catch {
|
||||
setGitStatus(null);
|
||||
const closeGitActionModal = useCallback(() => {
|
||||
if (isGitActionRunning) return;
|
||||
setGitModalAction(null);
|
||||
setGitModalCommitMessage("");
|
||||
setGitModalProgress([]);
|
||||
setGitModalError(null);
|
||||
setGitModalResult(null);
|
||||
}, [isGitActionRunning]);
|
||||
|
||||
const runGitAction = useCallback(async () => {
|
||||
if (!api || !gitCwd || !gitModalAction) return;
|
||||
const actionCwd = gitCwd;
|
||||
const action = gitModalAction;
|
||||
const commitMessage = gitModalCommitMessage.trim();
|
||||
const includeGeneratedCommitMessage = commitMessage.length === 0;
|
||||
|
||||
setIsGitActionRunning(true);
|
||||
setGitModalError(null);
|
||||
setGitActionError(null);
|
||||
setGitModalResult(null);
|
||||
setGitModalProgress(initialGitProgressSteps(action, commitMessage));
|
||||
|
||||
let commit: GitRunStackedActionResult["commit"] = {
|
||||
status: "skipped_no_changes",
|
||||
};
|
||||
let push: GitRunStackedActionResult["push"] = {
|
||||
status: "skipped_not_requested",
|
||||
};
|
||||
let pr: GitRunStackedActionResult["pr"] = {
|
||||
status: "skipped_not_requested",
|
||||
};
|
||||
|
||||
const updateStep = (
|
||||
id: GitProgressStep["id"],
|
||||
status: GitProgressStepStatus,
|
||||
detail?: string,
|
||||
) => {
|
||||
setGitModalProgress((steps) => updateProgressStep(steps, id, status, detail));
|
||||
};
|
||||
|
||||
try {
|
||||
if (includeGeneratedCommitMessage) {
|
||||
updateStep("generate", "running");
|
||||
} else {
|
||||
updateStep("commit", "running");
|
||||
}
|
||||
|
||||
const commitRun = await api.git.runStackedAction({
|
||||
cwd: actionCwd,
|
||||
action: "commit",
|
||||
...(commitMessage.length > 0 ? { commitMessage } : {}),
|
||||
});
|
||||
commit = commitRun.commit;
|
||||
|
||||
if (includeGeneratedCommitMessage) {
|
||||
if (commitRun.commit.status === "created") {
|
||||
updateStep(
|
||||
"generate",
|
||||
"completed",
|
||||
commitRun.commit.subject
|
||||
? `Generated: ${commitRun.commit.subject}`
|
||||
: "Generated commit message.",
|
||||
);
|
||||
} else {
|
||||
updateStep("generate", "skipped", "No local changes to commit.");
|
||||
}
|
||||
}
|
||||
},
|
||||
[api, gitCwd, refreshGitStatus],
|
||||
);
|
||||
|
||||
if (commitRun.commit.status === "created") {
|
||||
updateStep(
|
||||
"commit",
|
||||
"completed",
|
||||
commitRun.commit.subject ?? "Committed local changes.",
|
||||
);
|
||||
} else {
|
||||
updateStep("commit", "skipped", "No local changes to commit.");
|
||||
}
|
||||
|
||||
if (action !== "commit") {
|
||||
updateStep("push", "running");
|
||||
const pushRun = await api.git.runStackedAction({
|
||||
cwd: actionCwd,
|
||||
action: "commit_push",
|
||||
});
|
||||
push = pushRun.push;
|
||||
if (pushRun.push.status === "pushed") {
|
||||
updateStep(
|
||||
"push",
|
||||
"completed",
|
||||
pushRun.push.upstreamBranch
|
||||
? `Pushed to ${pushRun.push.upstreamBranch}.`
|
||||
: "Pushed latest commits.",
|
||||
);
|
||||
} else {
|
||||
updateStep("push", "skipped", "Branch already up to date.");
|
||||
}
|
||||
}
|
||||
|
||||
if (action === "commit_push_pr") {
|
||||
updateStep("pr", "running");
|
||||
const prRun = await api.git.runStackedAction({
|
||||
cwd: actionCwd,
|
||||
action: "commit_push_pr",
|
||||
});
|
||||
pr = prRun.pr;
|
||||
if (prRun.pr.status === "opened_existing") {
|
||||
updateStep(
|
||||
"pr",
|
||||
"completed",
|
||||
prRun.pr.number
|
||||
? `Opened existing PR #${prRun.pr.number}.`
|
||||
: "Opened existing PR.",
|
||||
);
|
||||
} else if (prRun.pr.status === "created") {
|
||||
updateStep(
|
||||
"pr",
|
||||
"completed",
|
||||
prRun.pr.number ? `Created PR #${prRun.pr.number}.` : "Created PR.",
|
||||
);
|
||||
} else {
|
||||
updateStep("pr", "skipped", "PR step was not requested.");
|
||||
}
|
||||
}
|
||||
|
||||
setGitModalResult({ action, commit, push, pr });
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : "Git action failed.";
|
||||
setGitModalError(message);
|
||||
setGitActionError(message);
|
||||
setGitModalProgress((steps) => {
|
||||
const active = steps.find((step) => step.status === "running");
|
||||
if (!active) return steps;
|
||||
return updateProgressStep(steps, active.id, "failed", message);
|
||||
});
|
||||
} finally {
|
||||
setIsGitActionRunning(false);
|
||||
try {
|
||||
if (latestGitCwdRef.current === actionCwd) {
|
||||
await refreshGitStatus();
|
||||
}
|
||||
} catch {
|
||||
setGitStatus(null);
|
||||
}
|
||||
}
|
||||
}, [api, gitCwd, gitModalAction, gitModalCommitMessage, refreshGitStatus]);
|
||||
|
||||
const envLocked = Boolean(
|
||||
activeThread &&
|
||||
@@ -436,6 +670,11 @@ export default function ChatView() {
|
||||
|
||||
useEffect(() => {
|
||||
setGitActionError(null);
|
||||
setGitModalError(null);
|
||||
setGitModalAction(null);
|
||||
setGitModalCommitMessage("");
|
||||
setGitModalProgress([]);
|
||||
setGitModalResult(null);
|
||||
}, [activeProject?.id, activeWorktreePath]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -537,6 +776,21 @@ export default function ChatView() {
|
||||
};
|
||||
}, [isGitMenuOpen]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isGitModalOpen) return;
|
||||
|
||||
const handleEscape = (event: globalThis.KeyboardEvent) => {
|
||||
if (event.key !== "Escape") return;
|
||||
if (isGitActionRunning) return;
|
||||
closeGitActionModal();
|
||||
};
|
||||
|
||||
window.addEventListener("keydown", handleEscape);
|
||||
return () => {
|
||||
window.removeEventListener("keydown", handleEscape);
|
||||
};
|
||||
}, [closeGitActionModal, isGitActionRunning, isGitModalOpen]);
|
||||
|
||||
// Cmd+O / Ctrl+O to open in last-used editor
|
||||
useEffect(() => {
|
||||
const handler = (e: globalThis.KeyboardEvent) => {
|
||||
@@ -882,7 +1136,7 @@ export default function ChatView() {
|
||||
className="mb-1.5 flex w-full items-center gap-3 rounded-2xl px-3 py-2.5 text-left text-[14px] text-foreground transition-colors duration-150 hover:bg-accent disabled:cursor-not-allowed disabled:text-muted-foreground/65"
|
||||
disabled={item.disabled}
|
||||
onClick={() => {
|
||||
void runGitAction(item.id);
|
||||
openGitActionModal(item.id);
|
||||
}}
|
||||
>
|
||||
<GitActionIcon icon={item.icon} disabled={item.disabled} />
|
||||
@@ -941,12 +1195,6 @@ export default function ChatView() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{gitActionError && (
|
||||
<div className="mx-4 mt-3 rounded-lg border border-rose-200 bg-rose-50 px-3 py-2 text-xs text-rose-800 dark:border-rose-400/20 dark:bg-rose-900/20 dark:text-rose-200">
|
||||
{gitActionError}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{pendingApprovals.length > 0 && (
|
||||
<div className="mx-4 mt-3 space-y-2">
|
||||
{pendingApprovals.map((approval) => {
|
||||
@@ -1430,6 +1678,180 @@ export default function ChatView() {
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{isGitModalOpen && gitModalAction && (
|
||||
<div
|
||||
className="fixed inset-0 z-[80] flex items-center justify-center bg-black/35 px-4 py-6"
|
||||
onMouseDown={() => {
|
||||
closeGitActionModal();
|
||||
}}
|
||||
>
|
||||
<div
|
||||
className="w-full max-w-[640px] rounded-3xl border border-border bg-popover p-6 shadow-2xl"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-label="Git action confirmation"
|
||||
onMouseDown={(event) => {
|
||||
event.stopPropagation();
|
||||
}}
|
||||
>
|
||||
<div className="flex items-start justify-between gap-4">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="rounded-2xl bg-accent p-3">
|
||||
<GitActionIcon
|
||||
icon={
|
||||
gitModalAction === "commit"
|
||||
? "commit"
|
||||
: gitModalAction === "commit_push"
|
||||
? "push"
|
||||
: "pr"
|
||||
}
|
||||
disabled={false}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-xs uppercase tracking-[0.14em] text-muted-foreground/70">
|
||||
Git actions
|
||||
</p>
|
||||
<h3 className="text-3xl font-semibold tracking-tight text-foreground">
|
||||
{gitActionModalTitle(gitModalAction)}
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
className="rounded-md p-1 text-muted-foreground/60 transition-colors duration-150 hover:bg-accent hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50"
|
||||
onClick={closeGitActionModal}
|
||||
disabled={isGitActionRunning}
|
||||
aria-label="Close git action dialog"
|
||||
>
|
||||
<XIcon className="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="mt-6 space-y-2 rounded-2xl border border-border/80 bg-card/40 px-4 py-3">
|
||||
<div className="flex items-center justify-between gap-4 text-sm">
|
||||
<span className="text-muted-foreground/70">Branch</span>
|
||||
<span className="font-mono text-foreground">
|
||||
{gitStatus?.branch ?? "(detached HEAD)"}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center justify-between gap-4 text-sm">
|
||||
<span className="text-muted-foreground/70">Changes</span>
|
||||
<span className="text-foreground">
|
||||
{gitStatus?.hasWorkingTreeChanges ? "Working tree has changes" : "No local changes"}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mt-6">
|
||||
<label
|
||||
htmlFor="git-commit-message"
|
||||
className="mb-2 block text-sm font-medium text-foreground"
|
||||
>
|
||||
Commit message
|
||||
</label>
|
||||
<textarea
|
||||
id="git-commit-message"
|
||||
rows={3}
|
||||
className="w-full resize-none rounded-2xl border border-border bg-background px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground/50 focus:border-ring focus:outline-none disabled:cursor-not-allowed disabled:opacity-70"
|
||||
placeholder="Leave blank to autogenerate a commit message"
|
||||
value={gitModalCommitMessage}
|
||||
onChange={(event) => setGitModalCommitMessage(event.target.value)}
|
||||
disabled={isGitActionRunning || gitModalResult !== null}
|
||||
/>
|
||||
<p className="mt-1.5 text-xs text-muted-foreground/65">
|
||||
Leave this empty to use AI-generated commit text.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="mt-6">
|
||||
<p className="text-sm font-medium text-foreground">Next steps</p>
|
||||
<div className="mt-2 overflow-hidden rounded-2xl border border-border">
|
||||
{gitModalSteps.map((step, index) => {
|
||||
const borderClass = index < gitModalSteps.length - 1 ? "border-b border-border/70" : "";
|
||||
const statusTextClass =
|
||||
step.status === "failed"
|
||||
? "text-rose-500 dark:text-rose-300"
|
||||
: step.status === "completed"
|
||||
? "text-emerald-600 dark:text-emerald-300"
|
||||
: "text-muted-foreground/70";
|
||||
|
||||
return (
|
||||
<div
|
||||
key={step.id}
|
||||
className={`flex items-start gap-3 bg-card/45 px-4 py-3 ${borderClass}`}
|
||||
>
|
||||
<span className="mt-0.5">
|
||||
{step.status === "running" ? (
|
||||
<Loader2Icon className="h-4 w-4 animate-spin text-foreground" />
|
||||
) : step.status === "completed" ? (
|
||||
<CheckIcon className="h-4 w-4 text-emerald-600 dark:text-emerald-300" />
|
||||
) : step.status === "skipped" ? (
|
||||
<MinusIcon className="h-4 w-4 text-muted-foreground/70" />
|
||||
) : step.status === "failed" ? (
|
||||
<XIcon className="h-4 w-4 text-rose-500 dark:text-rose-300" />
|
||||
) : (
|
||||
<CircleIcon className="h-4 w-4 text-muted-foreground/60" />
|
||||
)}
|
||||
</span>
|
||||
<div className="min-w-0">
|
||||
<p className="text-sm text-foreground">{step.label}</p>
|
||||
{step.detail && (
|
||||
<p className={`mt-0.5 text-xs ${statusTextClass}`}>{step.detail}</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{(gitModalError ?? gitActionError) && (
|
||||
<div className="mt-4 rounded-lg border border-rose-300/50 bg-rose-500/10 px-3 py-2 text-xs text-rose-600 dark:text-rose-200">
|
||||
{gitModalError ?? gitActionError}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{gitModalResult?.pr.url && (
|
||||
<div className="mt-4 rounded-lg border border-border bg-card/40 px-3 py-2 text-xs text-muted-foreground/80">
|
||||
PR:{" "}
|
||||
<a
|
||||
href={gitModalResult.pr.url}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="text-foreground underline underline-offset-2"
|
||||
>
|
||||
{gitModalResult.pr.url}
|
||||
</a>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="mt-6 flex justify-end gap-2">
|
||||
<button
|
||||
type="button"
|
||||
className="rounded-xl border border-border px-4 py-2 text-sm text-foreground transition-colors duration-150 hover:bg-accent disabled:cursor-not-allowed disabled:opacity-60"
|
||||
onClick={closeGitActionModal}
|
||||
disabled={isGitActionRunning}
|
||||
>
|
||||
{gitModalResult ? "Done" : "Cancel"}
|
||||
</button>
|
||||
{!gitModalResult && (
|
||||
<button
|
||||
type="button"
|
||||
className="rounded-xl bg-foreground px-4 py-2 text-sm font-medium text-background transition-colors duration-150 hover:bg-foreground/90 disabled:cursor-not-allowed disabled:opacity-60"
|
||||
onClick={() => {
|
||||
void runGitAction();
|
||||
}}
|
||||
disabled={isGitActionRunning}
|
||||
>
|
||||
{isGitActionRunning ? "Running..." : runActionLabel(gitModalAction)}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<BranchToolbar envMode={envMode} onEnvModeChange={setEnvMode} envLocked={envLocked} />
|
||||
|
||||
{activeThread.terminalOpen && api && activeProject && (
|
||||
|
||||
@@ -43,6 +43,15 @@ describe("git contracts", () => {
|
||||
expect(parsed.action).toBe("commit_push");
|
||||
});
|
||||
|
||||
it("accepts custom commit message input", () => {
|
||||
const parsed = gitRunStackedActionInputSchema.parse({
|
||||
cwd: "/tmp/repo",
|
||||
action: "commit",
|
||||
commitMessage: " chore: update git action modal ",
|
||||
});
|
||||
expect(parsed.commitMessage).toBe("chore: update git action modal");
|
||||
});
|
||||
|
||||
it("parses stacked action result with metadata", () => {
|
||||
const parsed = gitRunStackedActionResultSchema.parse({
|
||||
action: "commit_push_pr",
|
||||
|
||||
@@ -106,6 +106,7 @@ const gitPrStepStatusSchema = z.enum([
|
||||
export const gitRunStackedActionInputSchema = z.object({
|
||||
cwd: z.string().trim().min(1),
|
||||
action: gitStackedActionSchema,
|
||||
commitMessage: z.string().trim().min(1).max(10_000).optional(),
|
||||
});
|
||||
|
||||
export const gitRunStackedActionResultSchema = z.object({
|
||||
|
||||
Reference in new issue
Block a user