@kud/jira-cli 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/dist/{chunk-RTBMVYZM.js → chunk-QEOE2RPV.js} +50 -1
- package/dist/index.js +4 -23
- package/dist/tui-TWKZI63D.js +825 -0
- package/package.json +2 -2
- package/dist/tui-IET37PRI.js +0 -467
|
@@ -0,0 +1,825 @@
|
|
|
1
|
+
import {
|
|
2
|
+
context,
|
|
3
|
+
looksLikeJql,
|
|
4
|
+
searchJql
|
|
5
|
+
} from "./chunk-QEOE2RPV.js";
|
|
6
|
+
|
|
7
|
+
// src/tui/index.tsx
|
|
8
|
+
import { render } from "ink";
|
|
9
|
+
|
|
10
|
+
// src/tui/app.tsx
|
|
11
|
+
import { execFile } from "child_process";
|
|
12
|
+
import { Alert, ConfirmInput, Select, Spinner, TextInput as TextInput2 } from "@kud/ink-ui";
|
|
13
|
+
import { Box as Box2, Text as Text2, useApp, useInput as useInput2, useStdout } from "ink";
|
|
14
|
+
import { useCallback, useEffect as useEffect2, useState as useState2 } from "react";
|
|
15
|
+
import { isJiraApiError } from "@kud/jira";
|
|
16
|
+
import { IssueDetailView } from "@kud/jira-ink";
|
|
17
|
+
|
|
18
|
+
// src/tui/list.tsx
|
|
19
|
+
import {
|
|
20
|
+
colors,
|
|
21
|
+
FooterHints,
|
|
22
|
+
Panel,
|
|
23
|
+
Pill,
|
|
24
|
+
pillWidth,
|
|
25
|
+
SelectableRow,
|
|
26
|
+
Tabs,
|
|
27
|
+
TextInput,
|
|
28
|
+
useListCursor,
|
|
29
|
+
useTabs
|
|
30
|
+
} from "@kud/ink-ui";
|
|
31
|
+
import { Box, Text, useInput } from "ink";
|
|
32
|
+
import { useEffect, useMemo, useState } from "react";
|
|
33
|
+
|
|
34
|
+
// src/tui/board.ts
|
|
35
|
+
var TABS = [
|
|
36
|
+
{ value: "todo", label: "To do" },
|
|
37
|
+
{ value: "doing", label: "In progress" },
|
|
38
|
+
{ value: "done", label: "Done" }
|
|
39
|
+
];
|
|
40
|
+
var tabOf = (category) => category === "new" ? "todo" : category === "done" ? "done" : "doing";
|
|
41
|
+
var countsFor = (rows) => rows.reduce(
|
|
42
|
+
(acc, row) => ({
|
|
43
|
+
...acc,
|
|
44
|
+
[tabOf(row.category)]: acc[tabOf(row.category)] + 1
|
|
45
|
+
}),
|
|
46
|
+
{ todo: 0, doing: 0, done: 0 }
|
|
47
|
+
);
|
|
48
|
+
var blocksFor = (rows) => {
|
|
49
|
+
if (!rows.some((r) => r.parent))
|
|
50
|
+
return rows.map((row) => ({ kind: "issue", row }));
|
|
51
|
+
const groups = /* @__PURE__ */ new Map();
|
|
52
|
+
for (const row of rows) {
|
|
53
|
+
const key = row.parent?.key ?? null;
|
|
54
|
+
const group = groups.get(key) ?? {
|
|
55
|
+
summary: row.parent?.summary ?? "",
|
|
56
|
+
rows: []
|
|
57
|
+
};
|
|
58
|
+
group.rows.push(row);
|
|
59
|
+
groups.set(key, group);
|
|
60
|
+
}
|
|
61
|
+
const ordered = [...groups.entries()].sort(
|
|
62
|
+
([a], [b]) => a === null ? 1 : b === null ? -1 : 0
|
|
63
|
+
);
|
|
64
|
+
return ordered.flatMap(([key, group]) => [
|
|
65
|
+
{ kind: "header", key, summary: key ? group.summary : "No epic" },
|
|
66
|
+
...group.rows.map((row) => ({ kind: "issue", row }))
|
|
67
|
+
]);
|
|
68
|
+
};
|
|
69
|
+
var blockIndexOfIssue = (blocks, issueIndex) => {
|
|
70
|
+
let seen = -1;
|
|
71
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
72
|
+
if (blocks[i].kind === "issue" && ++seen === issueIndex) return i;
|
|
73
|
+
}
|
|
74
|
+
return 0;
|
|
75
|
+
};
|
|
76
|
+
var priorityGlyph = (name) => {
|
|
77
|
+
const n = (name ?? "").trim().toLowerCase();
|
|
78
|
+
if (/highest|high|critical|blocker|urgent|^p[01]$/.test(n)) return "\u25B2";
|
|
79
|
+
if (/lowest|low|minor|trivial|^p[3-5]$/.test(n)) return "\u25BC";
|
|
80
|
+
return " ";
|
|
81
|
+
};
|
|
82
|
+
var UNITS = [
|
|
83
|
+
[60, "m"],
|
|
84
|
+
[60, "h"],
|
|
85
|
+
[24, "d"],
|
|
86
|
+
[7, "w"]
|
|
87
|
+
];
|
|
88
|
+
var relativeAge = (iso, now = Date.now()) => {
|
|
89
|
+
const then = Date.parse(iso);
|
|
90
|
+
if (Number.isNaN(then)) return "";
|
|
91
|
+
let value = Math.max(0, Math.round((now - then) / 1e3));
|
|
92
|
+
let unit = "s";
|
|
93
|
+
for (const [size, next] of UNITS) {
|
|
94
|
+
if (value < size) break;
|
|
95
|
+
value = Math.round(value / size);
|
|
96
|
+
unit = next;
|
|
97
|
+
}
|
|
98
|
+
return `${value}${unit}`;
|
|
99
|
+
};
|
|
100
|
+
var pillVariantFor = (type) => {
|
|
101
|
+
const t = type.toLowerCase();
|
|
102
|
+
if (t === "epic") return "group";
|
|
103
|
+
if (t === "bug") return "error";
|
|
104
|
+
if (t === "story") return "info";
|
|
105
|
+
return "muted";
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
// src/tui/list.tsx
|
|
109
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
110
|
+
var CHROME = 9;
|
|
111
|
+
var LEGEND = [
|
|
112
|
+
["\u25B2", "high priority"],
|
|
113
|
+
["\u25BC", "low priority"],
|
|
114
|
+
["\u2500\u2500 epic \u2500\u2500", "the parent the rows beneath hang under"],
|
|
115
|
+
["story \xB7 bug \xB7 task", "issue type"],
|
|
116
|
+
["2d", "time since last update"],
|
|
117
|
+
[
|
|
118
|
+
"To do \xB7 In progress \xB7 Done",
|
|
119
|
+
"status category \u2014 not any one board's column"
|
|
120
|
+
]
|
|
121
|
+
];
|
|
122
|
+
var windowFor = (focus, total, size) => {
|
|
123
|
+
const start = Math.max(
|
|
124
|
+
0,
|
|
125
|
+
Math.min(focus - Math.floor(size / 2), total - size)
|
|
126
|
+
);
|
|
127
|
+
return { start, end: start + size };
|
|
128
|
+
};
|
|
129
|
+
var IssueList = ({
|
|
130
|
+
rows,
|
|
131
|
+
viewer,
|
|
132
|
+
loadedAt,
|
|
133
|
+
scope,
|
|
134
|
+
showingAll,
|
|
135
|
+
searchError,
|
|
136
|
+
width,
|
|
137
|
+
height,
|
|
138
|
+
onOpen,
|
|
139
|
+
onToggleAll,
|
|
140
|
+
onRefresh,
|
|
141
|
+
onSearch,
|
|
142
|
+
onClearSearch
|
|
143
|
+
}) => {
|
|
144
|
+
const [legend, setLegend] = useState(false);
|
|
145
|
+
const [search, setSearch] = useState({
|
|
146
|
+
open: false,
|
|
147
|
+
draft: "",
|
|
148
|
+
mode: "auto"
|
|
149
|
+
});
|
|
150
|
+
const [now, setNow] = useState(Date.now);
|
|
151
|
+
useEffect(() => {
|
|
152
|
+
const tick = setInterval(() => setNow(Date.now()), 3e4);
|
|
153
|
+
return () => clearInterval(tick);
|
|
154
|
+
}, []);
|
|
155
|
+
const narrowed = useMemo(() => {
|
|
156
|
+
if (!search.open || modeOf(search) === "jql" || !search.draft.trim())
|
|
157
|
+
return rows;
|
|
158
|
+
const words = search.draft.trim().toLowerCase();
|
|
159
|
+
return rows.filter(
|
|
160
|
+
(r) => `${r.key} ${r.summary}`.toLowerCase().includes(words)
|
|
161
|
+
);
|
|
162
|
+
}, [rows, search]);
|
|
163
|
+
const counts = countsFor(narrowed);
|
|
164
|
+
const tabItems = TABS.map((t) => ({ ...t, count: counts[t.value] }));
|
|
165
|
+
const listFocused = !search.open && !legend;
|
|
166
|
+
const { active } = useTabs(tabItems, {
|
|
167
|
+
initial: "doing",
|
|
168
|
+
isActive: listFocused
|
|
169
|
+
});
|
|
170
|
+
const tab = active ?? "doing";
|
|
171
|
+
const blocks = useMemo(
|
|
172
|
+
() => blocksFor(narrowed.filter((r) => tabOf(r.category) === tab)),
|
|
173
|
+
[narrowed, tab]
|
|
174
|
+
);
|
|
175
|
+
const issues = blocks.filter(
|
|
176
|
+
(b) => b.kind === "issue"
|
|
177
|
+
);
|
|
178
|
+
const { cursor, setCursor } = useListCursor(issues.length, {
|
|
179
|
+
vimKeys: true,
|
|
180
|
+
isActive: listFocused
|
|
181
|
+
});
|
|
182
|
+
useEffect(() => setCursor(0), [tab, setCursor]);
|
|
183
|
+
useInput((input, key) => {
|
|
184
|
+
if (search.open) {
|
|
185
|
+
if (key.escape) setSearch((s) => ({ ...s, open: false }));
|
|
186
|
+
if (key.tab)
|
|
187
|
+
setSearch((s) => ({
|
|
188
|
+
...s,
|
|
189
|
+
mode: modeOf(s) === "jql" ? "text" : "jql"
|
|
190
|
+
}));
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (legend) {
|
|
194
|
+
if (input === "?" || key.escape) setLegend(false);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (key.return && issues[cursor]) onOpen(issues[cursor].row.key);
|
|
198
|
+
if (input === "/")
|
|
199
|
+
setSearch((s) => ({
|
|
200
|
+
...s,
|
|
201
|
+
open: true,
|
|
202
|
+
draft: scope.kind === "search" ? scope.query : s.draft
|
|
203
|
+
}));
|
|
204
|
+
if (input === "?") setLegend(true);
|
|
205
|
+
if (input === "a") onToggleAll();
|
|
206
|
+
if (input === "r") onRefresh();
|
|
207
|
+
if (key.escape && scope.kind === "search") onClearSearch();
|
|
208
|
+
});
|
|
209
|
+
const searching = search.open || scope.kind === "search";
|
|
210
|
+
const chrome = CHROME + (searching ? 1 : 0) + (searchError ? 1 : 0);
|
|
211
|
+
const size = Math.max(3, height - chrome);
|
|
212
|
+
const focus = blockIndexOfIssue(blocks, cursor);
|
|
213
|
+
const { start, end } = windowFor(focus, blocks.length, size);
|
|
214
|
+
const keyWidth = Math.max(8, ...narrowed.map((r) => r.key.length));
|
|
215
|
+
const typeWidth = Math.max(
|
|
216
|
+
0,
|
|
217
|
+
...narrowed.map((r) => pillWidth(r.type.toLowerCase()))
|
|
218
|
+
);
|
|
219
|
+
const scopeLabel = scope.kind === "mine" ? `@${viewer}` : scope.mode === "jql" ? "jql" : `\u201C${scope.query}\u201D`;
|
|
220
|
+
const countLabel = search.open && narrowed.length !== rows.length ? `${narrowed.length} of ${rows.length}` : `${rows.length} ${rows.length === 1 ? "item" : "items"}`;
|
|
221
|
+
const hints = search.open ? [
|
|
222
|
+
["enter", "run"],
|
|
223
|
+
["\u21E5", modeOf(search) === "jql" ? "as plain words" : "as jql"],
|
|
224
|
+
["esc", "cancel"]
|
|
225
|
+
] : legend ? [["?", "close"]] : [
|
|
226
|
+
["\u2191\u2193", "move"],
|
|
227
|
+
["\u21E5", "tab"],
|
|
228
|
+
["enter", "open"],
|
|
229
|
+
["/", scope.kind === "search" ? "edit" : "search"],
|
|
230
|
+
...scope.kind === "search" ? [["esc", "clear"]] : [["a", showingAll ? "recent only" : "everything"]],
|
|
231
|
+
["r", "refresh"],
|
|
232
|
+
["?", "legend"],
|
|
233
|
+
["q", "quit"]
|
|
234
|
+
];
|
|
235
|
+
return /* @__PURE__ */ jsxs(Panel, { width, height, children: [
|
|
236
|
+
/* @__PURE__ */ jsxs(Box, { paddingLeft: 1, children: [
|
|
237
|
+
/* @__PURE__ */ jsx(Text, { bold: true, children: "\u{1F3AB} Jira" }),
|
|
238
|
+
/* @__PURE__ */ jsxs(Text, { dimColor: true, children: [
|
|
239
|
+
" ",
|
|
240
|
+
countLabel,
|
|
241
|
+
" \xB7 ",
|
|
242
|
+
scopeLabel,
|
|
243
|
+
" \xB7 updated",
|
|
244
|
+
" ",
|
|
245
|
+
relativeAge(new Date(loadedAt).toISOString(), now),
|
|
246
|
+
" ago"
|
|
247
|
+
] })
|
|
248
|
+
] }),
|
|
249
|
+
search.open ? /* @__PURE__ */ jsxs(Box, { paddingRight: 1, children: [
|
|
250
|
+
/* @__PURE__ */ jsx(Box, { flexShrink: 0, children: /* @__PURE__ */ jsx(Text, { color: colors.accent, children: " / " }) }),
|
|
251
|
+
/* @__PURE__ */ jsx(Box, { flexGrow: 1, children: /* @__PURE__ */ jsx(
|
|
252
|
+
TextInput,
|
|
253
|
+
{
|
|
254
|
+
defaultValue: search.draft,
|
|
255
|
+
placeholder: "words, or JQL",
|
|
256
|
+
onChange: (draft) => setSearch((s) => ({ ...s, draft })),
|
|
257
|
+
onSubmit: (query) => {
|
|
258
|
+
setSearch((s) => ({ ...s, open: false, draft: query }));
|
|
259
|
+
if (query.trim()) onSearch(query, search.mode);
|
|
260
|
+
else onClearSearch();
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
) }),
|
|
264
|
+
/* @__PURE__ */ jsx(Box, { flexShrink: 0, children: /* @__PURE__ */ jsx(Text, { dimColor: true, children: modeOf(search) === "jql" ? "JQL" : "plain" }) })
|
|
265
|
+
] }) : scope.kind === "search" ? /* @__PURE__ */ jsxs(Box, { paddingRight: 1, children: [
|
|
266
|
+
/* @__PURE__ */ jsx(Box, { flexShrink: 0, children: /* @__PURE__ */ jsx(Text, { color: colors.accent, children: " / " }) }),
|
|
267
|
+
/* @__PURE__ */ jsx(Box, { flexGrow: 1, children: /* @__PURE__ */ jsx(Text, { wrap: "truncate-end", children: scope.query }) }),
|
|
268
|
+
/* @__PURE__ */ jsx(Box, { flexShrink: 0, children: /* @__PURE__ */ jsx(Text, { dimColor: true, children: scope.mode === "jql" ? "JQL" : "plain" }) })
|
|
269
|
+
] }) : null,
|
|
270
|
+
searchError ? /* @__PURE__ */ jsxs(Text, { color: colors.error, children: [
|
|
271
|
+
" \u2717 ",
|
|
272
|
+
searchError
|
|
273
|
+
] }) : null,
|
|
274
|
+
/* @__PURE__ */ jsx(Box, { paddingLeft: 2, children: /* @__PURE__ */ jsx(Tabs, { active: tab, items: tabItems }) }),
|
|
275
|
+
/* @__PURE__ */ jsx(
|
|
276
|
+
Box,
|
|
277
|
+
{
|
|
278
|
+
flexDirection: "column",
|
|
279
|
+
marginTop: 1,
|
|
280
|
+
height: size,
|
|
281
|
+
paddingRight: 1,
|
|
282
|
+
children: legend ? LEGEND.map(([glyph, meaning]) => /* @__PURE__ */ jsxs(Box, { paddingLeft: 4, children: [
|
|
283
|
+
/* @__PURE__ */ jsx(Box, { width: 28, flexShrink: 0, children: /* @__PURE__ */ jsx(Text, { color: colors.accent, children: glyph }) }),
|
|
284
|
+
/* @__PURE__ */ jsx(Text, { dimColor: true, children: meaning })
|
|
285
|
+
] }, glyph)) : issues.length === 0 ? /* @__PURE__ */ jsx(Box, { paddingLeft: 4, children: /* @__PURE__ */ jsx(Text, { dimColor: true, children: emptyHint(tab, counts, showingAll, scope) }) }) : blocks.slice(start, end).map(
|
|
286
|
+
(block, i) => block.kind === "header" ? /* @__PURE__ */ jsx(Box, { paddingLeft: 4, children: /* @__PURE__ */ jsx(Text, { dimColor: true, children: rule(
|
|
287
|
+
block.key ? `${block.summary} \xB7 ${block.key}` : block.summary,
|
|
288
|
+
width - 7
|
|
289
|
+
) }) }, `h:${block.key ?? "none"}`) : /* @__PURE__ */ jsxs(SelectableRow, { active: start + i === focus, children: [
|
|
290
|
+
/* @__PURE__ */ jsx(Box, { flexShrink: 0, width: 2, children: /* @__PURE__ */ jsx(
|
|
291
|
+
Text,
|
|
292
|
+
{
|
|
293
|
+
color: priorityGlyph(block.row.priority) === "\u25B2" ? colors.warning : colors.muted,
|
|
294
|
+
children: priorityGlyph(block.row.priority)
|
|
295
|
+
}
|
|
296
|
+
) }),
|
|
297
|
+
/* @__PURE__ */ jsx(Box, { flexShrink: 0, width: keyWidth + 2, children: /* @__PURE__ */ jsx(Text, { color: colors.accent, bold: start + i === focus, children: block.row.key }) }),
|
|
298
|
+
/* @__PURE__ */ jsx(Box, { flexShrink: 0, width: typeWidth + 2, children: /* @__PURE__ */ jsx(Pill, { tone: "soft", variant: pillVariantFor(block.row.type), children: block.row.type.toLowerCase() }) }),
|
|
299
|
+
/* @__PURE__ */ jsx(Box, { flexGrow: 1, children: /* @__PURE__ */ jsx(Text, { wrap: "truncate-end", bold: start + i === focus, children: block.row.summary }) }),
|
|
300
|
+
/* @__PURE__ */ jsx(Box, { flexShrink: 0, width: 5, justifyContent: "flex-end", children: /* @__PURE__ */ jsx(Text, { dimColor: true, children: relativeAge(block.row.updated, now) }) })
|
|
301
|
+
] }, block.row.key)
|
|
302
|
+
)
|
|
303
|
+
}
|
|
304
|
+
),
|
|
305
|
+
/* @__PURE__ */ jsxs(Box, { marginTop: 1, paddingLeft: 2, flexDirection: "column", children: [
|
|
306
|
+
/* @__PURE__ */ jsx(Text, { dimColor: true, children: issues.length ? `${cursor + 1}/${issues.length}` : " " }),
|
|
307
|
+
/* @__PURE__ */ jsx(FooterHints, { hints })
|
|
308
|
+
] })
|
|
309
|
+
] });
|
|
310
|
+
};
|
|
311
|
+
var modeOf = (s) => s.mode === "auto" ? looksLikeJql(s.draft) ? "jql" : "text" : s.mode;
|
|
312
|
+
var rule = (label, width) => {
|
|
313
|
+
const head = `\u2500\u2500 ${label} `;
|
|
314
|
+
return head + "\u2500".repeat(Math.max(0, width - [...head].length));
|
|
315
|
+
};
|
|
316
|
+
var emptyHint = (tab, counts, showingAll, scope) => {
|
|
317
|
+
const total = counts.todo + counts.doing + counts.done;
|
|
318
|
+
if (total === 0) {
|
|
319
|
+
if (scope.kind === "search")
|
|
320
|
+
return "Nothing matches \u2014 / to edit, esc to clear.";
|
|
321
|
+
return showingAll ? "Nothing is assigned to you." : "No open issues assigned to you \u2014 press a to include everything.";
|
|
322
|
+
}
|
|
323
|
+
const elsewhere = TABS.filter((t) => t.value !== tab && counts[t.value] > 0).map((t) => `${t.label} (${counts[t.value]})`).join(", ");
|
|
324
|
+
const closed = tab === "done" && !showingAll ? " Only the last 14 days of closed work is loaded \u2014 press a for everything." : "";
|
|
325
|
+
return `Nothing here \u2014 \u21E5 to ${elsewhere}.${closed}`;
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
// src/tui/app.tsx
|
|
329
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
330
|
+
var MIN_WIDTH = 60;
|
|
331
|
+
var MIN_HEIGHT = 12;
|
|
332
|
+
var App = ({ data, initialScreen, initialKey }) => {
|
|
333
|
+
const { exit } = useApp();
|
|
334
|
+
const { stdout } = useStdout();
|
|
335
|
+
const width = stdout?.columns ?? 80;
|
|
336
|
+
const height = stdout?.rows ?? 24;
|
|
337
|
+
const [screen, setScreen] = useState2(initialScreen);
|
|
338
|
+
const [rows, setRows] = useState2(null);
|
|
339
|
+
const [viewer, setViewer] = useState2("you");
|
|
340
|
+
const [loadedAt, setLoadedAt] = useState2(Date.now);
|
|
341
|
+
const [scope, setScope] = useState2({ kind: "mine" });
|
|
342
|
+
const [searchError, setSearchError] = useState2(null);
|
|
343
|
+
const [issue, setIssue] = useState2(null);
|
|
344
|
+
const [overlay, setOverlay] = useState2({ kind: "none" });
|
|
345
|
+
const [showingAll, setShowingAll] = useState2(false);
|
|
346
|
+
const [error, setError] = useState2(null);
|
|
347
|
+
const [busy, setBusy] = useState2(null);
|
|
348
|
+
const loadList = useCallback(
|
|
349
|
+
async (all) => {
|
|
350
|
+
setError(null);
|
|
351
|
+
setRows(null);
|
|
352
|
+
setScope({ kind: "mine" });
|
|
353
|
+
setSearchError(null);
|
|
354
|
+
try {
|
|
355
|
+
setRows(await data.listIssues(all));
|
|
356
|
+
setLoadedAt(Date.now());
|
|
357
|
+
} catch (e) {
|
|
358
|
+
setError(e instanceof Error ? e.message : String(e));
|
|
359
|
+
}
|
|
360
|
+
},
|
|
361
|
+
[data]
|
|
362
|
+
);
|
|
363
|
+
const loadIssue = useCallback(
|
|
364
|
+
async (key) => {
|
|
365
|
+
setError(null);
|
|
366
|
+
setIssue(null);
|
|
367
|
+
setScreen("detail");
|
|
368
|
+
try {
|
|
369
|
+
setIssue(await data.getIssue(key));
|
|
370
|
+
} catch (e) {
|
|
371
|
+
setError(e instanceof Error ? e.message : String(e));
|
|
372
|
+
}
|
|
373
|
+
},
|
|
374
|
+
[data]
|
|
375
|
+
);
|
|
376
|
+
const runSearch = useCallback(
|
|
377
|
+
async (query, mode) => {
|
|
378
|
+
setSearchError(null);
|
|
379
|
+
try {
|
|
380
|
+
const result = await data.search(query, mode);
|
|
381
|
+
setRows(result.rows);
|
|
382
|
+
setScope({ kind: "search", query, mode: result.mode });
|
|
383
|
+
setLoadedAt(Date.now());
|
|
384
|
+
} catch (e) {
|
|
385
|
+
setSearchError(jiraMessageOf(e));
|
|
386
|
+
}
|
|
387
|
+
},
|
|
388
|
+
[data]
|
|
389
|
+
);
|
|
390
|
+
useEffect2(() => {
|
|
391
|
+
void data.me().then((me) => setViewer(me.displayName)).catch(() => {
|
|
392
|
+
});
|
|
393
|
+
}, [data]);
|
|
394
|
+
useEffect2(() => {
|
|
395
|
+
if (initialScreen === "detail" && initialKey) void loadIssue(initialKey);
|
|
396
|
+
else void loadList(false);
|
|
397
|
+
}, [initialScreen, initialKey, loadIssue, loadList]);
|
|
398
|
+
useInput2((input, key) => {
|
|
399
|
+
if (overlay.kind !== "none") return;
|
|
400
|
+
if (input === "q" || key.ctrl && input === "c") exit();
|
|
401
|
+
if (error && input === "r") {
|
|
402
|
+
if (screen === "issues") void loadList(showingAll);
|
|
403
|
+
else if (issue) void loadIssue(issue.key);
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
if (width < MIN_WIDTH || height < MIN_HEIGHT) {
|
|
407
|
+
return /* @__PURE__ */ jsxs2(Text2, { children: [
|
|
408
|
+
"Terminal too small \u2014 needs at least ",
|
|
409
|
+
MIN_WIDTH,
|
|
410
|
+
"\xD7",
|
|
411
|
+
MIN_HEIGHT,
|
|
412
|
+
", this is",
|
|
413
|
+
" ",
|
|
414
|
+
width,
|
|
415
|
+
"\xD7",
|
|
416
|
+
height,
|
|
417
|
+
"."
|
|
418
|
+
] });
|
|
419
|
+
}
|
|
420
|
+
if (error) {
|
|
421
|
+
return /* @__PURE__ */ jsxs2(Box2, { flexDirection: "column", gap: 1, children: [
|
|
422
|
+
/* @__PURE__ */ jsx2(Alert, { variant: "error", children: error }),
|
|
423
|
+
/* @__PURE__ */ jsx2(Text2, { dimColor: true, children: "r retry \xB7 q quit" })
|
|
424
|
+
] });
|
|
425
|
+
}
|
|
426
|
+
if (busy) return /* @__PURE__ */ jsx2(Spinner, { label: busy });
|
|
427
|
+
if (overlay.kind === "transition") {
|
|
428
|
+
return /* @__PURE__ */ jsxs2(Box2, { flexDirection: "column", gap: 1, children: [
|
|
429
|
+
/* @__PURE__ */ jsxs2(Text2, { bold: true, children: [
|
|
430
|
+
"Move ",
|
|
431
|
+
issue?.key,
|
|
432
|
+
" to\u2026"
|
|
433
|
+
] }),
|
|
434
|
+
/* @__PURE__ */ jsx2(
|
|
435
|
+
Select,
|
|
436
|
+
{
|
|
437
|
+
options: overlay.options.map((t) => ({
|
|
438
|
+
label: `${t.name} \u2192 ${t.to}`,
|
|
439
|
+
value: t.id
|
|
440
|
+
})),
|
|
441
|
+
onSubmit: (id) => {
|
|
442
|
+
setOverlay({ kind: "none" });
|
|
443
|
+
void (async () => {
|
|
444
|
+
setBusy("Transitioning\u2026");
|
|
445
|
+
try {
|
|
446
|
+
await data.transition(issue.key, id);
|
|
447
|
+
await loadIssue(issue.key);
|
|
448
|
+
} catch (e) {
|
|
449
|
+
setError(e instanceof Error ? e.message : String(e));
|
|
450
|
+
} finally {
|
|
451
|
+
setBusy(null);
|
|
452
|
+
}
|
|
453
|
+
})();
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
),
|
|
457
|
+
/* @__PURE__ */ jsx2(Text2, { dimColor: true, children: "esc cancel" })
|
|
458
|
+
] });
|
|
459
|
+
}
|
|
460
|
+
if (overlay.kind === "comment") {
|
|
461
|
+
return /* @__PURE__ */ jsxs2(Box2, { flexDirection: "column", gap: 1, children: [
|
|
462
|
+
/* @__PURE__ */ jsxs2(Text2, { bold: true, children: [
|
|
463
|
+
"Comment on ",
|
|
464
|
+
issue?.key
|
|
465
|
+
] }),
|
|
466
|
+
/* @__PURE__ */ jsx2(
|
|
467
|
+
TextInput2,
|
|
468
|
+
{
|
|
469
|
+
placeholder: "Markdown is supported\u2026",
|
|
470
|
+
onSubmit: (body) => {
|
|
471
|
+
setOverlay({ kind: "none" });
|
|
472
|
+
if (!body.trim()) return;
|
|
473
|
+
void (async () => {
|
|
474
|
+
setBusy("Posting\u2026");
|
|
475
|
+
try {
|
|
476
|
+
await data.comment(issue.key, body);
|
|
477
|
+
await loadIssue(issue.key);
|
|
478
|
+
} catch (e) {
|
|
479
|
+
setError(e instanceof Error ? e.message : String(e));
|
|
480
|
+
} finally {
|
|
481
|
+
setBusy(null);
|
|
482
|
+
}
|
|
483
|
+
})();
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
)
|
|
487
|
+
] });
|
|
488
|
+
}
|
|
489
|
+
if (overlay.kind === "assign") {
|
|
490
|
+
return /* @__PURE__ */ jsxs2(Box2, { flexDirection: "column", gap: 1, children: [
|
|
491
|
+
/* @__PURE__ */ jsxs2(Text2, { children: [
|
|
492
|
+
"Assign ",
|
|
493
|
+
issue?.key,
|
|
494
|
+
" to yourself?"
|
|
495
|
+
] }),
|
|
496
|
+
/* @__PURE__ */ jsx2(
|
|
497
|
+
ConfirmInput,
|
|
498
|
+
{
|
|
499
|
+
onCancel: () => setOverlay({ kind: "none" }),
|
|
500
|
+
onConfirm: () => {
|
|
501
|
+
setOverlay({ kind: "none" });
|
|
502
|
+
void (async () => {
|
|
503
|
+
setBusy("Assigning\u2026");
|
|
504
|
+
try {
|
|
505
|
+
await data.assignToMe(issue.key);
|
|
506
|
+
await loadIssue(issue.key);
|
|
507
|
+
} catch (e) {
|
|
508
|
+
setError(e instanceof Error ? e.message : String(e));
|
|
509
|
+
} finally {
|
|
510
|
+
setBusy(null);
|
|
511
|
+
}
|
|
512
|
+
})();
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
)
|
|
516
|
+
] });
|
|
517
|
+
}
|
|
518
|
+
if (screen === "detail") {
|
|
519
|
+
if (!issue) return /* @__PURE__ */ jsx2(Spinner, { label: "Loading issue\u2026" });
|
|
520
|
+
return /* @__PURE__ */ jsx2(
|
|
521
|
+
IssueDetailView,
|
|
522
|
+
{
|
|
523
|
+
issue,
|
|
524
|
+
width,
|
|
525
|
+
height,
|
|
526
|
+
onBack: () => setScreen("issues"),
|
|
527
|
+
onOpenBrowser: () => execFile(opener(), [issue.url]),
|
|
528
|
+
onAssign: () => setOverlay({ kind: "assign" }),
|
|
529
|
+
onComment: () => setOverlay({ kind: "comment" }),
|
|
530
|
+
onTransition: () => {
|
|
531
|
+
void (async () => {
|
|
532
|
+
setBusy("Loading transitions\u2026");
|
|
533
|
+
try {
|
|
534
|
+
const options = await data.getTransitions(issue.key);
|
|
535
|
+
setOverlay({ kind: "transition", options });
|
|
536
|
+
} catch (e) {
|
|
537
|
+
setError(e instanceof Error ? e.message : String(e));
|
|
538
|
+
} finally {
|
|
539
|
+
setBusy(null);
|
|
540
|
+
}
|
|
541
|
+
})();
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
);
|
|
545
|
+
}
|
|
546
|
+
if (!rows) return /* @__PURE__ */ jsx2(Spinner, { label: "Loading issues\u2026" });
|
|
547
|
+
return /* @__PURE__ */ jsx2(
|
|
548
|
+
IssueList,
|
|
549
|
+
{
|
|
550
|
+
rows,
|
|
551
|
+
viewer,
|
|
552
|
+
loadedAt,
|
|
553
|
+
scope,
|
|
554
|
+
searchError,
|
|
555
|
+
width,
|
|
556
|
+
height,
|
|
557
|
+
showingAll,
|
|
558
|
+
onOpen: (key) => void loadIssue(key),
|
|
559
|
+
onRefresh: () => void (scope.kind === "search" ? runSearch(scope.query, scope.mode) : loadList(showingAll)),
|
|
560
|
+
onSearch: (query, mode) => void runSearch(query, mode),
|
|
561
|
+
onClearSearch: () => void loadList(showingAll),
|
|
562
|
+
onToggleAll: () => {
|
|
563
|
+
const next = !showingAll;
|
|
564
|
+
setShowingAll(next);
|
|
565
|
+
void loadList(next);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
);
|
|
569
|
+
};
|
|
570
|
+
var jiraMessageOf = (e) => {
|
|
571
|
+
if (isJiraApiError(e)) {
|
|
572
|
+
if (e.status === 401 || e.status === 403)
|
|
573
|
+
return `Jira refused the request (${e.status}) \u2014 check your token.`;
|
|
574
|
+
try {
|
|
575
|
+
const body = JSON.parse(e.body);
|
|
576
|
+
if (body.errorMessages?.length) return body.errorMessages.join(" ");
|
|
577
|
+
} catch {
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
return e instanceof Error ? e.message : String(e);
|
|
581
|
+
};
|
|
582
|
+
var opener = () => process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
|
|
583
|
+
|
|
584
|
+
// src/tui/data.ts
|
|
585
|
+
import {
|
|
586
|
+
issueDetailOf,
|
|
587
|
+
transitionsOf
|
|
588
|
+
} from "@kud/jira-ink";
|
|
589
|
+
var DEFAULT_SCOPE = "(statusCategory != Done OR (statusCategory = Done AND updated >= -14d))";
|
|
590
|
+
var CATEGORIES = ["new", "indeterminate", "done"];
|
|
591
|
+
var categoryOf = (key) => CATEGORIES.find((c) => c === key) ?? "unknown";
|
|
592
|
+
var toRow = (issue) => ({
|
|
593
|
+
key: issue.key,
|
|
594
|
+
status: issue.fields.status?.name ?? "\u2014",
|
|
595
|
+
category: categoryOf(issue.fields.status?.statusCategory?.key),
|
|
596
|
+
summary: issue.fields.summary ?? "",
|
|
597
|
+
type: issue.fields.issuetype?.name ?? "",
|
|
598
|
+
priority: issue.fields.priority?.name ?? null,
|
|
599
|
+
...issue.fields.parent ? {
|
|
600
|
+
parent: {
|
|
601
|
+
key: issue.fields.parent.key,
|
|
602
|
+
summary: issue.fields.parent.fields?.summary ?? ""
|
|
603
|
+
}
|
|
604
|
+
} : {},
|
|
605
|
+
assignee: issue.fields.assignee?.displayName ?? "unassigned",
|
|
606
|
+
updated: issue.fields.updated ?? ""
|
|
607
|
+
});
|
|
608
|
+
var liveData = (ctx = context()) => ({
|
|
609
|
+
baseUrl: ctx.config.baseUrl,
|
|
610
|
+
listIssues: async (all) => {
|
|
611
|
+
const jql = `assignee = currentUser()${all ? "" : ` AND ${DEFAULT_SCOPE}`} ORDER BY updated DESC`;
|
|
612
|
+
return (await ctx.client.searchIssues(jql, { limit: 200 })).map(toRow);
|
|
613
|
+
},
|
|
614
|
+
me: async () => ({ displayName: (await ctx.client.getMe()).displayName }),
|
|
615
|
+
search: async (query, mode) => {
|
|
616
|
+
const { jql, mode: used } = searchJql(query, {
|
|
617
|
+
mode,
|
|
618
|
+
scope: "assignee = currentUser()"
|
|
619
|
+
});
|
|
620
|
+
const issues = await ctx.client.searchIssues(jql, { limit: 200 });
|
|
621
|
+
return { rows: issues.map(toRow), mode: used };
|
|
622
|
+
},
|
|
623
|
+
getIssue: (key) => issueDetailOf(ctx.client, ctx.config.baseUrl, key),
|
|
624
|
+
getTransitions: (key) => transitionsOf(ctx.client, key),
|
|
625
|
+
transition: (key, transitionId) => ctx.client.transitionIssue(key, transitionId),
|
|
626
|
+
comment: async (key, body) => {
|
|
627
|
+
const { markdownToAdf } = await import("@kud/jira");
|
|
628
|
+
await ctx.client.addComment(key, markdownToAdf(body));
|
|
629
|
+
},
|
|
630
|
+
assignToMe: async (key) => {
|
|
631
|
+
const me = await ctx.client.getMe();
|
|
632
|
+
await ctx.client.assignIssue(key, me.accountId);
|
|
633
|
+
}
|
|
634
|
+
});
|
|
635
|
+
|
|
636
|
+
// src/tui/mock.ts
|
|
637
|
+
var CHECKOUT = { key: "SHOP-300", summary: "Basket and checkout correctness" };
|
|
638
|
+
var STOREFRONT = { key: "SHOP-350", summary: "Storefront refresh" };
|
|
639
|
+
var ROWS = [
|
|
640
|
+
{
|
|
641
|
+
key: "SHOP-412",
|
|
642
|
+
status: "In Progress",
|
|
643
|
+
category: "indeterminate",
|
|
644
|
+
summary: "Checkout total ignores the discount on the last item",
|
|
645
|
+
type: "Bug",
|
|
646
|
+
priority: "High",
|
|
647
|
+
parent: CHECKOUT,
|
|
648
|
+
assignee: "Ada Okafor",
|
|
649
|
+
updated: "2026-08-14T09:12:00.000Z"
|
|
650
|
+
},
|
|
651
|
+
{
|
|
652
|
+
key: "SHOP-408",
|
|
653
|
+
status: "In Review",
|
|
654
|
+
category: "indeterminate",
|
|
655
|
+
summary: "Add a dark theme to the storefront",
|
|
656
|
+
type: "Story",
|
|
657
|
+
priority: "Medium",
|
|
658
|
+
parent: STOREFRONT,
|
|
659
|
+
assignee: "Ada Okafor",
|
|
660
|
+
updated: "2026-08-13T16:40:00.000Z"
|
|
661
|
+
},
|
|
662
|
+
{
|
|
663
|
+
key: "SHOP-397",
|
|
664
|
+
status: "To Do",
|
|
665
|
+
category: "new",
|
|
666
|
+
summary: "Search returns stale results after a filter change",
|
|
667
|
+
type: "Bug",
|
|
668
|
+
priority: "Medium",
|
|
669
|
+
parent: CHECKOUT,
|
|
670
|
+
assignee: "Ada Okafor",
|
|
671
|
+
updated: "2026-08-11T08:00:00.000Z"
|
|
672
|
+
},
|
|
673
|
+
{
|
|
674
|
+
key: "SHOP-401",
|
|
675
|
+
status: "In Progress",
|
|
676
|
+
category: "indeterminate",
|
|
677
|
+
summary: "Coupon field accepts whitespace-only codes",
|
|
678
|
+
type: "Bug",
|
|
679
|
+
priority: "Low",
|
|
680
|
+
parent: CHECKOUT,
|
|
681
|
+
assignee: "Ada Okafor",
|
|
682
|
+
updated: "2026-08-12T11:30:00.000Z"
|
|
683
|
+
},
|
|
684
|
+
{
|
|
685
|
+
key: "PLAT-88",
|
|
686
|
+
status: "Blocked",
|
|
687
|
+
category: "indeterminate",
|
|
688
|
+
summary: "Rotate the staging database credentials",
|
|
689
|
+
type: "Task",
|
|
690
|
+
priority: "Highest",
|
|
691
|
+
assignee: "Ada Okafor",
|
|
692
|
+
updated: "2026-08-09T14:05:00.000Z"
|
|
693
|
+
},
|
|
694
|
+
{
|
|
695
|
+
key: "SHOP-390",
|
|
696
|
+
status: "Done",
|
|
697
|
+
category: "done",
|
|
698
|
+
summary: "Show the VAT breakdown on the order summary",
|
|
699
|
+
type: "Story",
|
|
700
|
+
priority: "Medium",
|
|
701
|
+
parent: CHECKOUT,
|
|
702
|
+
assignee: "Ada Okafor",
|
|
703
|
+
updated: "2026-08-08T10:00:00.000Z"
|
|
704
|
+
}
|
|
705
|
+
];
|
|
706
|
+
var DETAIL = {
|
|
707
|
+
"SHOP-412": {
|
|
708
|
+
key: "SHOP-412",
|
|
709
|
+
summary: "Checkout total ignores the discount on the last item",
|
|
710
|
+
status: "In Progress",
|
|
711
|
+
type: "Bug",
|
|
712
|
+
assignee: "Ada Okafor",
|
|
713
|
+
reporter: "Bram Nilsen",
|
|
714
|
+
labels: ["checkout", "regression"],
|
|
715
|
+
parent: { key: "SHOP-300", summary: "Basket and checkout correctness" },
|
|
716
|
+
url: "https://example.atlassian.net/browse/SHOP-412",
|
|
717
|
+
description: [
|
|
718
|
+
"## What happens",
|
|
719
|
+
"",
|
|
720
|
+
"The basket total is correct until the **last** line item, whose discount is",
|
|
721
|
+
"dropped from the sum.",
|
|
722
|
+
"",
|
|
723
|
+
"```js",
|
|
724
|
+
"const total = items.slice(0, -1).reduce(withDiscount, 0)",
|
|
725
|
+
"```",
|
|
726
|
+
"",
|
|
727
|
+
"1. Add three items",
|
|
728
|
+
"2. Apply `SUMMER20`",
|
|
729
|
+
"3. Compare the total against the line items",
|
|
730
|
+
"",
|
|
731
|
+
"[attachment: basket.png]"
|
|
732
|
+
].join("\n"),
|
|
733
|
+
comments: [
|
|
734
|
+
{
|
|
735
|
+
id: "c1",
|
|
736
|
+
author: "Bram Nilsen",
|
|
737
|
+
created: "2026-08-13",
|
|
738
|
+
body: "Reproduced on staging. Screenshot attached.\n\n[attachment: basket.png]"
|
|
739
|
+
},
|
|
740
|
+
{
|
|
741
|
+
id: "c2",
|
|
742
|
+
author: "Ada Okafor",
|
|
743
|
+
created: "2026-08-14",
|
|
744
|
+
body: "Off-by-one in `slice(0, -1)`. Fix and a regression test on the way."
|
|
745
|
+
}
|
|
746
|
+
],
|
|
747
|
+
attachments: [
|
|
748
|
+
{
|
|
749
|
+
id: "9001",
|
|
750
|
+
filename: "basket.png",
|
|
751
|
+
mimeType: "image/png",
|
|
752
|
+
size: 48213,
|
|
753
|
+
origins: [{ kind: "comment", commentId: "c1", author: "Bram Nilsen" }]
|
|
754
|
+
},
|
|
755
|
+
{
|
|
756
|
+
id: "9002",
|
|
757
|
+
filename: "checkout.log",
|
|
758
|
+
mimeType: "text/plain",
|
|
759
|
+
size: 2044,
|
|
760
|
+
origins: [{ kind: "issue" }]
|
|
761
|
+
}
|
|
762
|
+
]
|
|
763
|
+
}
|
|
764
|
+
};
|
|
765
|
+
var fallbackDetail = (key) => {
|
|
766
|
+
const row = ROWS.find((r) => r.key === key) ?? ROWS[0];
|
|
767
|
+
return {
|
|
768
|
+
key: row.key,
|
|
769
|
+
summary: row.summary,
|
|
770
|
+
status: row.status,
|
|
771
|
+
type: row.type,
|
|
772
|
+
assignee: row.assignee,
|
|
773
|
+
reporter: "Bram Nilsen",
|
|
774
|
+
labels: [],
|
|
775
|
+
url: `https://example.atlassian.net/browse/${row.key}`,
|
|
776
|
+
description: "_No description._",
|
|
777
|
+
comments: [],
|
|
778
|
+
attachments: []
|
|
779
|
+
};
|
|
780
|
+
};
|
|
781
|
+
var mockData = () => ({
|
|
782
|
+
baseUrl: "https://example.atlassian.net",
|
|
783
|
+
listIssues: async () => ROWS,
|
|
784
|
+
me: async () => ({ displayName: "Ada Okafor" }),
|
|
785
|
+
search: async (query, mode) => {
|
|
786
|
+
const used = mode === "jql" || mode === "auto" && looksLikeJql(query) ? "jql" : "text";
|
|
787
|
+
const words = query.toLowerCase();
|
|
788
|
+
return {
|
|
789
|
+
mode: used,
|
|
790
|
+
rows: used === "jql" ? ROWS : ROWS.filter((r) => `${r.key} ${r.summary}`.toLowerCase().includes(words))
|
|
791
|
+
};
|
|
792
|
+
},
|
|
793
|
+
getIssue: async (key) => DETAIL[key] ?? fallbackDetail(key),
|
|
794
|
+
getTransitions: async () => [
|
|
795
|
+
{ id: "11", name: "Start progress", to: "In Progress" },
|
|
796
|
+
{ id: "21", name: "Ready for review", to: "In Review" },
|
|
797
|
+
{ id: "31", name: "Done", to: "Done" }
|
|
798
|
+
],
|
|
799
|
+
transition: async () => {
|
|
800
|
+
},
|
|
801
|
+
comment: async () => {
|
|
802
|
+
},
|
|
803
|
+
assignToMe: async () => {
|
|
804
|
+
}
|
|
805
|
+
});
|
|
806
|
+
|
|
807
|
+
// src/tui/index.tsx
|
|
808
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
809
|
+
var SCREENS = ["issues", "detail"];
|
|
810
|
+
var runTui = async ({
|
|
811
|
+
screen,
|
|
812
|
+
mock,
|
|
813
|
+
issueKey
|
|
814
|
+
}) => {
|
|
815
|
+
const data = mock ? mockData() : liveData();
|
|
816
|
+
const key = issueKey ?? (mock ? "SHOP-412" : void 0);
|
|
817
|
+
const { waitUntilExit } = render(
|
|
818
|
+
/* @__PURE__ */ jsx3(App, { data, initialScreen: screen, initialKey: key })
|
|
819
|
+
);
|
|
820
|
+
await waitUntilExit();
|
|
821
|
+
};
|
|
822
|
+
export {
|
|
823
|
+
SCREENS,
|
|
824
|
+
runTui
|
|
825
|
+
};
|