Enhanced Jira integration
Browse filesX-Lovable-Edit-ID: edt-d51fc19a-4086-46de-be99-bc05aec776a6
src/routes/dashboard.branch-debug.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import { createFileRoute } from "@tanstack/react-router";
|
| 2 |
import { useState, useEffect, useRef } from "react";
|
| 3 |
-
import { GitBranch, Play, RotateCcw, Shield, ChevronLeft, ChevronRight, Check, Loader2, Sparkles, FileCode, ExternalLink, Copy, Eye, ArrowRight, Download, FileJson, FileText, Terminal, Edit3, Lock, Send, Brain, Unlock, Target, Ticket, type LucideIcon } from "lucide-react";
|
| 4 |
import { useServerFn } from "@tanstack/react-start";
|
| 5 |
import { debugBranch, debugSnippet, type DebugResult, type Suspect } from "@/server/branch-debug.functions";
|
| 6 |
import { Button } from "@/components/ui/button";
|
|
@@ -905,22 +905,43 @@ function StatCell({ label, value, highlight }: { label: string; value: number; h
|
|
| 905 |
type JiraConfig = {
|
| 906 |
baseUrl: string;
|
| 907 |
projectKey: string;
|
|
|
|
| 908 |
assignee: string;
|
| 909 |
labels: string;
|
| 910 |
components: string;
|
|
|
|
| 911 |
};
|
| 912 |
|
| 913 |
const JIRA_CONFIG_KEY = "branchdebug.jiraConfig";
|
| 914 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 915 |
function loadJiraConfig(): JiraConfig {
|
| 916 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 917 |
try {
|
| 918 |
const raw = localStorage.getItem(JIRA_CONFIG_KEY);
|
| 919 |
-
if (raw) return {
|
| 920 |
} catch {}
|
| 921 |
-
// migrate old key
|
| 922 |
const oldBase = localStorage.getItem("branchdebug.jiraBaseUrl") || "";
|
| 923 |
-
return { baseUrl: oldBase
|
| 924 |
}
|
| 925 |
|
| 926 |
function ExportButtons({ result, mode }: { result: DebugResult; mode: "diff" | "snippet" | "unknown" }) {
|
|
@@ -993,7 +1014,7 @@ function ExportButtons({ result, mode }: { result: DebugResult; mode: "diff" | "
|
|
| 993 |
download(`branchdebug-report-${stamp}.md`, lines.join("\n"), "text/markdown");
|
| 994 |
};
|
| 995 |
|
| 996 |
-
const
|
| 997 |
const body: string[] = [];
|
| 998 |
body.push(`*Mode:* ${mode === "snippet" ? "Code snippet" : mode === "diff" ? "Git diff" : "Unknown"}`);
|
| 999 |
body.push(`*Generated:* ${new Date().toLocaleString()}`);
|
|
@@ -1028,38 +1049,76 @@ function ExportButtons({ result, mode }: { result: DebugResult; mode: "diff" | "
|
|
| 1028 |
return body.join("\n");
|
| 1029 |
};
|
| 1030 |
|
| 1031 |
-
const
|
| 1032 |
-
|
| 1033 |
-
|
| 1034 |
-
|
| 1035 |
-
|
| 1036 |
-
|
| 1037 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1038 |
|
|
|
|
|
|
|
| 1039 |
const top = result.suspects[0];
|
| 1040 |
const summary = top
|
| 1041 |
? `BranchDebug: ${top.changeSummary} (${top.filePath})`
|
| 1042 |
: `BranchDebug: ${(result.summary || "Root-cause report").slice(0, 80)}`;
|
| 1043 |
-
|
| 1044 |
-
const description = buildJiraDescription();
|
| 1045 |
-
try {
|
| 1046 |
-
await navigator.clipboard.writeText(description);
|
| 1047 |
-
toast.success("Ticket description copied — paste into Jira");
|
| 1048 |
-
} catch {
|
| 1049 |
-
toast.message("Could not copy automatically — paste manually in Jira");
|
| 1050 |
-
}
|
| 1051 |
-
|
| 1052 |
const params = new URLSearchParams();
|
| 1053 |
params.set("summary", summary);
|
|
|
|
| 1054 |
if (jira.projectKey.trim()) params.set("pid", jira.projectKey.trim());
|
|
|
|
| 1055 |
if (jira.assignee.trim()) params.set("assignee", jira.assignee.trim());
|
| 1056 |
jira.labels.split(",").map((l) => l.trim()).filter(Boolean).forEach((l) => params.append("labels", l));
|
| 1057 |
jira.components.split(",").map((c) => c.trim()).filter(Boolean).forEach((c) => params.append("components", c));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1058 |
|
| 1059 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1060 |
setJiraOpen(false);
|
| 1061 |
};
|
| 1062 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1063 |
return (
|
| 1064 |
<div className="flex items-center gap-1">
|
| 1065 |
<button
|
|
@@ -1086,11 +1145,11 @@ function ExportButtons({ result, mode }: { result: DebugResult; mode: "diff" | "
|
|
| 1086 |
|
| 1087 |
{jiraOpen && (
|
| 1088 |
<div
|
| 1089 |
-
className="fixed inset-0 z-50 bg-black/70 flex items-center justify-center p-4"
|
| 1090 |
onClick={() => setJiraOpen(false)}
|
| 1091 |
>
|
| 1092 |
<div
|
| 1093 |
-
className="w-full max-w-
|
| 1094 |
onClick={(e) => e.stopPropagation()}
|
| 1095 |
>
|
| 1096 |
<div className="flex items-center gap-2 text-[#2684ff]">
|
|
@@ -1098,35 +1157,64 @@ function ExportButtons({ result, mode }: { result: DebugResult; mode: "diff" | "
|
|
| 1098 |
<h3 className="text-sm font-mono uppercase tracking-widest">Create Jira ticket</h3>
|
| 1099 |
</div>
|
| 1100 |
<p className="text-[11px] text-muted-foreground">
|
| 1101 |
-
Optional fields
|
| 1102 |
</p>
|
| 1103 |
|
| 1104 |
-
|
| 1105 |
-
{
|
| 1106 |
-
|
| 1107 |
-
|
| 1108 |
-
|
| 1109 |
-
|
| 1110 |
-
|
| 1111 |
-
|
| 1112 |
-
|
| 1113 |
-
|
| 1114 |
-
|
| 1115 |
-
|
| 1116 |
-
|
| 1117 |
-
|
| 1118 |
-
className="mt-1 w-full h-8 px-2 rounded-md bg-[#080c10] border border-border text-xs font-mono text-foreground focus:border-[#2684ff] outline-none"
|
| 1119 |
-
/>
|
| 1120 |
-
</label>
|
| 1121 |
-
))}
|
| 1122 |
|
| 1123 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1124 |
<button
|
| 1125 |
onClick={() => setJiraOpen(false)}
|
| 1126 |
className="h-8 px-3 rounded-md border border-border text-[10px] font-mono uppercase tracking-widest text-muted-foreground hover:text-foreground"
|
| 1127 |
>
|
| 1128 |
Cancel
|
| 1129 |
</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1130 |
<button
|
| 1131 |
onClick={createJiraTicket}
|
| 1132 |
className="h-8 px-3 rounded-md bg-[#2684ff] hover:bg-[#2684ff]/90 text-white text-[10px] font-mono uppercase tracking-widest flex items-center gap-1"
|
|
|
|
| 1 |
import { createFileRoute } from "@tanstack/react-router";
|
| 2 |
import { useState, useEffect, useRef } from "react";
|
| 3 |
+
import { GitBranch, Play, RotateCcw, Shield, ChevronLeft, ChevronRight, Check, Loader2, Sparkles, FileCode, ExternalLink, Copy, Eye, ArrowRight, Download, FileJson, FileText, Terminal, Edit3, Lock, Send, Brain, Unlock, Target, Ticket, Link2, Paperclip, type LucideIcon } from "lucide-react";
|
| 4 |
import { useServerFn } from "@tanstack/react-start";
|
| 5 |
import { debugBranch, debugSnippet, type DebugResult, type Suspect } from "@/server/branch-debug.functions";
|
| 6 |
import { Button } from "@/components/ui/button";
|
|
|
|
| 905 |
type JiraConfig = {
|
| 906 |
baseUrl: string;
|
| 907 |
projectKey: string;
|
| 908 |
+
issueType: string;
|
| 909 |
assignee: string;
|
| 910 |
labels: string;
|
| 911 |
components: string;
|
| 912 |
+
descriptionTemplate: string;
|
| 913 |
};
|
| 914 |
|
| 915 |
const JIRA_CONFIG_KEY = "branchdebug.jiraConfig";
|
| 916 |
|
| 917 |
+
const DEFAULT_JIRA_TEMPLATE = `h2. Context
|
| 918 |
+
Briefly describe what you were trying to do.
|
| 919 |
+
|
| 920 |
+
h2. Steps to reproduce
|
| 921 |
+
#
|
| 922 |
+
#
|
| 923 |
+
|
| 924 |
+
h2. Expected vs actual
|
| 925 |
+
|
| 926 |
+
{{REPORT}}
|
| 927 |
+
|
| 928 |
+
h2. Notes
|
| 929 |
+
- App: BranchDebug
|
| 930 |
+
- Reporter: {{REPORTER}}
|
| 931 |
+
- Generated: {{TIMESTAMP}}`;
|
| 932 |
+
|
| 933 |
function loadJiraConfig(): JiraConfig {
|
| 934 |
+
const fallback: JiraConfig = {
|
| 935 |
+
baseUrl: "", projectKey: "", issueType: "Bug", assignee: "",
|
| 936 |
+
labels: "", components: "", descriptionTemplate: DEFAULT_JIRA_TEMPLATE,
|
| 937 |
+
};
|
| 938 |
+
if (typeof window === "undefined") return fallback;
|
| 939 |
try {
|
| 940 |
const raw = localStorage.getItem(JIRA_CONFIG_KEY);
|
| 941 |
+
if (raw) return { ...fallback, ...JSON.parse(raw) };
|
| 942 |
} catch {}
|
|
|
|
| 943 |
const oldBase = localStorage.getItem("branchdebug.jiraBaseUrl") || "";
|
| 944 |
+
return { ...fallback, baseUrl: oldBase };
|
| 945 |
}
|
| 946 |
|
| 947 |
function ExportButtons({ result, mode }: { result: DebugResult; mode: "diff" | "snippet" | "unknown" }) {
|
|
|
|
| 1014 |
download(`branchdebug-report-${stamp}.md`, lines.join("\n"), "text/markdown");
|
| 1015 |
};
|
| 1016 |
|
| 1017 |
+
const buildReportSection = () => {
|
| 1018 |
const body: string[] = [];
|
| 1019 |
body.push(`*Mode:* ${mode === "snippet" ? "Code snippet" : mode === "diff" ? "Git diff" : "Unknown"}`);
|
| 1020 |
body.push(`*Generated:* ${new Date().toLocaleString()}`);
|
|
|
|
| 1049 |
return body.join("\n");
|
| 1050 |
};
|
| 1051 |
|
| 1052 |
+
const buildJiraDescription = () => {
|
| 1053 |
+
const reporter = (typeof window !== "undefined" && (window as any).__bdReporter) || "BranchDebug user";
|
| 1054 |
+
const tpl = jira.descriptionTemplate?.includes("{{REPORT}}")
|
| 1055 |
+
? jira.descriptionTemplate
|
| 1056 |
+
: `${jira.descriptionTemplate || ""}\n\n{{REPORT}}`;
|
| 1057 |
+
return tpl
|
| 1058 |
+
.replaceAll("{{REPORT}}", buildReportSection())
|
| 1059 |
+
.replaceAll("{{TIMESTAMP}}", new Date().toLocaleString())
|
| 1060 |
+
.replaceAll("{{REPORTER}}", reporter)
|
| 1061 |
+
.replaceAll("{{MODE}}", mode);
|
| 1062 |
+
};
|
| 1063 |
|
| 1064 |
+
const buildJiraUrl = () => {
|
| 1065 |
+
const base = jira.baseUrl.replace(/\/$/, "");
|
| 1066 |
const top = result.suspects[0];
|
| 1067 |
const summary = top
|
| 1068 |
? `BranchDebug: ${top.changeSummary} (${top.filePath})`
|
| 1069 |
: `BranchDebug: ${(result.summary || "Root-cause report").slice(0, 80)}`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1070 |
const params = new URLSearchParams();
|
| 1071 |
params.set("summary", summary);
|
| 1072 |
+
params.set("description", buildJiraDescription());
|
| 1073 |
if (jira.projectKey.trim()) params.set("pid", jira.projectKey.trim());
|
| 1074 |
+
if (jira.issueType.trim()) params.set("issuetype", jira.issueType.trim());
|
| 1075 |
if (jira.assignee.trim()) params.set("assignee", jira.assignee.trim());
|
| 1076 |
jira.labels.split(",").map((l) => l.trim()).filter(Boolean).forEach((l) => params.append("labels", l));
|
| 1077 |
jira.components.split(",").map((c) => c.trim()).filter(Boolean).forEach((c) => params.append("components", c));
|
| 1078 |
+
return `${base}/secure/CreateIssue!default.jspa?${params.toString()}`;
|
| 1079 |
+
};
|
| 1080 |
+
|
| 1081 |
+
const persistJira = () => {
|
| 1082 |
+
const next = { ...jira, baseUrl: jira.baseUrl.replace(/\/$/, "") };
|
| 1083 |
+
localStorage.setItem(JIRA_CONFIG_KEY, JSON.stringify(next));
|
| 1084 |
+
};
|
| 1085 |
|
| 1086 |
+
const createJiraTicket = async () => {
|
| 1087 |
+
if (!jira.baseUrl) { toast.error("Jira base URL is required"); return; }
|
| 1088 |
+
persistJira();
|
| 1089 |
+
// Also download the report files so the user can attach them after Jira opens
|
| 1090 |
+
exportMarkdown();
|
| 1091 |
+
exportJson();
|
| 1092 |
+
try {
|
| 1093 |
+
await navigator.clipboard.writeText(buildJiraDescription());
|
| 1094 |
+
toast.success("Description copied · .md + .json downloaded — attach in Jira");
|
| 1095 |
+
} catch {
|
| 1096 |
+
toast.message("Description ready — attach the downloaded .md/.json in Jira");
|
| 1097 |
+
}
|
| 1098 |
+
window.open(buildJiraUrl(), "_blank", "noopener,noreferrer");
|
| 1099 |
setJiraOpen(false);
|
| 1100 |
};
|
| 1101 |
|
| 1102 |
+
const copyJiraLink = async () => {
|
| 1103 |
+
if (!jira.baseUrl) { toast.error("Jira base URL is required"); return; }
|
| 1104 |
+
persistJira();
|
| 1105 |
+
try {
|
| 1106 |
+
await navigator.clipboard.writeText(buildJiraUrl());
|
| 1107 |
+
toast.success("Jira create-issue link copied to clipboard");
|
| 1108 |
+
} catch {
|
| 1109 |
+
toast.error("Could not copy link");
|
| 1110 |
+
}
|
| 1111 |
+
};
|
| 1112 |
+
|
| 1113 |
+
const textFields = [
|
| 1114 |
+
{ key: "baseUrl", label: "Base URL *", placeholder: "https://acme.atlassian.net" },
|
| 1115 |
+
{ key: "projectKey", label: "Project key / ID", placeholder: "ENG or 10001" },
|
| 1116 |
+
{ key: "issueType", label: "Issue type", placeholder: "Bug, Task, Story, Incident" },
|
| 1117 |
+
{ key: "assignee", label: "Assignee (username / accountId)", placeholder: "jdoe" },
|
| 1118 |
+
{ key: "labels", label: "Labels (comma-separated)", placeholder: "bug, regression, branch-debug" },
|
| 1119 |
+
{ key: "components", label: "Components (comma-separated)", placeholder: "API, Auth" },
|
| 1120 |
+
] as const;
|
| 1121 |
+
|
| 1122 |
return (
|
| 1123 |
<div className="flex items-center gap-1">
|
| 1124 |
<button
|
|
|
|
| 1145 |
|
| 1146 |
{jiraOpen && (
|
| 1147 |
<div
|
| 1148 |
+
className="fixed inset-0 z-50 bg-black/70 flex items-center justify-center p-4 overflow-y-auto"
|
| 1149 |
onClick={() => setJiraOpen(false)}
|
| 1150 |
>
|
| 1151 |
<div
|
| 1152 |
+
className="w-full max-w-lg my-8 bg-[#0d1520] border border-border rounded-lg p-5 space-y-3"
|
| 1153 |
onClick={(e) => e.stopPropagation()}
|
| 1154 |
>
|
| 1155 |
<div className="flex items-center gap-2 text-[#2684ff]">
|
|
|
|
| 1157 |
<h3 className="text-sm font-mono uppercase tracking-widest">Create Jira ticket</h3>
|
| 1158 |
</div>
|
| 1159 |
<p className="text-[11px] text-muted-foreground">
|
| 1160 |
+
Optional fields pre-fill the new issue. Saved locally. Use {"{{REPORT}}"}, {"{{TIMESTAMP}}"}, {"{{REPORTER}}"}, {"{{MODE}}"} in the template.
|
| 1161 |
</p>
|
| 1162 |
|
| 1163 |
+
<div className="grid grid-cols-2 gap-2">
|
| 1164 |
+
{textFields.map((f) => (
|
| 1165 |
+
<label key={f.key} className={f.key === "baseUrl" ? "col-span-2 block" : "block"}>
|
| 1166 |
+
<span className="text-[10px] font-mono uppercase tracking-widest text-muted-foreground">{f.label}</span>
|
| 1167 |
+
<input
|
| 1168 |
+
type="text"
|
| 1169 |
+
value={jira[f.key]}
|
| 1170 |
+
onChange={(e) => setJira({ ...jira, [f.key]: e.target.value })}
|
| 1171 |
+
placeholder={f.placeholder}
|
| 1172 |
+
className="mt-1 w-full h-8 px-2 rounded-md bg-[#080c10] border border-border text-xs font-mono text-foreground focus:border-[#2684ff] outline-none"
|
| 1173 |
+
/>
|
| 1174 |
+
</label>
|
| 1175 |
+
))}
|
| 1176 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1177 |
|
| 1178 |
+
<label className="block">
|
| 1179 |
+
<div className="flex items-center justify-between">
|
| 1180 |
+
<span className="text-[10px] font-mono uppercase tracking-widest text-muted-foreground">Description template</span>
|
| 1181 |
+
<button
|
| 1182 |
+
type="button"
|
| 1183 |
+
onClick={() => setJira({ ...jira, descriptionTemplate: DEFAULT_JIRA_TEMPLATE })}
|
| 1184 |
+
className="text-[10px] font-mono uppercase tracking-widest text-muted-foreground hover:text-[#2684ff]"
|
| 1185 |
+
>
|
| 1186 |
+
Reset
|
| 1187 |
+
</button>
|
| 1188 |
+
</div>
|
| 1189 |
+
<textarea
|
| 1190 |
+
value={jira.descriptionTemplate}
|
| 1191 |
+
onChange={(e) => setJira({ ...jira, descriptionTemplate: e.target.value })}
|
| 1192 |
+
rows={6}
|
| 1193 |
+
className="mt-1 w-full px-2 py-1.5 rounded-md bg-[#080c10] border border-border text-xs font-mono text-foreground focus:border-[#2684ff] outline-none resize-y"
|
| 1194 |
+
/>
|
| 1195 |
+
</label>
|
| 1196 |
+
|
| 1197 |
+
<div className="rounded-md border border-border bg-[#080c10] p-2 flex items-start gap-2">
|
| 1198 |
+
<Paperclip className="h-3 w-3 text-[#2684ff] mt-0.5 flex-shrink-0" />
|
| 1199 |
+
<p className="text-[10px] text-muted-foreground leading-relaxed">
|
| 1200 |
+
Jira's web URL doesn't support direct file attachments. When you click <strong className="text-foreground">Open in Jira</strong>, the Markdown + JSON reports are auto-downloaded so you can drag-drop them onto the new issue.
|
| 1201 |
+
</p>
|
| 1202 |
+
</div>
|
| 1203 |
+
|
| 1204 |
+
<div className="flex items-center justify-end gap-2 pt-2 flex-wrap">
|
| 1205 |
<button
|
| 1206 |
onClick={() => setJiraOpen(false)}
|
| 1207 |
className="h-8 px-3 rounded-md border border-border text-[10px] font-mono uppercase tracking-widest text-muted-foreground hover:text-foreground"
|
| 1208 |
>
|
| 1209 |
Cancel
|
| 1210 |
</button>
|
| 1211 |
+
<button
|
| 1212 |
+
onClick={copyJiraLink}
|
| 1213 |
+
className="h-8 px-3 rounded-md border border-[#2684ff]/40 bg-[#2684ff]/10 hover:bg-[#2684ff]/20 text-[#2684ff] text-[10px] font-mono uppercase tracking-widest flex items-center gap-1"
|
| 1214 |
+
title="Copy the full Jira create-issue URL with all parameters"
|
| 1215 |
+
>
|
| 1216 |
+
<Link2 className="h-3 w-3" /> Copy link
|
| 1217 |
+
</button>
|
| 1218 |
<button
|
| 1219 |
onClick={createJiraTicket}
|
| 1220 |
className="h-8 px-3 rounded-md bg-[#2684ff] hover:bg-[#2684ff]/90 text-white text-[10px] font-mono uppercase tracking-widest flex items-center gap-1"
|