Factory: show and merge pull requests, issue chats (plan features, cut milestones)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a0a4082383
commit
56c20d92f8
10 files changed
+673
-3
No files matched your search
@@ -2,11 +2,23 @@ import { useEffect, useMemo, useState } from "react";
|
||||
import { get, post, put } from "../api";
|
||||
import { fmtCompact, fmtCost, fmtRelative, useT } from "../i18n";
|
||||
import { navigate } from "../router";
|
||||
import { confirmDialog, toast } from "../dialogs";
|
||||
import { choiceDialog, confirmDialog, promptDialog, toast } from "../dialogs";
|
||||
import { Icon } from "./Icon";
|
||||
import { Spinner } from "./Activity";
|
||||
import { ModelSelect } from "./ModelSelect";
|
||||
|
||||
interface PrInfo {
|
||||
number: number;
|
||||
html_url: string;
|
||||
title: string;
|
||||
state: "open" | "merged" | "closed";
|
||||
mergeable: boolean | null;
|
||||
changed_files: number | null;
|
||||
additions: number | null;
|
||||
deletions: number | null;
|
||||
head: string;
|
||||
}
|
||||
|
||||
type Phase = "review" | "build" | "qa";
|
||||
const PHASES: Phase[] = ["review", "build", "qa"];
|
||||
|
||||
@@ -180,6 +192,35 @@ function FactoryOverview({ onSettings }: { onSettings: () => void }) {
|
||||
}
|
||||
};
|
||||
|
||||
/** Start a chat that works out a feature or cuts a milestone into issues. */
|
||||
const issueChat = async (mode: "feature" | "slice") => {
|
||||
if (!data) return;
|
||||
let target = repo;
|
||||
if (!target) {
|
||||
const repos = data.repos.filter((r) => r.enabled);
|
||||
if (repos.length === 1) target = repos[0].url;
|
||||
else {
|
||||
const pick = await choiceDialog({ message: t("issues.pickRepo"), choices: repos.map((r) => ({ value: r.url, label: repoName(r.url) })) });
|
||||
if (!pick) return;
|
||||
target = pick;
|
||||
}
|
||||
}
|
||||
let topic = "";
|
||||
if (mode === "slice") {
|
||||
const name = await promptDialog({ message: t("issues.sliceWhich"), placeholder: "M2", confirmLabel: t("issues.sliceGo") });
|
||||
if (!name?.trim()) return;
|
||||
topic = name.trim();
|
||||
}
|
||||
setBusy(true);
|
||||
try {
|
||||
const s = await post<{ id: string }>("/factory/issue-chats", { repo: target, mode, topic });
|
||||
navigate(`/s/${s.id}`);
|
||||
} catch (e: any) {
|
||||
toast(e.message);
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
const issues = useMemo(() => (data?.issues ?? []).filter((i) => !repo || i.repo === repo), [data, repo]);
|
||||
const runs = useMemo(() => (data?.runs ?? []).filter((r) => !repo || r.repo === repo), [data, repo]);
|
||||
if (!data) return <div className="empty"><Spinner /></div>;
|
||||
@@ -231,6 +272,37 @@ function FactoryOverview({ onSettings }: { onSettings: () => void }) {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
const [pr, setPr] = useState<PrInfo | null>(null);
|
||||
const [prMethod, setPrMethod] = useState("merge");
|
||||
const selKey = selected ? `${selected.repo}#${selected.number}` : "";
|
||||
const loadPr = async () => {
|
||||
if (!selected || (!selected.branch && !selected.pr_url)) return setPr(null);
|
||||
try {
|
||||
const r = await get<{ pr: PrInfo | null }>(`/factory/issues/pr?repo=${encodeURIComponent(selected.repo)}&number=${selected.number}`);
|
||||
setPr(r.pr);
|
||||
} catch {
|
||||
setPr(null);
|
||||
}
|
||||
};
|
||||
useEffect(() => {
|
||||
setPr(null);
|
||||
void loadPr();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [selKey, selected?.state]);
|
||||
const mergePr = async () => {
|
||||
if (!selected || !pr) return;
|
||||
if (!(await confirmDialog({ message: t("factory.mergeConfirm", { n: pr.number, method: t(`factory.merge.${prMethod}` as any) }) }))) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
await post("/factory/issues/pr/merge", { repo: selected.repo, number: selected.number, pr: pr.number, method: prMethod });
|
||||
toast(t("factory.merged"));
|
||||
await loadPr();
|
||||
} catch (e: any) {
|
||||
toast(e.message);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
const phaseRunning = !!selected && ["review", "building", "testing"].includes(selected.state);
|
||||
|
||||
return (
|
||||
@@ -289,6 +361,12 @@ function FactoryOverview({ onSettings }: { onSettings: () => void }) {
|
||||
<button className="small primary" onClick={newProject} disabled={busy}>
|
||||
<Icon name="plus" /> {t("factory.newProject")}
|
||||
</button>
|
||||
<button className="small" onClick={() => issueChat("feature")} disabled={busy} title={t("issues.featureHint")}>
|
||||
<Icon name="sparkle" /> {t("issues.feature")}
|
||||
</button>
|
||||
<button className="small" onClick={() => issueChat("slice")} disabled={busy} title={t("issues.sliceHint")}>
|
||||
<Icon name="sparkle" /> {t("issues.slice")}
|
||||
</button>
|
||||
<button className="small" onClick={poll} disabled={busy} title={t("factory.pollNow")}>
|
||||
<Icon name="refresh" /> {t("factory.pollNow")}
|
||||
</button>
|
||||
@@ -360,6 +438,36 @@ function FactoryOverview({ onSettings }: { onSettings: () => void }) {
|
||||
)}
|
||||
</div>
|
||||
{selected?.note && <div className="hint" style={{ margin: "6px 0" }}>{selected.note}</div>}
|
||||
{pr && (
|
||||
<div className="factory-pr">
|
||||
<a href={pr.html_url} target="_blank" rel="noreferrer">
|
||||
<Icon name="external" /> #{pr.number} {pr.title}
|
||||
</a>
|
||||
<span className={`chip ${pr.state === "merged" ? "ok" : pr.state === "open" ? "" : "warn"}`}>{t(`factory.pr.${pr.state}` as any)}</span>
|
||||
{pr.state === "open" && pr.mergeable === false && <span className="chip warn">{t("factory.pr.conflict")}</span>}
|
||||
{pr.changed_files != null && (
|
||||
<span className="hint">
|
||||
{t("factory.pr.files", { n: pr.changed_files })}
|
||||
{pr.additions != null && ` · +${pr.additions} −${pr.deletions ?? 0}`}
|
||||
</span>
|
||||
)}
|
||||
<span className="spacer" />
|
||||
{pr.state === "open" && (
|
||||
<>
|
||||
<select value={prMethod} onChange={(e) => setPrMethod(e.target.value)} disabled={busy}>
|
||||
{["merge", "squash", "rebase"].map((m) => (
|
||||
<option key={m} value={m}>
|
||||
{t(`factory.merge.${m}` as any)}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<button className="small primary" onClick={mergePr} disabled={busy || pr.mergeable === false}>
|
||||
{t("factory.mergeBtn")}
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{shown.length === 0 && <div className="hint">{t("factory.noRuns")}</div>}
|
||||
{shown.length > 0 && (
|
||||
<div className="table-wrap">
|
||||
|
||||
Reference in new issue
Block a user