Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: prefill issue-report fields via include toggles (#10307)

Kiran Gadhave0f481eb7fc65
diff --git a/.github/ISSUE_TEMPLATE/bug_report.yaml b/.github/ISSUE_TEMPLATE/bug_report.yaml
index 102d81f318..9f6eb26c08 100644
--- a/.github/ISSUE_TEMPLATE/bug_report.yaml
+++ b/.github/ISSUE_TEMPLATE/bug_report.yaml
@@ -31,9 +31,9 @@ body:
attributes:
label: Environment
description: |
- In marimo, open **Send feedback → Report an issue** and click **Copy issue details**, then paste below. Otherwise, paste the output of `marimo env`.
+ In marimo, open **Send feedback → Report an issue** and click **Open GitHub issue** to prefill this field, or copy the environment details with the copy icon and paste below. Otherwise, paste the output of `marimo env`.
placeholder: |
- Paste the copied issue details here; they render as collapsible sections. If you ran `marimo env` instead, paste its output.
+ Paste the copied environment details here; they render as a collapsible section. If you ran `marimo env` instead, paste its output.
validations:
required: true
- type: textarea
diff --git a/frontend/src/components/editor/chrome/components/__tests__/feedback-button.test.tsx b/frontend/src/components/editor/chrome/components/__tests__/feedback-button.test.tsx
index 765a7dfcc3..2a0ce95474 100644
--- a/frontend/src/components/editor/chrome/components/__tests__/feedback-button.test.tsx
+++ b/frontend/src/components/editor/chrome/components/__tests__/feedback-button.test.tsx
@@ -50,6 +50,7 @@ function wrapper({ children }: { children: React.ReactNode }) {
describe("FeedbackModal issue reporting", () => {
beforeEach(() => {
vi.clearAllMocks();
+ localStorage.clear();
store.set(requestClientAtom, MockRequestClient.create());
store.set(viewStateAtom, { mode: "edit", cellAnchor: null });
store.set(connectionAtom, { state: WebSocketState.OPEN });
@@ -87,7 +88,7 @@ describe("FeedbackModal issue reporting", () => {
).toBeInTheDocument();
});
- it("copies partial details when the environment request fails", async () => {
+ it("copies partial environment JSON when the environment request fails", async () => {
store.set(
requestClientAtom,
MockRequestClient.create({
@@ -97,7 +98,9 @@ describe("FeedbackModal issue reporting", () => {
render(<FeedbackModal onClose={vi.fn()} />, { wrapper });
await screen.findByText("Server environment information unavailable");
- fireEvent.click(screen.getByRole("button", { name: "Copy issue details" }));
+ fireEvent.click(
+ screen.getByRole("button", { name: "Copy environment JSON" }),
+ );
await waitFor(() =>
expect(copyModule.copyToClipboard).toHaveBeenCalledWith(
expect.stringContaining("Environment Collection Error"),
@@ -125,10 +128,8 @@ describe("FeedbackModal issue reporting", () => {
);
});
- it("includes notebook source only after explicit opt-in", async () => {
- const readCode = vi.fn().mockResolvedValue({
- contents: "secret = 'review before posting'",
- });
+ it("prefills the notebook code after checking include code", async () => {
+ const readCode = vi.fn().mockResolvedValue({ contents: "import marimo" });
store.set(
requestClientAtom,
MockRequestClient.create({
@@ -137,51 +138,43 @@ describe("FeedbackModal issue reporting", () => {
}),
);
render(<FeedbackModal onClose={vi.fn()} />, { wrapper });
+ const link = screen.getByRole("link", { name: "Open GitHub issue" });
await screen.findByText("Environment details");
expect(readCode).not.toHaveBeenCalled();
+ expect(link.getAttribute("href") ?? "").not.toContain("reproduction-code=");
+
fireEvent.click(
- screen.getByRole("checkbox", { name: "Include full notebook source" }),
+ screen.getByRole("checkbox", { name: "Include notebook code" }),
);
await waitFor(() => expect(readCode).toHaveBeenCalledOnce());
-
- fireEvent.click(screen.getByRole("button", { name: "Copy issue details" }));
- await waitFor(() =>
- expect(copyModule.copyToClipboard).toHaveBeenCalledWith(
- expect.stringContaining("Notebook source: example.py"),
- ),
- );
+ await waitFor(() => {
+ const href = link.getAttribute("href") ?? "";
+ expect(href).toContain("reproduction-code=");
+ expect(href).toContain(encodeURIComponent("import marimo"));
+ });
});
- it("discards notebook source after unchecking", async () => {
- const readCode = vi.fn().mockResolvedValue({ contents: "x = 1" });
+ it("disables include code and explains why when disconnected", async () => {
+ store.set(connectionAtom, { state: WebSocketState.CONNECTING });
store.set(
requestClientAtom,
MockRequestClient.create({
getEnvironmentInfo: vi.fn().mockResolvedValue(environment),
- readCode,
}),
);
render(<FeedbackModal onClose={vi.fn()} />, { wrapper });
await screen.findByText("Environment details");
- const checkbox = screen.getByRole("checkbox", {
- name: "Include full notebook source",
- });
- fireEvent.click(checkbox);
- await waitFor(() => expect(readCode).toHaveBeenCalledOnce());
- fireEvent.click(checkbox);
-
- fireEvent.click(screen.getByRole("button", { name: "Copy issue details" }));
- await waitFor(() =>
- expect(copyModule.copyToClipboard).toHaveBeenCalledWith(
- expect.not.stringContaining("Notebook source"),
- ),
- );
+ expect(
+ screen.getByRole("checkbox", { name: "Include notebook code" }),
+ ).toBeDisabled();
+ expect(
+ screen.getByText("Connect the notebook to include its source."),
+ ).toBeInTheDocument();
});
- it("disables the notebook option and explains why when disconnected", async () => {
- store.set(connectionAtom, { state: WebSocketState.CONNECTING });
+ it("disables include errors when there are no errors", async () => {
store.set(
requestClientAtom,
MockRequestClient.create({
@@ -192,11 +185,8 @@ describe("FeedbackModal issue reporting", () => {
await screen.findByText("Environment details");
expect(
- screen.getByRole("checkbox", { name: "Include full notebook source" }),
+ screen.getByRole("checkbox", { name: "Include errors" }),
).toBeDisabled();
- expect(
- screen.getByText("Connect the notebook to include its source."),
- ).toBeInTheDocument();
});
it("prefills the GitHub issue link with the environment once loaded", async () => {
diff --git a/frontend/src/components/editor/chrome/components/feedback-button.tsx b/frontend/src/components/editor/chrome/components/feedback-button.tsx
index b6beb89796..0f3ff0ee7e 100644
--- a/frontend/src/components/editor/chrome/components/feedback-button.tsx
+++ b/frontend/src/components/editor/chrome/components/feedback-button.tsx
@@ -5,7 +5,7 @@ import { Slot as SlotPrimitive } from "radix-ui";
const Slot = SlotPrimitive.Slot;
import { useAtomValue } from "jotai";
-import { CheckIcon, ExternalLinkIcon, TriangleAlertIcon } from "lucide-react";
+import { ExternalLinkIcon, TriangleAlertIcon } from "lucide-react";
import React, { type PropsWithChildren, useMemo, useState } from "react";
import { CopyClipboardIcon } from "@/components/icons/copy-icon";
import { useImperativeModal } from "@/components/modal/ImperativeModal";
@@ -18,16 +18,16 @@ import {
DialogTitle,
} from "@/components/ui/dialog";
import { Skeleton } from "@/components/ui/skeleton";
-import { toast } from "@/components/ui/use-toast";
import { notebookAtom } from "@/core/cells/cells";
import { Constants } from "@/core/constants";
import {
buildBugReportUrl,
- buildIssueDetails,
createPartialEnvironment,
type EnvironmentDiagnostics,
enrichEnvironment,
- type NotebookSource,
+ formatCodeSection,
+ formatEnvironmentSection,
+ formatErrorsSection,
} from "@/core/diagnostics/issue-details";
import {
formatCellError,
@@ -41,8 +41,8 @@ import { filenameAtom } from "@/core/saving/file-state";
import { store } from "@/core/state/jotai";
import { WebSocketState } from "@/core/websocket/types";
import { useAsyncData } from "@/hooks/useAsyncData";
+import { useLocalStorage } from "@/hooks/useLocalStorage";
import { cn } from "@/utils/cn";
-import { copyToClipboard } from "@/utils/copy";
const CollapsiblePreview: React.FC<{ content: string }> = ({ content }) => {
const [expanded, setExpanded] = useState(false);
@@ -108,8 +108,6 @@ export const FeedbackModal: React.FC<{
codeAvailable &&
connection.state === WebSocketState.OPEN;
- const [includeNotebook, setIncludeNotebook] = useState(false);
-
const notebookSourceReason = notebookSourceAvailable
? undefined
: filename === null
@@ -118,13 +116,14 @@ export const FeedbackModal: React.FC<{
? "Notebook source is hidden in this view."
: "Connect the notebook to include its source.";
- const notebookSourceRequest = useAsyncData(async () => {
- if (!includeNotebook || !notebookSourceAvailable || filename === null) {
- return undefined;
- }
- const { contents } = await readCode();
- return { filename, contents } satisfies NotebookSource;
- }, [includeNotebook, notebookSourceAvailable, filename, readCode]);
+ const [includeErrors, setIncludeErrors] = useLocalStorage(
+ "marimo:issue-report:include-errors",
+ false,
+ );
+ const [includeCode, setIncludeCode] = useLocalStorage(
+ "marimo:issue-report:include-code",
+ false,
+ );
const environment: EnvironmentDiagnostics | undefined =
environmentRequest.data
@@ -138,83 +137,122 @@ export const FeedbackModal: React.FC<{
)
: undefined;
- const [issueDetailsCopied, setIssueDetailsCopied] = useState(false);
-
- const githubIssueUrl = useMemo(() => {
- if (!environment) {
- return Constants.bugReportUrl;
+ const codeRequest = useAsyncData(async () => {
+ if (!includeCode || !notebookSourceAvailable) {
+ return undefined;
}
- return buildBugReportUrl(
- Constants.bugReportUrl,
- buildIssueDetails({ environment, errors }),
- );
- }, [environment, errors]);
+ const { contents } = await readCode();
+ return contents;
+ }, [includeCode, notebookSourceAvailable, readCode]);
- const copyIssueDetails = async () => {
+ const { url: githubIssueUrl, omitted } = useMemo(() => {
if (!environment) {
- return;
+ return { url: Constants.bugReportUrl, omitted: [] as string[] };
+ }
+ const fields: Record<string, string> = {
+ env: formatEnvironmentSection(environment),
+ };
+ if (includeErrors && errors.length > 0) {
+ fields["bug-description"] = formatErrorsSection(errors);
}
- const notebookForReport = includeNotebook
- ? notebookSourceRequest.data
- : undefined;
- await copyToClipboard(
- buildIssueDetails({ environment, errors, notebook: notebookForReport }),
- );
- setIssueDetailsCopied(true);
- setTimeout(() => setIssueDetailsCopied(false), 2000);
- toast({
- title:
- environmentRequest.status === "error"
- ? "Partial issue details copied"
- : "Issue details copied",
- });
- };
+ if (includeCode && codeRequest.data) {
+ fields["reproduction-code"] = formatCodeSection(codeRequest.data);
+ }
+ return buildBugReportUrl(Constants.bugReportUrl, fields);
+ }, [environment, errors, includeErrors, includeCode, codeRequest.data]);
+
+ const omittedLabels = omitted
+ .map((field) =>
+ field === "bug-description"
+ ? "errors"
+ : field === "reproduction-code"
+ ? "code"
+ : field,
+ )
+ .join(", ");
return (
<DialogContent className="w-[540px] max-w-[90vw]">
<DialogHeader>
<DialogTitle>Report an issue</DialogTitle>
<DialogDescription>
- Copy your environment and any current errors to include in a GitHub
- bug report. Nothing is uploaded automatically; review the details
- before posting.
+ Open a GitHub bug report prefilled with your environment, and
+ optionally your current errors and notebook code. Nothing is uploaded
+ automatically; review the details before posting.
</DialogDescription>
</DialogHeader>
<div className="flex flex-col gap-4 max-h-[60vh] overflow-y-auto">
- <div className="flex flex-wrap gap-2">
+ <div className="flex flex-col gap-3">
<Button
type="button"
variant="default"
size="xs"
- disabled={
- !environment ||
- (includeNotebook && notebookSourceRequest.isFetching)
- }
- onClick={copyIssueDetails}
+ asChild={true}
+ className="self-start"
>
- {issueDetailsCopied && (
- <CheckIcon
- className="w-4 h-4 mr-2 text-(--grass-11)"
- color="white"
- />
- )}
- {issueDetailsCopied ? "Copied!" : "Copy issue details"}
- </Button>
- <Button type="button" variant="outline" size="xs" asChild={true}>
<a href={githubIssueUrl} target="_blank" rel="noreferrer">
<ExternalLinkIcon className="w-4 h-4 mr-2" />
Open GitHub issue
</a>
</Button>
- </div>
- {includeNotebook && (
- <p className="text-xs text-muted-foreground">
- The GitHub link prefills your environment only. Use Copy issue
- details to include the full notebook source.
- </p>
- )}
+ <div className="flex flex-col gap-2">
+ <div className="flex items-center gap-2 text-sm">
+ <Checkbox
+ id="issue-include-errors"
+ checked={includeErrors}
+ disabled={errors.length === 0}
+ onCheckedChange={(checked) =>
+ setIncludeErrors(checked === true)
+ }
+ aria-label="Include errors"
+ />
+ <label htmlFor="issue-include-errors">Include errors</label>
+ </div>
+
+ <div className="flex flex-col gap-1">
+ <div className="flex items-center gap-2 text-sm">
+ <Checkbox
+ id="issue-include-code"
+ checked={includeCode}
+ disabled={!notebookSourceAvailable}
+ onCheckedChange={(checked) =>
+ setIncludeCode(checked === true)
+ }
+ aria-label="Include notebook code"
+ />
+ <label htmlFor="issue-include-code">
+ Include notebook code
+ </label>
+ </div>
+ {notebookSourceReason && (
+ <span className="text-xs text-muted-foreground ml-6">
+ {notebookSourceReason}
+ </span>
+ )}
+ {includeCode && codeRequest.status === "error" && (
+ <span className="text-xs text-(--red-11) ml-6">
+ Notebook source could not be loaded.
+ </span>
+ )}
+ </div>
+ </div>
+
+ {omittedLabels ? (
+ <div className="flex items-start gap-2 text-xs text-(--yellow-11)">
+ <TriangleAlertIcon className="w-3.5 h-3.5 shrink-0 mt-0.5" />
+ <span>
+ Too large to prefill and left out of the link: {omittedLabels}.
+ Paste them into the issue manually.
+ </span>
+ </div>
+ ) : (
+ <p className="text-xs text-muted-foreground">
+ Your environment is always included.
+ </p>
+ )}
+ </div>
{environmentRequest.status === "pending" && (
<div className="flex flex-col gap-2">
@@ -261,7 +299,15 @@ export const FeedbackModal: React.FC<{
{environment && errors.length > 0 && (
<div className="flex flex-col gap-1">
- <span className="text-sm font-medium">Current errors</span>
+ <div className="flex items-center justify-between">
+ <span className="text-sm font-medium">Errors</span>
+ <CopyClipboardIcon
+ className="w-3.5 h-3.5"
+ value={formatErrorsSection(errors)}
+ ariaLabel="Copy errors"
+ toastTitle="Errors copied"
+ />
+ </div>
<CollapsiblePreview
content={errors.map(formatCellError).join("\n\n---\n\n")}
/>
@@ -270,46 +316,10 @@ export const FeedbackModal: React.FC<{
{environment && errors.length === 0 && (
<span className="text-sm text-muted-foreground">
- No current errors detected.
+ No errors detected.
</span>
)}
- <div className="flex flex-col gap-1">
- <div className="flex items-start gap-2 text-sm">
- <Checkbox
- id="issue-include-notebook"
- className="mt-0.5"
- checked={includeNotebook}
- disabled={!notebookSourceAvailable}
- onCheckedChange={(checked) =>
- setIncludeNotebook(checked === true)
- }
- aria-label="Include full notebook source"
- />
- <label htmlFor="issue-include-notebook">
- Include full notebook source
- </label>
- </div>
- <p className="text-xs text-muted-foreground ml-6">
- Copies the entire saved Python source, including comments, literal
- data, embedded credentials, and package metadata. Outputs and
- external files are not included. Review it before posting.{" "}
- <span className="font-bold">
- For private notebooks, paste a minimal reproduction instead.
- </span>
- </p>
- {notebookSourceReason && (
- <span className="text-xs text-muted-foreground ml-6">
- {notebookSourceReason}
- </span>
- )}
- {includeNotebook && notebookSourceRequest.status === "error" && (
- <span className="text-xs text-(--red-11) ml-6">
- Notebook source could not be loaded.
- </span>
- )}
- </div>
-
<div className="border-t pt-3">
<p className="text-sm text-muted-foreground">
Other feedback? Take our{" "}
diff --git a/frontend/src/core/diagnostics/__tests__/issue-details.test.ts b/frontend/src/core/diagnostics/__tests__/issue-details.test.ts
index 6de14d6ba0..37b3b69dfb 100644
--- a/frontend/src/core/diagnostics/__tests__/issue-details.test.ts
+++ b/frontend/src/core/diagnostics/__tests__/issue-details.test.ts
@@ -6,9 +6,11 @@ import type { CellErrorEntry } from "@/core/errors/error-entries";
import type { EnvironmentInfo } from "@/core/network/types";
import {
buildBugReportUrl,
- buildIssueDetails,
createPartialEnvironment,
enrichEnvironment,
+ formatCodeSection,
+ formatEnvironmentSection,
+ formatErrorsSection,
markdownCodeFence,
MAX_PREFILL_URL_LENGTH,
} from "../issue-details";
@@ -86,20 +88,16 @@ describe("markdownCodeFence", () => {
});
});
-describe("buildIssueDetails", () => {
- it("includes the environment and omits notebook source unless provided", () => {
- const markdown = buildIssueDetails({
- environment,
- errors: [],
- notebook: undefined,
- });
+describe("formatEnvironmentSection", () => {
+ it("wraps the environment JSON in a collapsible section", () => {
+ const markdown = formatEnvironmentSection(environment);
expect(markdown).toContain("<summary>Environment</summary>");
expect(markdown).toContain('"marimo": "1.2.3"');
- expect(markdown).not.toContain("Notebook source");
- expect(markdown).not.toContain("Current errors");
});
+});
- it("includes current errors as plain text without notebook source", () => {
+describe("formatErrorsSection", () => {
+ it("wraps errors in a collapsible section without cell source", () => {
const errors: CellErrorEntry[] = [
{
cellId: cellId("cell-1"),
@@ -110,38 +108,19 @@ describe("buildIssueDetails", () => {
'<span class="gr">ValueError</span>: <span class="n">bad value</span>',
},
];
- const markdown = buildIssueDetails({ environment, errors });
- expect(markdown).toContain("<summary>Current errors</summary>");
+ const markdown = formatErrorsSection(errors);
+ expect(markdown).toContain("<summary>Errors</summary>");
+ expect(markdown).toContain("```text\n");
expect(markdown).toContain("ValueError: bad value");
expect(markdown).not.toContain("password");
});
+});
- it("includes notebook source under its basename when provided", () => {
- const markdown = buildIssueDetails({
- environment,
- errors: [],
- notebook: {
- filename: "/project/example.py",
- contents: "x = 1",
- },
- });
- expect(markdown).toContain(
- "<summary>Notebook source: example.py</summary>",
- );
- expect(markdown).toContain("x = 1");
- });
-
- it("escapes the summary label as text", () => {
- const markdown = buildIssueDetails({
- environment,
- errors: [],
- notebook: {
- filename: "/project/<script>.py",
- contents: "x = 1",
- },
- });
- expect(markdown).toContain("&lt;script&gt;.py");
- expect(markdown).not.toContain("<script>.py");
+describe("formatCodeSection", () => {
+ it("wraps the code in a collapsible python section", () => {
+ const markdown = formatCodeSection("import marimo");
+ expect(markdown).toContain("<summary>Code</summary>");
+ expect(markdown).toContain("```python\nimport marimo");
});
});
@@ -149,25 +128,48 @@ describe("buildBugReportUrl", () => {
const baseUrl =
"https://github.com/marimo-team/marimo/issues/new?template=bug_report.yaml";
- it("prefills the env field with the encoded issue details", () => {
- const url = buildBugReportUrl(baseUrl, "hello world");
- expect(url).toBe(`${baseUrl}&env=hello%20world`);
+ it("prefills each field keyed by its template id", () => {
+ const { url, omitted } = buildBugReportUrl(baseUrl, {
+ env: "hello world",
+ "bug-description": "boom",
+ });
+ expect(url).toBe(`${baseUrl}&env=hello%20world&bug-description=boom`);
+ expect(omitted).toEqual([]);
});
- it("appends env with a query separator when the base URL has none", () => {
- const url = buildBugReportUrl("https://example.com/new", "x");
+ it("appends fields with a query separator when the base URL has none", () => {
+ const { url } = buildBugReportUrl("https://example.com/new", { env: "x" });
expect(url).toBe("https://example.com/new?env=x");
});
+ it("skips empty fields", () => {
+ const { url } = buildBugReportUrl(baseUrl, {
+ env: "x",
+ "bug-description": "",
+ });
+ expect(url).toBe(`${baseUrl}&env=x`);
+ expect(url).not.toContain("bug-description");
+ });
+
+ it("returns the base URL when no fields have content", () => {
+ const { url } = buildBugReportUrl(baseUrl, { env: "" });
+ expect(url).toBe(baseUrl);
+ });
+
it("encodes markdown so it survives as a single query param", () => {
- const details = buildIssueDetails({ environment, errors: [] });
- const url = buildBugReportUrl(baseUrl, details);
+ const details = formatEnvironmentSection(environment);
+ const { url } = buildBugReportUrl(baseUrl, { env: details });
expect(url).toContain("&env=");
expect(new URL(url).searchParams.get("env")).toBe(details);
});
- it("falls back to the plain base URL when the prefill exceeds the cap", () => {
+ it("keeps earlier fields and omits only the oversized later one", () => {
const huge = "x".repeat(MAX_PREFILL_URL_LENGTH);
- expect(buildBugReportUrl(baseUrl, huge)).toBe(baseUrl);
+ const { url, omitted } = buildBugReportUrl(baseUrl, {
+ env: "small",
+ "reproduction-code": huge,
+ });
+ expect(url).toBe(`${baseUrl}&env=small`);
+ expect(omitted).toEqual(["reproduction-code"]);
});
});
diff --git a/frontend/src/core/diagnostics/issue-details.ts b/frontend/src/core/diagnostics/issue-details.ts
index 73e461d254..9d52289fc7 100644
--- a/frontend/src/core/diagnostics/issue-details.ts
+++ b/frontend/src/core/diagnostics/issue-details.ts
@@ -5,7 +5,6 @@ import {
formatCellError,
} from "@/core/errors/error-entries";
import type { EnvironmentInfo } from "@/core/network/types";
-import { Paths } from "@/utils/paths";
import { Strings } from "@/utils/strings";
/**
@@ -23,12 +22,6 @@ export interface NotebookSource {
contents: string;
}
-export interface IssueDetailsInput {
- environment: EnvironmentDiagnostics;
- errors: CellErrorEntry[];
- notebook?: NotebookSource;
-}
-
/**
* Replace the server-detected browser with the active browser's user agent.
*
@@ -82,17 +75,35 @@ export function markdownCodeFence(language: string, contents: string): string {
export const MAX_PREFILL_URL_LENGTH = 6000;
/**
- * Build a bug-report URL with `issueDetails` prefilled into the form's `env`
- * field. Falls back to `baseUrl` unchanged when the prefilled URL would exceed
- * `MAX_PREFILL_URL_LENGTH`.
+ * Build a bug-report URL with `fields` prefilled into the issue form, keyed by
+ * each field's template `id`. Fields are added greedily in order; any that
+ * would push the URL past `MAX_PREFILL_URL_LENGTH` are skipped and returned in
+ * `omitted`, so an oversized later field never discards the ones before it.
*/
export function buildBugReportUrl(
baseUrl: string,
- issueDetails: string,
-): string {
+ fields: Record<string, string>,
+): { url: string; omitted: string[] } {
const separator = baseUrl.includes("?") ? "&" : "?";
- const prefilled = `${baseUrl}${separator}env=${encodeURIComponent(issueDetails)}`;
- return prefilled.length > MAX_PREFILL_URL_LENGTH ? baseUrl : prefilled;
+ const omitted: string[] = [];
+ let url = baseUrl;
+ let added = 0;
+
+ for (const [key, value] of Object.entries(fields)) {
+ if (value.length === 0) {
+ continue;
+ }
+ const param = `${key}=${encodeURIComponent(value)}`;
+ const candidate = `${url}${added === 0 ? separator : "&"}${param}`;
+ if (candidate.length > MAX_PREFILL_URL_LENGTH) {
+ omitted.push(key);
+ continue;
+ }
+ url = candidate;
+ added += 1;
+ }
+
+ return { url, omitted };
}
function detailsSection(summary: string, body: string): string {
@@ -106,34 +117,34 @@ function detailsSection(summary: string, body: string): string {
].join("\n");
}
-export function buildIssueDetails(input: IssueDetailsInput): string {
- const sections = [
- detailsSection(
- "Environment",
- markdownCodeFence("json", JSON.stringify(input.environment, null, 2)),
- ),
- ];
-
- if (input.errors.length > 0) {
- sections.push(
- detailsSection(
- "Current errors",
- markdownCodeFence(
- "text",
- input.errors.map(formatCellError).join("\n\n---\n\n"),
- ),
- ),
- );
- }
+/**
+ * Format the environment as a collapsible section for the issue form's
+ * `env` field.
+ */
+export function formatEnvironmentSection(
+ environment: EnvironmentDiagnostics,
+): string {
+ return detailsSection(
+ "Environment",
+ markdownCodeFence("json", JSON.stringify(environment, null, 2)),
+ );
+}
- if (input.notebook) {
- sections.push(
- detailsSection(
- `Notebook source: ${Paths.basename(input.notebook.filename)}`,
- markdownCodeFence("python", input.notebook.contents),
- ),
- );
- }
+/**
+ * Format cell errors as a collapsible section for the issue form's
+ * `bug-description` field.
+ */
+export function formatErrorsSection(errors: CellErrorEntry[]): string {
+ return detailsSection(
+ "Errors",
+ markdownCodeFence("text", errors.map(formatCellError).join("\n\n---\n\n")),
+ );
+}
- return sections.join("\n\n");
+/**
+ * Format notebook source as a collapsible section for the issue form's
+ * `reproduction-code` field.
+ */
+export function formatCodeSection(contents: string): string {
+ return detailsSection("Code", markdownCodeFence("python", contents));
}