@kud/gh-ink 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Erwann Mest
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # @kud/gh-ink
2
+
3
+ Controlled [Ink](https://github.com/vadimdemedes/ink) components for rendering
4
+ GitHub PR domain objects in the terminal. Presentation-first: data comes in as
5
+ props (the consuming surface owns the fetch), mutations run against
6
+ [`@kud/gh`](../gh). Built on [`@kud/ink-ui`](https://github.com/kud/ink-ui).
7
+
8
+ Consumed by the standalone `gh-pr-*` CLIs **and** by cockpit — one component, many
9
+ surfaces.
10
+
11
+ ## Install
12
+
13
+ ```sh
14
+ npm install @kud/gh-ink @kud/gh
15
+ ```
16
+
17
+ `ink` and `react` are peer dependencies.
18
+
19
+ ## Exports
20
+
21
+ | Export | What |
22
+ | ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
23
+ | `CommentsPanel` (`CommentsPanelProps`) | Selectable review-thread + conversation panel — resolve (`x`), reply (`r`), show/hide resolved (`R`). |
24
+ | `healthDisplay` / `healthGlyph` / `healthColor` | Map a `@kud/gh` `Health` token → glyph + `@kud/ink-ui` colour. Glyph distinguishes (colourblind-safe); colour reinforces. |
25
+ | `healthLegend` | Ordered `[Health, label]` pairs for a help legend. |
26
+ | `renderMarkdown` | GitHub-flavoured markdown → styled terminal lines. |
27
+
28
+ ## Design
29
+
30
+ Every component is controlled — the parent owns loading and passes `data` in — so
31
+ the same panel drops into a full-screen CLI or a single pane of a dashboard. The
32
+ core (`@kud/gh`) decides the semantic token; this layer maps it to a colour. Same
33
+ seam as `@kud/jenkins` → `@kud/jenkins-ink`.
34
+
35
+ ## Development
36
+
37
+ ```sh
38
+ npm run typecheck
39
+ npm run test
40
+ npm run build
41
+ ```
42
+
43
+ ## Licence
44
+
45
+ MIT © Erwann Mest
@@ -0,0 +1,35 @@
1
+ import React from 'react';
2
+ import { PrComments, PrHealthData, PrCheck, Health } from '@kud/gh';
3
+ import { StyledLine } from '@kud/ink-ui';
4
+
5
+ type CommentsPanelProps = {
6
+ repo: string;
7
+ number: number;
8
+ data: PrComments | null;
9
+ error: string | null;
10
+ reload: () => void;
11
+ onReplyingChange?: (active: boolean) => void;
12
+ };
13
+ declare const CommentsPanel: ({ repo, number, data, error, reload, onReplyingChange, }: CommentsPanelProps) => React.JSX.Element;
14
+
15
+ type HealthPanelProps = {
16
+ repo: string;
17
+ number: number;
18
+ data: PrHealthData | null;
19
+ error: string | null;
20
+ reload: () => void;
21
+ onOpenCheck: (check: PrCheck) => void;
22
+ };
23
+ declare const HealthPanel: ({ repo, number, data, error, reload, onOpenCheck, }: HealthPanelProps) => React.JSX.Element;
24
+
25
+ declare const renderMarkdown: (raw: string, width: number, fileLink?: (path: string, line?: number) => string) => StyledLine[];
26
+
27
+ declare const healthDisplay: Record<Health, {
28
+ glyph: string;
29
+ color: string;
30
+ }>;
31
+ declare const healthGlyph: (h: Health) => string;
32
+ declare const healthColor: (h: Health) => string;
33
+ declare const healthLegend: [Health, string][];
34
+
35
+ export { CommentsPanel, type CommentsPanelProps, HealthPanel, type HealthPanelProps, healthColor, healthDisplay, healthGlyph, healthLegend, renderMarkdown };
package/dist/index.js ADDED
@@ -0,0 +1,600 @@
1
+ import React2, { useState } from 'react';
2
+ import { useWindowSize, useInput, Text, Box } from 'ink';
3
+ import { colors, ScrollView, TextInput } from '@kud/ink-ui';
4
+ import { isPassCheck, isFailCheck, resolveThread, unresolveThread, replyToThread, rerunFailedRun, mergePr, reRequestReviewer } from '@kud/gh';
5
+ import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
6
+
7
+ // src/components/comments-panel.tsx
8
+ var ENTITIES = {
9
+ "&lt;": "<",
10
+ "&gt;": ">",
11
+ "&amp;": "&",
12
+ "&quot;": '"',
13
+ "&#39;": "'",
14
+ "&apos;": "'",
15
+ "&nbsp;": " ",
16
+ "&mdash;": "\u2014",
17
+ "&ndash;": "\u2013",
18
+ "&hellip;": "\u2026",
19
+ "&bull;": "\u2022",
20
+ "&rarr;": "\u2192",
21
+ "&larr;": "\u2190",
22
+ "&check;": "\u2713"
23
+ };
24
+ var decodeEntities = (s) => s.replace(/&#(\d+);/g, (_, n) => String.fromCodePoint(Number(n))).replace(
25
+ /&#x([0-9a-f]+);/gi,
26
+ (_, n) => String.fromCodePoint(parseInt(n, 16))
27
+ ).replace(/&[a-z]+;/gi, (m) => ENTITIES[m.toLowerCase()] ?? "");
28
+ var htmlToText = (s) => s.replace(/<br\s*\/?>/gi, "\n").replace(/<\/(p|div|h[1-6]|tr|ul|ol|table|thead|tbody|blockquote)>/gi, "\n").replace(/<li[^>]*>/gi, "\n\u2022 ").replace(/<\/(td|th)>/gi, " \xB7 ").replace(/<(td|th)[^>]*>/gi, "").replace(/<img[^>]*alt="([^"]*)"[^>]*>/gi, "[img: $1]").replace(/<img[^>]*>/gi, "[img]").replace(/<[^>]+>/g, "");
29
+ var stripInline = (line) => line.replace(/!\[([^\]]*)\]\([^)]*\)/g, "[img: $1]").replace(/\[([^\]]+)\]\(([^)]+)\)/g, "$1 ($2)").replace(/\*\*(.+?)\*\*/g, "$1").replace(/__(.+?)__/g, "$1").replace(/(^|[^*])\*(?!\*)([^*]+?)\*(?!\*)/g, "$1$2").replace(/`([^`]+)`/g, "$1");
30
+ var wrap = (text, width) => {
31
+ if (width <= 0) return [text];
32
+ const words = text.split(/\s+/);
33
+ const lines = [];
34
+ let cur = "";
35
+ for (const word of words) {
36
+ if (word.length > width) {
37
+ if (cur) {
38
+ lines.push(cur);
39
+ cur = "";
40
+ }
41
+ let rest = word;
42
+ while (rest.length > width) {
43
+ lines.push(rest.slice(0, width));
44
+ rest = rest.slice(width);
45
+ }
46
+ cur = rest;
47
+ continue;
48
+ }
49
+ if (!cur) cur = word;
50
+ else if (cur.length + 1 + word.length <= width) cur += " " + word;
51
+ else {
52
+ lines.push(cur);
53
+ cur = word;
54
+ }
55
+ }
56
+ if (cur) lines.push(cur);
57
+ return lines.length ? lines : [""];
58
+ };
59
+ var CODE_COLOR = "#8FBCBB";
60
+ var linkify = (s) => s.replace(/!\[([^\]]*)\]\([^)]*\)/g, "[img: $1]").replace(/\[([^\]]+)\]\(([^)]+)\)/g, "$1 ($2)");
61
+ var INLINE_RE = /(\*\*(.+?)\*\*|`([^`]+)`|\*([^*\s][^*]*?)\*)/g;
62
+ var parseInline = (text) => {
63
+ const spans = [];
64
+ const re = new RegExp(INLINE_RE);
65
+ let last = 0;
66
+ let m;
67
+ while (m = re.exec(text)) {
68
+ if (m.index > last) spans.push({ text: text.slice(last, m.index) });
69
+ if (m[2] != null) spans.push({ text: m[2], bold: true });
70
+ else if (m[3] != null) spans.push({ text: m[3], color: CODE_COLOR });
71
+ else if (m[4] != null) spans.push({ text: m[4], italic: true });
72
+ last = re.lastIndex;
73
+ }
74
+ if (last < text.length) spans.push({ text: text.slice(last) });
75
+ return spans;
76
+ };
77
+ var sameStyle = (a, b) => a.color === b.color && a.bold === b.bold && a.dim === b.dim && a.italic === b.italic;
78
+ var wrapSpans = (spans, width) => {
79
+ const words = [];
80
+ for (const s of spans)
81
+ for (const w of s.text.split(/\s+/).filter(Boolean))
82
+ words.push({ text: w, color: s.color, bold: s.bold, italic: s.italic });
83
+ const lines = [];
84
+ let cur = [];
85
+ const curLen = () => cur.reduce((n, sp) => n + sp.text.length, 0);
86
+ for (const w of words) {
87
+ const sep = cur.length ? 1 : 0;
88
+ if (cur.length && curLen() + sep + w.text.length > width) {
89
+ lines.push(cur);
90
+ cur = [];
91
+ }
92
+ const prefix = cur.length ? " " : "";
93
+ const last = cur[cur.length - 1];
94
+ if (last && sameStyle(last, w)) last.text += prefix + w.text;
95
+ else cur.push({ ...w, text: prefix + w.text });
96
+ }
97
+ if (cur.length) lines.push(cur);
98
+ return lines.length ? lines : [[]];
99
+ };
100
+ var EMOJI = {
101
+ ":rocket:": "\u{1F680}",
102
+ ":tada:": "\u{1F389}",
103
+ ":sparkles:": "\u2728",
104
+ ":+1:": "\u{1F44D}",
105
+ ":-1:": "\u{1F44E}",
106
+ ":white_check_mark:": "\u2705",
107
+ ":heavy_check_mark:": "\u2714\uFE0F",
108
+ ":x:": "\u274C",
109
+ ":warning:": "\u26A0\uFE0F",
110
+ ":rotating_light:": "\u{1F6A8}",
111
+ ":fire:": "\u{1F525}",
112
+ ":eyes:": "\u{1F440}",
113
+ ":bug:": "\u{1F41B}",
114
+ ":memo:": "\u{1F4DD}",
115
+ ":point_right:": "\u{1F449}"
116
+ };
117
+ var decodeShortcodes = (s) => s.replace(/:[a-z0-9_+-]+:/g, (m) => EMOJI[m] ?? m);
118
+ var FILE_REF_RE = /^((?:[\w.@-]+\/)+[\w.@-]+\.[A-Za-z]\w*)(?::(\d+))?$/;
119
+ var fileRef = (s) => {
120
+ const m = s.trim().match(FILE_REF_RE);
121
+ return m ? { path: m[1], line: m[2] ? Number(m[2]) : void 0 } : null;
122
+ };
123
+ var isSeparatorRow = (l) => l.includes("|") && /^[\s|:-]*-[\s|:-]*$/.test(l.trim());
124
+ var tableCells = (l) => l.trim().replace(/^\||\|$/g, "").split("|").map((c) => c.trim());
125
+ var renderMarkdown = (raw, width, fileLink) => {
126
+ if (!raw || !raw.trim()) return [];
127
+ const normalised = decodeShortcodes(
128
+ htmlToText(decodeEntities(raw.replace(/\r\n?/g, "\n")))
129
+ );
130
+ const out = [];
131
+ const push = (text, style, indent = 0) => {
132
+ for (const w of wrap(text, width - indent))
133
+ out.push({ text: " ".repeat(indent) + w, ...style });
134
+ };
135
+ const emitSpans = (raw2, indent = 0, prefix = "") => {
136
+ const avail = Math.max(8, width - indent - prefix.length);
137
+ const wrapped = wrapSpans(parseInline(linkify(raw2)), avail);
138
+ wrapped.forEach((lineSpans, k) => {
139
+ const lead = k === 0 ? " ".repeat(indent) + prefix : " ".repeat(indent + prefix.length);
140
+ out.push({ text: "", spans: [{ text: lead }, ...lineSpans] });
141
+ });
142
+ };
143
+ const renderTable = (header, rows) => {
144
+ for (const row of rows) {
145
+ const first = stripInline(row[0] ?? "");
146
+ if (first) {
147
+ push(first, { color: colors.accent, bold: true });
148
+ if (fileLink) {
149
+ const ref = fileRef(first);
150
+ if (ref) push(fileLink(ref.path, ref.line), { dim: true }, 2);
151
+ }
152
+ }
153
+ for (let c = 1; c < row.length; c++) {
154
+ const val = stripInline(row[c] ?? "");
155
+ if (!val) continue;
156
+ const label = header.length > 2 && header[c] ? `${stripInline(header[c])}: ` : "";
157
+ push(label + val, {}, 2);
158
+ }
159
+ out.push({ text: "" });
160
+ }
161
+ };
162
+ const src = normalised.split("\n");
163
+ let inFence = false;
164
+ let i = 0;
165
+ while (i < src.length) {
166
+ const line = src[i].replace(/\s+$/, "");
167
+ if (/^\s*```/.test(line)) {
168
+ inFence = !inFence;
169
+ i++;
170
+ continue;
171
+ }
172
+ if (inFence) {
173
+ out.push({ text: " " + line, color: CODE_COLOR });
174
+ i++;
175
+ continue;
176
+ }
177
+ if (line.includes("|") && i + 1 < src.length && isSeparatorRow(src[i + 1])) {
178
+ const header = tableCells(line);
179
+ i += 2;
180
+ const rows = [];
181
+ while (i < src.length && src[i].includes("|") && src[i].trim()) {
182
+ rows.push(tableCells(src[i]));
183
+ i++;
184
+ }
185
+ renderTable(header, rows);
186
+ continue;
187
+ }
188
+ if (/^\s*([-*_])\1{2,}\s*$/.test(line)) {
189
+ out.push({ text: "\u2500".repeat(Math.min(width, 40)), dim: true });
190
+ i++;
191
+ continue;
192
+ }
193
+ const heading = line.match(/^\s*(#{1,6})\s+(.*)$/);
194
+ if (heading) {
195
+ push(stripInline(heading[2]), { color: colors.accent, bold: true });
196
+ i++;
197
+ continue;
198
+ }
199
+ if (fileLink) {
200
+ const ref = fileRef(line);
201
+ if (ref) {
202
+ push(ref.path + (ref.line ? `:${ref.line}` : ""), {
203
+ color: colors.accent,
204
+ bold: true
205
+ });
206
+ push(fileLink(ref.path, ref.line), { dim: true }, 2);
207
+ i++;
208
+ continue;
209
+ }
210
+ }
211
+ if (/^\s*>\s?/.test(line)) {
212
+ const quote = stripInline(line.replace(/^\s*>\s?/, ""));
213
+ for (const w of wrap(quote, width - 2))
214
+ out.push({ text: "\u2502 " + w, color: colors.info });
215
+ i++;
216
+ continue;
217
+ }
218
+ const bullet = line.match(/^(\s*)[-*+]\s+(.*)$/);
219
+ if (bullet) {
220
+ emitSpans(bullet[2], bullet[1].length, "\u2022 ");
221
+ i++;
222
+ continue;
223
+ }
224
+ if (!line.trim()) {
225
+ out.push({ text: "" });
226
+ i++;
227
+ continue;
228
+ }
229
+ emitSpans(line.trimStart(), line.length - line.trimStart().length);
230
+ i++;
231
+ }
232
+ const isBlank = (l) => !!l && !l.spans && l.text === "";
233
+ const collapsed = [];
234
+ for (const l of out) {
235
+ if (isBlank(l) && isBlank(collapsed[collapsed.length - 1])) continue;
236
+ collapsed.push(l);
237
+ }
238
+ while (isBlank(collapsed[collapsed.length - 1])) collapsed.pop();
239
+ return collapsed;
240
+ };
241
+ var clamp = (n, lo, hi) => Math.max(lo, Math.min(n, hi));
242
+ var commentLines = ({ author, body }, width, fileLink, indent = 0) => {
243
+ const pad = " ".repeat(indent);
244
+ const fill = Math.max(3, width - indent - author.length - 4);
245
+ const lines = [
246
+ {
247
+ text: "",
248
+ spans: [
249
+ { text: pad + "\u2500\u2500 ", dim: true },
250
+ { text: author, color: colors.accent, bold: true },
251
+ { text: " " + "\u2500".repeat(fill), dim: true }
252
+ ]
253
+ }
254
+ ];
255
+ const bodyLines = renderMarkdown(body, width - indent, fileLink);
256
+ if (bodyLines.length === 0) lines.push({ text: pad + "(empty)", dim: true });
257
+ else
258
+ for (const l of bodyLines)
259
+ lines.push(
260
+ l.spans ? { ...l, spans: [{ text: pad }, ...l.spans] } : { ...l, text: pad + l.text }
261
+ );
262
+ lines.push({ text: "" });
263
+ return lines;
264
+ };
265
+ var CommentsPanel = ({
266
+ repo,
267
+ number,
268
+ data,
269
+ error,
270
+ reload,
271
+ onReplyingChange
272
+ }) => {
273
+ const [showResolved, setShowResolved] = useState(true);
274
+ const [threadSel, setThreadSel] = useState(0);
275
+ const [replying, setReplying] = useState(false);
276
+ const [status, setStatus] = useState(null);
277
+ const { columns } = useWindowSize();
278
+ const width = Math.max(20, columns - 2);
279
+ const setReply = (v) => {
280
+ setReplying(v);
281
+ onReplyingChange?.(v);
282
+ };
283
+ const fileLink = (path, line) => `https://github.com/${repo}/blob/${data?.headRef ?? "HEAD"}/${path}` + (line ? `#L${line}` : "");
284
+ const conversation = data?.conversation ?? [];
285
+ const allThreads = data?.threads ?? [];
286
+ const threads = showResolved ? allThreads : allThreads.filter((t) => !t.isResolved && !t.isOutdated);
287
+ const hiddenThreads = allThreads.length - threads.length;
288
+ const sel = clamp(threadSel, 0, Math.max(0, threads.length - 1));
289
+ const selThread = threads[sel] ?? null;
290
+ const doResolveToggle = async () => {
291
+ if (!selThread) return;
292
+ const resolving = !selThread.isResolved;
293
+ setStatus(resolving ? "Resolving\u2026" : "Unresolving\u2026");
294
+ try {
295
+ if (resolving) await resolveThread(selThread.id);
296
+ else await unresolveThread(selThread.id);
297
+ setStatus(null);
298
+ reload();
299
+ } catch (e) {
300
+ setStatus(`Failed: ${e.message}`);
301
+ }
302
+ };
303
+ const submitReply = async (body) => {
304
+ setReply(false);
305
+ const trimmed = body.trim();
306
+ if (!selThread || !trimmed) return;
307
+ const root = selThread.comments[0];
308
+ if (!root?.databaseId) {
309
+ setStatus("Nothing to reply to on this thread");
310
+ return;
311
+ }
312
+ setStatus("Replying\u2026");
313
+ try {
314
+ await replyToThread({
315
+ repo,
316
+ pull: number,
317
+ inReplyTo: root.databaseId,
318
+ body: trimmed
319
+ });
320
+ setStatus(null);
321
+ reload();
322
+ } catch (e) {
323
+ setStatus(`Reply failed: ${e.message}`);
324
+ }
325
+ };
326
+ useInput(
327
+ (_input, key) => {
328
+ if (key.escape) setReply(false);
329
+ },
330
+ { isActive: replying }
331
+ );
332
+ useInput(
333
+ (input, key) => {
334
+ if (input === "R") return setShowResolved((s) => !s);
335
+ if (!threads.length) return;
336
+ if (key.upArrow || input === "k")
337
+ setThreadSel(() => clamp(sel - 1, 0, threads.length - 1));
338
+ else if (key.downArrow || input === "j")
339
+ setThreadSel(() => clamp(sel + 1, 0, threads.length - 1));
340
+ else if (input === "x") void doResolveToggle();
341
+ else if (input === "r" && selThread) setReply(true);
342
+ },
343
+ { isActive: !replying }
344
+ );
345
+ const lines = [];
346
+ let anchor = 0;
347
+ if (error) lines.push({ text: `Error: ${error}`, color: colors.error });
348
+ else if (!data) lines.push({ text: "Fetching comments\u2026", color: colors.info });
349
+ else {
350
+ if (status)
351
+ lines.push(
352
+ { text: status, color: colors.warning, bold: true },
353
+ { text: "" }
354
+ );
355
+ if (conversation.length === 0 && allThreads.length === 0)
356
+ lines.push({ text: "No comments on this PR.", dim: true });
357
+ if (conversation.length > 0) {
358
+ lines.push({
359
+ text: `Conversation (${conversation.length})`,
360
+ color: colors.info,
361
+ bold: true
362
+ });
363
+ lines.push({ text: "" });
364
+ for (const c of conversation)
365
+ lines.push(...commentLines(c, width, fileLink));
366
+ }
367
+ if (threads.length > 0) {
368
+ lines.push({
369
+ text: `Review threads (${threads.length})`,
370
+ color: colors.info,
371
+ bold: true
372
+ });
373
+ lines.push({ text: "" });
374
+ threads.forEach((t, i) => {
375
+ if (i === sel) anchor = lines.length;
376
+ const active = i === sel;
377
+ const loc = (t.path ?? "conversation") + (t.line ? `:${t.line}` : "");
378
+ const tags = (t.isResolved ? " [resolved]" : "") + (t.isOutdated ? " [outdated]" : "");
379
+ lines.push({
380
+ text: "",
381
+ spans: [
382
+ { text: active ? "\u276F " : " ", color: colors.info, bold: true },
383
+ {
384
+ text: loc,
385
+ color: active ? colors.accent : colors.muted,
386
+ bold: active
387
+ },
388
+ ...tags ? [{ text: tags, dim: true }] : []
389
+ ]
390
+ });
391
+ for (const c of t.comments)
392
+ lines.push(...commentLines(c, width, fileLink, 2));
393
+ });
394
+ }
395
+ if (hiddenThreads > 0)
396
+ lines.push({
397
+ text: `${hiddenThreads} resolved/outdated hidden \u2014 R to show`,
398
+ dim: true
399
+ });
400
+ }
401
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
402
+ /* @__PURE__ */ jsx(ScrollView, { lines, initialStart: anchor, isActive: !replying }),
403
+ replying ? /* @__PURE__ */ jsx(
404
+ TextInput,
405
+ {
406
+ placeholder: `Reply to ${selThread?.path ?? "thread"}\u2026 (\u21B5 send \xB7 esc cancel)`,
407
+ onSubmit: submitReply
408
+ }
409
+ ) : null
410
+ ] });
411
+ };
412
+ var checkIcon = (c) => isPassCheck(c) ? ["\u2713", colors.success] : isFailCheck(c) ? ["\u2717", colors.error] : ["\xB7", colors.warning];
413
+ var checkLabel = (c) => {
414
+ const name = c.context ?? c.name ?? "";
415
+ return c.workflowName ? `${c.workflowName} / ${name}` : name;
416
+ };
417
+ var checkUrl = (c) => c.detailsUrl ?? c.targetUrl ?? "";
418
+ var runIdOf = (url) => url.match(/\/runs\/(\d+)/)?.[1] ?? null;
419
+ var reviewIcon = (state) => state === "APPROVED" ? ["\u2713", colors.success] : state === "CHANGES_REQUESTED" ? ["~", colors.warning] : ["\xB7", colors.muted];
420
+ var MERGE = {
421
+ CLEAN: ["ready", colors.success],
422
+ BLOCKED: ["blocked", colors.error],
423
+ DIRTY: ["has conflicts", colors.error],
424
+ UNSTABLE: ["unstable", colors.warning],
425
+ BEHIND: ["behind base", colors.warning]
426
+ };
427
+ var mergeText = (status) => MERGE[status] ?? ["checking\u2026", colors.warning];
428
+ var Summary = ({
429
+ label,
430
+ icon,
431
+ parts
432
+ }) => /* @__PURE__ */ jsxs(Box, { children: [
433
+ /* @__PURE__ */ jsx(Text, { children: " " }),
434
+ /* @__PURE__ */ jsx(Text, { bold: true, children: label.padEnd(10) }),
435
+ /* @__PURE__ */ jsx(Text, { children: icon + " " }),
436
+ parts.map(([text, color], i) => /* @__PURE__ */ jsxs(React2.Fragment, { children: [
437
+ i > 0 && /* @__PURE__ */ jsx(Text, { dimColor: true, children: " \xB7 " }),
438
+ /* @__PURE__ */ jsx(Text, { color, children: text })
439
+ ] }, text + i))
440
+ ] });
441
+ var HealthPanel = ({
442
+ repo,
443
+ number,
444
+ data,
445
+ error,
446
+ reload,
447
+ onOpenCheck
448
+ }) => {
449
+ const [cursor, setCursor] = useState(0);
450
+ const [note, setNote] = useState(null);
451
+ const [confirm, setConfirm] = useState(null);
452
+ const [busy, setBusy] = useState(false);
453
+ const checks = (data?.statusCheckRollup ?? []).filter(
454
+ (c) => (c.name ?? c.context)?.trim()
455
+ );
456
+ const reviewers = data ? Object.entries(
457
+ data.reviews.reduce(
458
+ (acc, r) => r.author?.login && r.author.login !== data.author?.login ? { ...acc, [r.author.login]: r.state } : acc,
459
+ {}
460
+ )
461
+ ) : [];
462
+ const focusCount = checks.length + reviewers.length;
463
+ const safeCursor = Math.min(cursor, Math.max(0, focusCount - 1));
464
+ const selected = safeCursor < checks.length ? checks[safeCursor] : void 0;
465
+ const selectedReviewer = safeCursor >= checks.length ? reviewers[safeCursor - checks.length] : void 0;
466
+ const flash = (msg) => {
467
+ setNote(msg);
468
+ setTimeout(() => setNote(null), 2500);
469
+ };
470
+ const act = async (msg, run) => {
471
+ setBusy(true);
472
+ setNote(`\u22EF ${msg}\u2026`);
473
+ try {
474
+ await run();
475
+ flash(`\u2713 ${msg}`);
476
+ reload();
477
+ } catch {
478
+ flash(`\u2717 ${msg} failed`);
479
+ } finally {
480
+ setBusy(false);
481
+ }
482
+ };
483
+ const retrigger = () => {
484
+ const failing = checks.find((c) => isFailCheck(c) && runIdOf(checkUrl(c)));
485
+ const runId = failing && runIdOf(checkUrl(failing));
486
+ if (!runId) return flash("No failed Actions run to retrigger");
487
+ void act("retrigger CI", () => rerunFailedRun(repo, runId));
488
+ };
489
+ useInput((input, key) => {
490
+ if (busy) return;
491
+ if (confirm === "merge") {
492
+ if (input === "y" || input === "Y")
493
+ void act("merge", () => mergePr(repo, number));
494
+ setConfirm(null);
495
+ return;
496
+ }
497
+ if (key.upArrow || input === "k") setCursor((c) => Math.max(0, c - 1));
498
+ if (key.downArrow || input === "j")
499
+ setCursor((c) => Math.min(Math.max(0, focusCount - 1), c + 1));
500
+ if (input === "r") return retrigger();
501
+ if (input === "m") return void setConfirm("merge");
502
+ if (key.return || input === "l") {
503
+ if (selected) onOpenCheck(selected);
504
+ else if (selectedReviewer) {
505
+ const login = selectedReviewer[0];
506
+ void act(
507
+ `re-request ${login}`,
508
+ () => reRequestReviewer(repo, number, login)
509
+ );
510
+ }
511
+ }
512
+ });
513
+ if (error) return /* @__PURE__ */ jsxs(Text, { color: colors.error, children: [
514
+ "Error: ",
515
+ error
516
+ ] });
517
+ if (!data) return /* @__PURE__ */ jsx(Text, { color: colors.info, children: "Fetching status\u2026" });
518
+ const reviewerMap = Object.fromEntries(reviewers);
519
+ const passed = checks.filter(isPassCheck).length;
520
+ const failed = checks.filter(isFailCheck).length;
521
+ const pending = checks.length - passed - failed;
522
+ const approved = Object.values(reviewerMap).filter(
523
+ (s) => s === "APPROVED"
524
+ ).length;
525
+ const changesReq = Object.values(reviewerMap).filter(
526
+ (s) => s === "CHANGES_REQUESTED"
527
+ ).length;
528
+ const checkParts = [[`${passed} passed`, colors.success]];
529
+ if (failed > 0) checkParts.push([`${failed} failed`, colors.error]);
530
+ if (pending > 0) checkParts.push([`${pending} pending`, colors.warning]);
531
+ const reviewParts = [
532
+ approved > 0 ? [`${approved} approved`, colors.success] : ["0 approved", "white"]
533
+ ];
534
+ if (changesReq > 0)
535
+ reviewParts.push([`${changesReq} changes requested`, colors.error]);
536
+ if (data.reviewDecision === "REVIEW_REQUIRED")
537
+ reviewParts.push(["review required", colors.warning]);
538
+ const [mText, mColor] = mergeText(data.mergeStateStatus);
539
+ const checksIcon = failed > 0 ? "\u2717" : pending > 0 ? "\xB7" : "\u2713";
540
+ const reviewsIcon = changesReq > 0 ? "\u2717" : approved > 0 ? "\u2713" : "\xB7";
541
+ const mergeIcon = data.mergeStateStatus === "CLEAN" ? "\u2713" : "\xB7";
542
+ return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", children: [
543
+ /* @__PURE__ */ jsx(Summary, { label: "Checks", icon: checksIcon, parts: checkParts }),
544
+ /* @__PURE__ */ jsx(Box, { flexDirection: "column", children: checks.map((c, i) => {
545
+ const [icon, color] = checkIcon(c);
546
+ return /* @__PURE__ */ jsxs(Box, { children: [
547
+ /* @__PURE__ */ jsx(Text, { color: colors.info, children: i === safeCursor ? " \u276F " : " " }),
548
+ /* @__PURE__ */ jsx(Text, { color, children: icon + " " }),
549
+ /* @__PURE__ */ jsx(Text, { bold: i === safeCursor, children: checkLabel(c) }),
550
+ i === safeCursor ? /* @__PURE__ */ jsx(Text, { dimColor: true, children: " \u21B5 open" }) : null
551
+ ] }, checkLabel(c) + i);
552
+ }) }),
553
+ /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsx(Summary, { label: "Reviews", icon: reviewsIcon, parts: reviewParts }) }),
554
+ reviewers.map(([login, state], j) => {
555
+ const [icon, color] = reviewIcon(state);
556
+ const active = safeCursor === checks.length + j;
557
+ return /* @__PURE__ */ jsxs(Box, { children: [
558
+ /* @__PURE__ */ jsx(Text, { color: colors.info, children: active ? " \u276F " : " " }),
559
+ /* @__PURE__ */ jsx(Text, { color, children: icon + " " }),
560
+ /* @__PURE__ */ jsx(Text, { bold: active, children: login }),
561
+ active ? /* @__PURE__ */ jsx(Text, { dimColor: true, children: " \u21B5 re-request" }) : null
562
+ ] }, login);
563
+ }),
564
+ /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsx(Summary, { label: "Merge", icon: mergeIcon, parts: [[mText, mColor]] }) }),
565
+ confirm === "merge" ? /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsxs(Text, { color: colors.warning, children: [
566
+ ` Merge #${number}? `,
567
+ /* @__PURE__ */ jsx(Text, { color: colors.success, children: "y" }),
568
+ /* @__PURE__ */ jsx(Text, { dimColor: true, children: " confirm \xB7 any other key cancels" })
569
+ ] }) }) : note ? /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsx(Text, { color: colors.success, children: " " + note }) }) : null
570
+ ] });
571
+ };
572
+ var healthDisplay = {
573
+ none: { glyph: " ", color: colors.muted },
574
+ draft: { glyph: "~", color: colors.muted },
575
+ "ci-fail": { glyph: "\u2717", color: colors.error },
576
+ conflict: { glyph: "!", color: colors.accent },
577
+ "changes-req": { glyph: "\xB1", color: colors.warning },
578
+ threads: { glyph: "\u25C6", color: colors.accent },
579
+ pending: { glyph: "*", color: colors.warning },
580
+ approved: { glyph: "\u2713", color: colors.success },
581
+ waiting: { glyph: "\xB7", color: colors.muted },
582
+ merged: { glyph: "\xBB", color: colors.muted },
583
+ closed: { glyph: "\xD7", color: colors.muted }
584
+ };
585
+ var healthGlyph = (h) => healthDisplay[h].glyph;
586
+ var healthColor = (h) => healthDisplay[h].color;
587
+ var healthLegend = [
588
+ ["approved", "Approved \xB7 ready to merge"],
589
+ ["pending", "Checks running"],
590
+ ["ci-fail", "CI failing"],
591
+ ["conflict", "Merge conflict"],
592
+ ["changes-req", "Changes requested"],
593
+ ["threads", "Open threads \xB7 your reply"],
594
+ ["waiting", "Awaiting review"],
595
+ ["draft", "Draft"],
596
+ ["merged", "Merged"],
597
+ ["closed", "Closed"]
598
+ ];
599
+
600
+ export { CommentsPanel, HealthPanel, healthColor, healthDisplay, healthGlyph, healthLegend, renderMarkdown };
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@kud/gh-ink",
3
+ "version": "0.1.0",
4
+ "description": "Ink components for rendering GitHub PR review comments and health — controlled, presentation-only, built on @kud/ink-ui and fed by @kud/gh.",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "engines": {
18
+ "node": ">=20"
19
+ },
20
+ "scripts": {
21
+ "build": "tsup",
22
+ "dev": "tsup --watch",
23
+ "typecheck": "tsc --noEmit",
24
+ "test": "vitest run",
25
+ "test:watch": "vitest"
26
+ },
27
+ "keywords": [
28
+ "github",
29
+ "pull-request",
30
+ "ink",
31
+ "cli",
32
+ "react",
33
+ "terminal",
34
+ "components"
35
+ ],
36
+ "author": "Erwann Mest <m@kud.io>",
37
+ "license": "MIT",
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "https://github.com/kud/gh",
41
+ "directory": "packages/gh-ink"
42
+ },
43
+ "publishConfig": {
44
+ "access": "public"
45
+ },
46
+ "peerDependencies": {
47
+ "ink": ">=7",
48
+ "react": ">=19"
49
+ },
50
+ "dependencies": {
51
+ "@kud/gh": "0.1.0",
52
+ "@kud/ink-ui": "0.8.0"
53
+ },
54
+ "devDependencies": {
55
+ "@types/node": "22.20.1",
56
+ "@types/react": "19.2.17",
57
+ "ink": "7.1.0",
58
+ "ink-testing-library": "4.0.0",
59
+ "react": "19.2.7",
60
+ "tsup": "8.5.1",
61
+ "typescript": "5.9.3",
62
+ "vitest": "4.1.10"
63
+ }
64
+ }