Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 34 additions & 25 deletions services/hackbot-ui/components/RunDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,45 @@ import { StatusBadge } from "./StatusBadge";
import { parseTestPlan, TestPlanView } from "./TestPlanView";

// What a proposed action would write, rendered under its row so the reviewer
// approves the actual text and not just an action type. A comment carries its
// body in params.text; a Phabricator submission carries the title and summary of
// the revision it would open for the patch (previewed by PatchView), and an
// update carries them only when it rewords the existing revision's. A GitHub
// submission carries the title and body of the pull request it would open.
// approves the actual text and not just an action type. Each entry lists the
// params whose text is shown. A Phabricator update carries a title and summary
// only when it rewords the existing revision's; the patch itself is previewed
// by PatchView.
const ACTION_PREVIEWS: Record<string, { label: string; fields: string[] }> = {
"bugzilla.add_comment": {
label: "Comment preview",
fields: ["text"],
},
"phabricator.submit_patch": {
label: "Revision preview",
fields: ["title", "summary"],
},
"phabricator.update_patch": {
label: "Revision preview",
fields: ["title", "summary"],
},
"github.submit_patch": {
label: "Pull request preview",
fields: ["title", "body"],
},
"feedback.report_problem": {
label: "Feedback preview",
fields: ["title", "message"],
},
};

function actionPreview(
action: RunAction
): { label: string; text: string } | null {
const preview = ACTION_PREVIEWS[action.type];
if (!preview) return null;
const text = (v: unknown): string =>
typeof v === "string" && v.trim() ? v : "";
if (action.type === "bugzilla.add_comment") {
const body = text(action.params?.text);
return body ? { label: "Comment preview", text: body } : null;
}
if (
action.type === "phabricator.submit_patch" ||
action.type === "phabricator.update_patch"
) {
const body = [text(action.params?.title), text(action.params?.summary)]
.filter(Boolean)
.join("\n\n");
return body ? { label: "Revision preview", text: body } : null;
}
if (action.type === "github.submit_patch") {
const body = [text(action.params?.title), text(action.params?.body)]
.filter(Boolean)
.join("\n\n");
return body ? { label: "Pull request preview", text: body } : null;
}
return null;
const body = preview.fields
.map((field) => text(action.params?.[field]))
.filter(Boolean)
.join("\n\n");
return body ? { label: preview.label, text: body } : null;
}

const POLL_MS = 4000;
Expand Down