pi-odd-worktree 3.9.1 → 3.10.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 +63 -40
- package/extensions/odd-worktree-tools.ts +859 -12
- package/lib/gh-issues.js +65 -10
- package/lib/gh-prs.js +2011 -0
- package/lib/issue-preview.js +70 -4
- package/lib/issues-cache-store.js +4 -1
- package/lib/issues-section.js +346 -23
- package/lib/issues-view.js +116 -5
- package/lib/modules.js +5 -0
- package/lib/pr-preview.js +353 -0
- package/lib/prs-rail-store.js +317 -0
- package/lib/prs-view.js +2896 -0
- package/package.json +1 -1
- package/tools/files-bridge.test.js +2 -2
- package/tools/files-command.test.js +1 -1
- package/tools/fixtures/gh-pr-connection-page.json +84 -0
- package/tools/fixtures/gh-pr-metadata.json +29 -0
- package/tools/fixtures/gh-pr-rail.json +61 -0
- package/tools/fixtures/gh-pr-search-page.json +82 -0
- package/tools/fixtures/gh-pr-view.json +159 -0
- package/tools/gh-issues.test.js +4 -2
- package/tools/gh-prs.test.js +1828 -0
- package/tools/issue-preview.test.js +119 -0
- package/tools/issues-cache-store.test.js +2 -2
- package/tools/issues-command.test.js +10 -3
- package/tools/issues-open-guard.test.js +15 -0
- package/tools/issues-section.test.js +618 -9
- package/tools/issues-view.test.js +297 -0
- package/tools/modules-wiring.test.js +5 -0
- package/tools/package-surface.test.js +18 -4
- package/tools/pr-preview.test.js +281 -0
- package/tools/prs-command.test.js +1280 -0
- package/tools/prs-rail-store.test.js +343 -0
- package/tools/prs-t10-safety.test.js +326 -0
- package/tools/prs-t12-safety.test.js +348 -0
- package/tools/prs-t13-independent.test.js +378 -0
- package/tools/prs-t14-safety.test.js +340 -0
- package/tools/prs-t15-independent.test.js +259 -0
- package/tools/prs-t18-safety.test.js +217 -0
- package/tools/prs-t7-safety.test.js +127 -0
- package/tools/prs-view.test.js +1462 -0
package/lib/issues-view.js
CHANGED
|
@@ -12,8 +12,17 @@
|
|
|
12
12
|
// labels through `loadLabels()` on the editor's first use, and writes go
|
|
13
13
|
// through `actions.{editLabels,postComment,setState}` — every failure is
|
|
14
14
|
// shown and keeps the local state unchanged. Same host contract as
|
|
15
|
-
// lib/odd-view.js: { render(width), handleInput(data),
|
|
16
|
-
// `state`.
|
|
15
|
+
// lib/odd-view.js: { render(width), handleInput(data), handleMouse(event),
|
|
16
|
+
// invalidate() } plus `state`.
|
|
17
|
+
//
|
|
18
|
+
// S6/S7 (prs: cross-links and Enter): `enter` in list mode is the INSERT key —
|
|
19
|
+
// it calls `actions.insert("ISSUE #N")` for the selected issue and closes the
|
|
20
|
+
// panel — while inside the search box, the editors and the close confirmation
|
|
21
|
+
// the same key keeps the meaning it always had there. The pane's `linked PRs:`
|
|
22
|
+
// row is a set of independent click ranges: `handleMouse` maps a left click
|
|
23
|
+
// through the frame it last composed (pane columns, body row, scroll offset)
|
|
24
|
+
// and calls `actions.openLinked({kind:'pullRequest', number})` for exactly the
|
|
25
|
+
// clicked number, never for the whole line; a host with no seam does nothing.
|
|
17
26
|
//
|
|
18
27
|
// S16/D2: label and assignee editing is a repository capability, never the
|
|
19
28
|
// fact that the user authenticated. Issue detail carries
|
|
@@ -141,6 +150,9 @@ const { renderOddMarkdown } = require('./odd-markdown.js');
|
|
|
141
150
|
|
|
142
151
|
const CARD_PADDING = layout.CARD_PADDING;
|
|
143
152
|
const MIN_WIDTH = 24;
|
|
153
|
+
// S6: the frame rows above the body — the top rule, the search row, the tab row
|
|
154
|
+
// and the note row — so the painted body starts here on every full frame.
|
|
155
|
+
const BODY_TOP = 4;
|
|
144
156
|
// The buckets the server seam reads from unless the caller passes its own
|
|
145
157
|
// `pages` metadata (ids and labels are then the caller's). S15 appended `All`,
|
|
146
158
|
// the whole open repository, and never deduplicates it against the others; S1
|
|
@@ -212,6 +224,12 @@ const FOOTER_KEYS = [
|
|
|
212
224
|
// rides the legend; `X` keeps closing without a token.
|
|
213
225
|
{ key: 'x', text: 'x close', short: 'x', priority: 40, requires: 'canCloseIssues', needsIssue: true },
|
|
214
226
|
{ key: 'o', text: 'o web', short: 'o', priority: 20, needsIssue: true },
|
|
227
|
+
// S7 (prs): `enter` is the insert key — it puts the selected issue into the
|
|
228
|
+
// chat input as `ISSUE #N` and closes the panel. It acts on the focused row
|
|
229
|
+
// like every other issue token (`needsIssue`), needs no repository
|
|
230
|
+
// capability, and its priority keeps the pre-existing legend's own drop
|
|
231
|
+
// order at narrow widths: the rows that already fit keep fitting.
|
|
232
|
+
{ key: 'enter', text: 'enter insert', short: 'enter', priority: 34, needsIssue: true },
|
|
215
233
|
// S4: the search key belongs here with every other shortcut, never on the
|
|
216
234
|
// search row above it. The legend spells the lowercase key `t` (the one a
|
|
217
235
|
// reader reaches for); `T` keeps opening the box without a token.
|
|
@@ -628,6 +646,11 @@ function createIssuesView(options = {}) {
|
|
|
628
646
|
searchPending: false,
|
|
629
647
|
};
|
|
630
648
|
let bodyRows = 1;
|
|
649
|
+
// S6: the click geometry of the frame `render` last composed, so a mouse
|
|
650
|
+
// event is mapped against the pane the reader is actually looking at,
|
|
651
|
+
// scroll offset included. `null` until a full frame painted (and after an
|
|
652
|
+
// early state frame, which carries no pane at all).
|
|
653
|
+
let pointerFrame = null;
|
|
631
654
|
// The interactive reader wants every tab's data at open (S13/S15 round 3):
|
|
632
655
|
// switching must never refetch and no tab may sit at a false zero.
|
|
633
656
|
const prefetchBuckets = Boolean(options) && options.prefetchBuckets === true;
|
|
@@ -1455,7 +1478,7 @@ function createIssuesView(options = {}) {
|
|
|
1455
1478
|
};
|
|
1456
1479
|
}
|
|
1457
1480
|
|
|
1458
|
-
function detailLines(row, width) {
|
|
1481
|
+
function detailLines(row, width, ranges = null) {
|
|
1459
1482
|
const entry = ensureDetail(row);
|
|
1460
1483
|
if (!entry) return [paint(theme, 'muted', '(no issue selected)')];
|
|
1461
1484
|
if (entry.status === 'error') return [paint(theme, 'error', `unreadable: ${entry.error}`)];
|
|
@@ -1482,6 +1505,10 @@ function createIssuesView(options = {}) {
|
|
|
1482
1505
|
paint: (role, text) => paint(theme, role, text),
|
|
1483
1506
|
emphasis: (text) => emphasize(theme, text),
|
|
1484
1507
|
wrap: detailWrap(markdownBodySources(issue, comments), width),
|
|
1508
|
+
// S6: the formatter reports one click range per linked PR number it
|
|
1509
|
+
// printed, against the rows it returned (the pane's own scroll window is
|
|
1510
|
+
// applied by `handleMouse`).
|
|
1511
|
+
ranges,
|
|
1485
1512
|
});
|
|
1486
1513
|
}
|
|
1487
1514
|
|
|
@@ -1537,6 +1564,9 @@ function createIssuesView(options = {}) {
|
|
|
1537
1564
|
|
|
1538
1565
|
function render(width) {
|
|
1539
1566
|
const w = typeof width === 'number' && Number.isFinite(width) ? Math.floor(width) : 0;
|
|
1567
|
+
// S6: every frame replaces the click geometry; a frame that paints no pane
|
|
1568
|
+
// leaves none, so a stale mapping can never open a link that is not there.
|
|
1569
|
+
pointerFrame = null;
|
|
1540
1570
|
if (w <= 0) return [];
|
|
1541
1571
|
const height = availableRows();
|
|
1542
1572
|
const title = titleText();
|
|
@@ -1689,6 +1719,10 @@ function createIssuesView(options = {}) {
|
|
|
1689
1719
|
}
|
|
1690
1720
|
|
|
1691
1721
|
let rightSource;
|
|
1722
|
+
// S6: the click ranges of the relation row this frame paints, collected
|
|
1723
|
+
// through the preview formatter's own seam. Only the plain reading pane has
|
|
1724
|
+
// one; every editor replaces that pane and carries no link.
|
|
1725
|
+
let linkRanges = null;
|
|
1692
1726
|
if (state.mode === 'labels') {
|
|
1693
1727
|
rightSource = labelEditorLines(rightWidth);
|
|
1694
1728
|
} else if (state.mode === 'assignees') {
|
|
@@ -1708,10 +1742,25 @@ function createIssuesView(options = {}) {
|
|
|
1708
1742
|
rightSource = [paint(theme, 'muted', 'no issues'), paint(theme, 'dim', 'nothing to show here')];
|
|
1709
1743
|
}
|
|
1710
1744
|
} else {
|
|
1711
|
-
|
|
1745
|
+
linkRanges = [];
|
|
1746
|
+
rightSource = detailLines(focused, rightWidth, linkRanges);
|
|
1712
1747
|
}
|
|
1713
1748
|
clampScroll(rightSource.length);
|
|
1714
1749
|
const visible = rightSource.slice(state.scroll, state.scroll + bodyRows);
|
|
1750
|
+
// S6: remember the geometry this frame paints, so a click maps through the
|
|
1751
|
+
// SAME window and scroll offset the reader is looking at: body row `n`
|
|
1752
|
+
// shows pane line `state.scroll + n`, and the right pane starts after the
|
|
1753
|
+
// left pane, its two spaces and the divider (`5 + listWidth`).
|
|
1754
|
+
pointerFrame = {
|
|
1755
|
+
width: w,
|
|
1756
|
+
height,
|
|
1757
|
+
bodyTop: BODY_TOP,
|
|
1758
|
+
bodyRows,
|
|
1759
|
+
paneStart: listWidth + 5,
|
|
1760
|
+
paneEnd: listWidth + 5 + rightWidth,
|
|
1761
|
+
scroll: state.scroll,
|
|
1762
|
+
links: linkRanges === null ? [] : linkRanges,
|
|
1763
|
+
};
|
|
1715
1764
|
// Empty left rows (a window shorter than the body) still paint blank cells.
|
|
1716
1765
|
for (let row = 0; row < bodyRows; row += 1) {
|
|
1717
1766
|
const left = pad(helpers, leftLines[row] ?? '', listWidth);
|
|
@@ -2764,6 +2813,13 @@ function createIssuesView(options = {}) {
|
|
|
2764
2813
|
openCloseConfirm();
|
|
2765
2814
|
return;
|
|
2766
2815
|
}
|
|
2816
|
+
// S7 (prs): `enter` in list mode inserts the selected issue into the chat
|
|
2817
|
+
// input and closes the panel. The search box, the editors and the close
|
|
2818
|
+
// confirmation above keep the meaning this key always had there.
|
|
2819
|
+
if (keyMatches(helpers, data, ['enter'])) {
|
|
2820
|
+
insertSelected();
|
|
2821
|
+
return;
|
|
2822
|
+
}
|
|
2767
2823
|
if (keyMatches(helpers, data, ['o'])) {
|
|
2768
2824
|
const open = actions && typeof actions.openBrowser === 'function' ? actions.openBrowser : null;
|
|
2769
2825
|
const row = selected();
|
|
@@ -2823,6 +2879,61 @@ function createIssuesView(options = {}) {
|
|
|
2823
2879
|
|
|
2824
2880
|
function invalidate() {}
|
|
2825
2881
|
|
|
2882
|
+
// S7 (prs): `enter` in list mode is the insert key. It formats the selected
|
|
2883
|
+
// issue as `ISSUE #N` and hands it to the host's own insertion seam, then
|
|
2884
|
+
// closes the panel. It is not a mutation, so no repository capability gates
|
|
2885
|
+
// it, and a host without the seam is a no-op that keeps the panel open.
|
|
2886
|
+
function insertSelected() {
|
|
2887
|
+
const row = selected();
|
|
2888
|
+
if (!row) return;
|
|
2889
|
+
const number = numOf(row);
|
|
2890
|
+
if (!Number.isFinite(number)) return;
|
|
2891
|
+
const insert = actions && typeof actions.insert === 'function' ? actions.insert : null;
|
|
2892
|
+
if (typeof insert !== 'function') return;
|
|
2893
|
+
try {
|
|
2894
|
+
insert(`ISSUE #${number}`);
|
|
2895
|
+
} catch {
|
|
2896
|
+
// A throwing host seam never blocks the close below.
|
|
2897
|
+
}
|
|
2898
|
+
close();
|
|
2899
|
+
}
|
|
2900
|
+
|
|
2901
|
+
// S6 (prs): a left click on ONE linked PR number opens exactly that pull
|
|
2902
|
+
// request in the PR panel. The geometry is the frame `render` last composed —
|
|
2903
|
+
// the pane's columns, the body row, and the scroll offset that decides which
|
|
2904
|
+
// pane line that row shows — so a scrolled pane maps correctly. Everything
|
|
2905
|
+
// else stays unhandled (the host keeps its own mouse behaviour): the relation
|
|
2906
|
+
// row's label, its separators and the truncation ellipsis carry no range, and
|
|
2907
|
+
// a click on a link in a host with no `openLinked` seam does nothing.
|
|
2908
|
+
function handleMouse(event) {
|
|
2909
|
+
if (!active) return undefined;
|
|
2910
|
+
const frame = pointerFrame;
|
|
2911
|
+
if (!frame) return undefined;
|
|
2912
|
+
if (event === null || typeof event !== 'object') return undefined;
|
|
2913
|
+
if (event.type !== 'click' || event.button !== 'left') return undefined;
|
|
2914
|
+
if (event.width !== frame.width || event.height !== frame.height) return undefined;
|
|
2915
|
+
const x = Math.floor(Number(event.x));
|
|
2916
|
+
const y = Math.floor(Number(event.y));
|
|
2917
|
+
if (!Number.isFinite(x) || !Number.isFinite(y)) return undefined;
|
|
2918
|
+
const row = y - frame.bodyTop;
|
|
2919
|
+
if (row < 0 || row >= frame.bodyRows) return undefined;
|
|
2920
|
+
if (x < frame.paneStart || x >= frame.paneEnd) return undefined;
|
|
2921
|
+
const column = x - frame.paneStart;
|
|
2922
|
+
const line = frame.scroll + row;
|
|
2923
|
+
const hit = frame.links.find((candidate) => candidate.line === line
|
|
2924
|
+
&& column >= candidate.start && column < candidate.end);
|
|
2925
|
+
if (!hit) return undefined;
|
|
2926
|
+
const open = actions && typeof actions.openLinked === 'function' ? actions.openLinked : null;
|
|
2927
|
+
if (typeof open === 'function') {
|
|
2928
|
+
try {
|
|
2929
|
+
open({ kind: 'pullRequest', number: hit.number });
|
|
2930
|
+
} catch {
|
|
2931
|
+
// A throwing seam never breaks the view; the click is still consumed.
|
|
2932
|
+
}
|
|
2933
|
+
}
|
|
2934
|
+
return { handled: true, render: false };
|
|
2935
|
+
}
|
|
2936
|
+
|
|
2826
2937
|
// E18 (S4): a seeded page is rows, so the opening selection matches them too —
|
|
2827
2938
|
// `/issues 22` over a cache holding #22 focuses it in the FIRST frame instead
|
|
2828
2939
|
// of waiting for a read, which is what the cache exists for. It proves nothing
|
|
@@ -2865,7 +2976,7 @@ function createIssuesView(options = {}) {
|
|
|
2865
2976
|
}
|
|
2866
2977
|
}
|
|
2867
2978
|
|
|
2868
|
-
return { render, handleInput, invalidate, state };
|
|
2979
|
+
return { render, handleInput, handleMouse, invalidate, state };
|
|
2869
2980
|
}
|
|
2870
2981
|
|
|
2871
2982
|
module.exports = { createIssuesView, FOOTER_KEYS, SEARCH_KEYS };
|
package/lib/modules.js
CHANGED
|
@@ -90,6 +90,11 @@ function moduleRowsProvider({ api, notify }) {
|
|
|
90
90
|
return {
|
|
91
91
|
id: PROVIDER_ID,
|
|
92
92
|
category: CATEGORY,
|
|
93
|
+
// The `Tools` page sits right after the host's `Sections` page and before `Keymaps`. The bridge
|
|
94
|
+
// derives its page list from the order of the rows once, while it builds the menu, so this has to
|
|
95
|
+
// be the provider's request: a page appended without it lands last, after `Profiles`. A bridge
|
|
96
|
+
// that predates `categoryPlacement` ignores the field and the page opens at the end again.
|
|
97
|
+
categoryPlacement: { after: 'Sections' },
|
|
93
98
|
rows() {
|
|
94
99
|
const rows = [];
|
|
95
100
|
for (const { key, setting } of MODULES) {
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// ONE pull request preview, cloned from `lib/issue-preview.js` (prs-panel T2).
|
|
3
|
+
// Same shape, same field ORDER, same omission of absent metadata, same pending
|
|
4
|
+
// rendering — applied to a pull request: the identity block, the reviewers with
|
|
5
|
+
// their own state marks, the linked issues, and the two summary blocks S3 asks
|
|
6
|
+
// for, `Changes` and `Checks`, before the body and the comments.
|
|
7
|
+
//
|
|
8
|
+
// Purity: plain data in, styled strings out. The caller injects `paint`,
|
|
9
|
+
// `emphasis`, its own `wrap` and, for deterministic tests, the clock. No
|
|
10
|
+
// filesystem, network or registry access happens here.
|
|
11
|
+
//
|
|
12
|
+
// S6: `options.links` is the ONE published click surface. While the
|
|
13
|
+
// `linked issues:` row is composed, every `#N` token records its own cell range
|
|
14
|
+
// (`{line, start, end, number}`) instead of leaving the view to find the number
|
|
15
|
+
// again in the painted text — a number that wraps, a truncated list and a
|
|
16
|
+
// narrow pane all keep an exact target, and the whole line is never one range.
|
|
17
|
+
//
|
|
18
|
+
// The small pure helpers below (`relativeTime`, `wrapText`, the wrap memo) are
|
|
19
|
+
// deliberate copies of the issues preview's, not imports: the two panels are
|
|
20
|
+
// owned by parallel units, so neither may gain a load-time dependency on the
|
|
21
|
+
// other's module shape. Their wording is the package's one clock style, so a
|
|
22
|
+
// reader of both panes never sees two ways to say the same age.
|
|
23
|
+
|
|
24
|
+
const { ROLES: PALETTE_ROLES } = require('./tui-paint.js');
|
|
25
|
+
|
|
26
|
+
// The one role a title is painted with, read from the shared table so this
|
|
27
|
+
// preview cannot drift into its own title colour.
|
|
28
|
+
const TITLE_ROLE = PALETTE_ROLES.title;
|
|
29
|
+
|
|
30
|
+
function labelName(label) {
|
|
31
|
+
if (typeof label === 'string') return label;
|
|
32
|
+
if (label && typeof label.name === 'string') return label.name;
|
|
33
|
+
return '';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function assigneeName(entry) {
|
|
37
|
+
if (typeof entry === 'string') return entry;
|
|
38
|
+
if (entry && typeof entry.login === 'string') return entry.login;
|
|
39
|
+
return '';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function commentAuthor(comment) {
|
|
43
|
+
if (typeof comment.author === 'string') return comment.author;
|
|
44
|
+
if (comment.author && typeof comment.author.login === 'string') return comment.author.login;
|
|
45
|
+
return 'unknown';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function reviewerName(reviewer) {
|
|
49
|
+
return assigneeName(reviewer);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// The review state GitHub reports, said in the reader's words. An unknown state
|
|
53
|
+
// adds no mark at all instead of printing the raw enum.
|
|
54
|
+
const REVIEW_MARKS = {
|
|
55
|
+
REQUESTED: 'review requested',
|
|
56
|
+
APPROVED: 'approved',
|
|
57
|
+
CHANGES_REQUESTED: 'changes requested',
|
|
58
|
+
COMMENTED: 'commented',
|
|
59
|
+
DISMISSED: 'dismissed',
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
function reviewMark(state) {
|
|
63
|
+
const key = String(state || '').toUpperCase();
|
|
64
|
+
return REVIEW_MARKS[key] || '';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function numberOrNull(value) {
|
|
68
|
+
return Number.isFinite(Number(value)) ? Number(value) : null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function plural(count, single, many) {
|
|
72
|
+
return `${count} ${count === 1 ? single : many}`;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// The package's one clock style (issues view, warp facts): just now, minutes,
|
|
76
|
+
// hours, days, months, years, always with the `ago` suffix.
|
|
77
|
+
function relativeTime(iso, nowMs) {
|
|
78
|
+
const when = Date.parse(iso);
|
|
79
|
+
if (!Number.isFinite(when)) return 'unknown time';
|
|
80
|
+
const diff = (Number.isFinite(nowMs) ? nowMs : Date.now()) - when;
|
|
81
|
+
if (!Number.isFinite(diff) || diff < 0) return 'just now';
|
|
82
|
+
const minutes = Math.floor(diff / 60000);
|
|
83
|
+
if (minutes < 1) return 'just now';
|
|
84
|
+
if (minutes < 60) return `${minutes}m ago`;
|
|
85
|
+
const hours = Math.floor(minutes / 60);
|
|
86
|
+
if (hours < 24) return `${hours}h ago`;
|
|
87
|
+
const days = Math.floor(hours / 24);
|
|
88
|
+
if (days < 30) return `${days}d ago`;
|
|
89
|
+
if (days < 365) return `${Math.floor(days / 30)}mo ago`;
|
|
90
|
+
return `${Math.floor(days / 365)}y ago`;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Word wrap that never splits a word unless the word alone is wider than the
|
|
94
|
+
// pane, and that keeps blank lines as blank rows.
|
|
95
|
+
function wrapText(text, width) {
|
|
96
|
+
const room = Math.max(1, Math.floor(Number(width) || 1));
|
|
97
|
+
const out = [];
|
|
98
|
+
for (const paragraph of String(text ?? '').split('\n')) {
|
|
99
|
+
if (paragraph.trim() === '') {
|
|
100
|
+
out.push('');
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const words = paragraph.split(/\s+/).filter(Boolean);
|
|
104
|
+
let line = '';
|
|
105
|
+
for (const word of words) {
|
|
106
|
+
if (line !== '' && (line + ' ' + word).length <= room) {
|
|
107
|
+
line += ' ' + word;
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
if (line !== '') out.push(line);
|
|
111
|
+
let tail = word;
|
|
112
|
+
while (tail.length > room) {
|
|
113
|
+
out.push(tail.slice(0, room));
|
|
114
|
+
tail = tail.slice(room);
|
|
115
|
+
}
|
|
116
|
+
line = tail;
|
|
117
|
+
}
|
|
118
|
+
out.push(line);
|
|
119
|
+
}
|
|
120
|
+
return out.length === 0 ? [''] : out;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function plainWidth(text) {
|
|
124
|
+
return [...String(text).replace(/\x1b\[[0-9;]*m/g, '')].length;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const WRAP_CACHE_ENTRIES = 400;
|
|
128
|
+
const WRAP_CACHE_ROWS = 20000;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* A bounded memo of finished wraps, keyed by width + the exact text, so an
|
|
132
|
+
* unchanged repaint wraps nothing while a changed body or pane always misses.
|
|
133
|
+
* `stats` makes "a repaint re-wraps nothing" observable.
|
|
134
|
+
*/
|
|
135
|
+
function createWrapCache(limit = WRAP_CACHE_ENTRIES) {
|
|
136
|
+
const max = Number.isFinite(limit) && limit > 0 ? Math.floor(limit) : WRAP_CACHE_ENTRIES;
|
|
137
|
+
const entries = new Map();
|
|
138
|
+
const stats = { wraps: 0, hits: 0 };
|
|
139
|
+
|
|
140
|
+
function wrap(text, width) {
|
|
141
|
+
const room = Math.max(1, Math.floor(Number(width) || 1));
|
|
142
|
+
const source = String(text ?? '');
|
|
143
|
+
const key = `${room}\u0000${source}`;
|
|
144
|
+
const cached = entries.get(key);
|
|
145
|
+
if (cached) {
|
|
146
|
+
stats.hits += 1;
|
|
147
|
+
entries.delete(key);
|
|
148
|
+
entries.set(key, cached);
|
|
149
|
+
return cached;
|
|
150
|
+
}
|
|
151
|
+
stats.wraps += 1;
|
|
152
|
+
const lines = wrapText(source, room);
|
|
153
|
+
if (lines.length <= WRAP_CACHE_ROWS) {
|
|
154
|
+
entries.set(key, lines);
|
|
155
|
+
while (entries.size > max) {
|
|
156
|
+
const oldest = entries.keys().next();
|
|
157
|
+
if (oldest.done) break;
|
|
158
|
+
entries.delete(oldest.value);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return lines;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return { wrap, stats };
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const defaultWrapCache = createWrapCache();
|
|
168
|
+
|
|
169
|
+
function identity(_role, text) {
|
|
170
|
+
return String(text);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function bold(text) {
|
|
174
|
+
return String(text);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// The `linked issues:` row, composed token by token so every number keeps its
|
|
178
|
+
// own cell range even when the pane forces the row onto several lines.
|
|
179
|
+
function linkedIssuesBlock(numbers, truncated, width, measure) {
|
|
180
|
+
const lines = [];
|
|
181
|
+
const ranges = [];
|
|
182
|
+
let text = '';
|
|
183
|
+
let length = 0;
|
|
184
|
+
const push = (piece) => (text += piece);
|
|
185
|
+
const setLength = () => { length = measure(text); };
|
|
186
|
+
const append = (piece, link) => {
|
|
187
|
+
const current = text === '' ? 0 : length;
|
|
188
|
+
if (current > 0 && measure(piece) > width - current) {
|
|
189
|
+
lines.push(text.replace(/^\s+/g, ''));
|
|
190
|
+
text = '';
|
|
191
|
+
length = 0;
|
|
192
|
+
piece = piece.replace(/^\s+/, '');
|
|
193
|
+
}
|
|
194
|
+
const before = text === '' ? 0 : length;
|
|
195
|
+
// The separator between two numbers belongs to the row, not to the click
|
|
196
|
+
// target: the range starts at the `#` itself.
|
|
197
|
+
const lead = measure(piece) - measure(piece.replace(/^\s+/, ''));
|
|
198
|
+
push(piece);
|
|
199
|
+
setLength();
|
|
200
|
+
if (link !== undefined) ranges.push({ line: lines.length, start: before + lead, end: length, number: link });
|
|
201
|
+
};
|
|
202
|
+
append('linked issues:');
|
|
203
|
+
numbers.forEach((number, at) => {
|
|
204
|
+
// The separator is its own piece, so the range below starts at the `#`
|
|
205
|
+
// itself and never covers the comma or the space before it.
|
|
206
|
+
append(at === 0 ? ' ' : ', ');
|
|
207
|
+
append(`#${number}`, number);
|
|
208
|
+
});
|
|
209
|
+
if (truncated) append(', …');
|
|
210
|
+
lines.push(text.replace(/^\s+/g, ''));
|
|
211
|
+
return { lines, ranges };
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* The preview pane for ONE pull request: identity and state, labels, assignees
|
|
216
|
+
* and reviewers with their state marks, author and ages, the reaction/comment
|
|
217
|
+
* counters, the linked issues, the `Changes` and `Checks` summaries, then the
|
|
218
|
+
* body and every comment (S3).
|
|
219
|
+
*
|
|
220
|
+
* @returns {string[]} styled lines, already wrapped to `options.width`
|
|
221
|
+
*/
|
|
222
|
+
function pullRequestDetailLines(pullRequest, comments, options = {}) {
|
|
223
|
+
const entry = pullRequest && typeof pullRequest === 'object' ? pullRequest : {};
|
|
224
|
+
const settings = options && typeof options === 'object' ? options : {};
|
|
225
|
+
const width = Math.max(1, Math.floor(Number(settings.width) || 1));
|
|
226
|
+
const paint = typeof settings.paint === 'function' ? settings.paint : identity;
|
|
227
|
+
const emphasize = typeof settings.emphasis === 'function' ? settings.emphasis : bold;
|
|
228
|
+
const cache = settings.cache && typeof settings.cache.wrap === 'function' ? settings.cache : defaultWrapCache;
|
|
229
|
+
const wrap = typeof settings.wrap === 'function' ? settings.wrap : (text) => cache.wrap(text, width);
|
|
230
|
+
const measure = typeof settings.measure === 'function' ? settings.measure : plainWidth;
|
|
231
|
+
const links = Array.isArray(settings.links) ? settings.links : null;
|
|
232
|
+
const list = Array.isArray(comments) ? comments : [];
|
|
233
|
+
const nowMs = Number.isFinite(settings.now) ? settings.now : Date.now();
|
|
234
|
+
|
|
235
|
+
const out = [];
|
|
236
|
+
const flush = (text) => {
|
|
237
|
+
for (const row of wrap(String(text))) out.push(row);
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
// S13: the title asks for the shared title role, and keeps its emphasis.
|
|
241
|
+
out.push(emphasize(paint(TITLE_ROLE, `#${entry.number} ${entry.title || '(no title)'}`)));
|
|
242
|
+
// S3: the state row says `[draft]` for a draft, never a bare `[open]`.
|
|
243
|
+
const state = entry.isDraft === true ? 'draft' : String(entry.state || 'open').toLowerCase();
|
|
244
|
+
out.push(paint(state === 'open' ? 'accent' : 'muted', `[${state}]`));
|
|
245
|
+
|
|
246
|
+
const labels = (Array.isArray(entry.labels) ? entry.labels : []).map(labelName).filter(Boolean);
|
|
247
|
+
flush(labels.length > 0 ? `labels: ${labels.join(', ')}` : paint('muted', '(no labels)'));
|
|
248
|
+
const assignees = (Array.isArray(entry.assignees) ? entry.assignees : []).map(assigneeName).filter(Boolean);
|
|
249
|
+
if (assignees.length > 0) flush(`assignees: ${assignees.join(', ')}`);
|
|
250
|
+
const reviewers = (Array.isArray(entry.reviewers) ? entry.reviewers : [])
|
|
251
|
+
.map((reviewer) => {
|
|
252
|
+
const login = reviewerName(reviewer);
|
|
253
|
+
if (login === '') return '';
|
|
254
|
+
const mark = reviewMark(reviewer && reviewer.state);
|
|
255
|
+
return mark === '' ? login : `${login} (${mark})`;
|
|
256
|
+
})
|
|
257
|
+
.filter(Boolean);
|
|
258
|
+
if (reviewers.length > 0) flush(`reviewers: ${reviewers.join(', ')}`);
|
|
259
|
+
|
|
260
|
+
// S16 of the issues pane, kept here: while the richer read is in flight the
|
|
261
|
+
// row's own facts are already painted and the read is NAMED — the body, the
|
|
262
|
+
// counters and the summaries are not invented from a row that never carried
|
|
263
|
+
// them, and a pending row publishes no click range.
|
|
264
|
+
if (settings.pending === true) {
|
|
265
|
+
if (typeof entry.author === 'string' && entry.author.length > 0) flush(`by ${entry.author}`);
|
|
266
|
+
out.push(paint('muted', 'loading…'));
|
|
267
|
+
return out;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
flush(`by ${entry.author || 'unknown'} · created ${relativeTime(entry.createdAt, nowMs)} · updated ${relativeTime(entry.updatedAt, nowMs)}`);
|
|
271
|
+
const plusOne = entry.reactions && Number.isFinite(Number(entry.reactions.plusOne))
|
|
272
|
+
? Number(entry.reactions.plusOne)
|
|
273
|
+
: 0;
|
|
274
|
+
const stored = Number.isFinite(Number(entry.commentsCount)) ? Number(entry.commentsCount) : 0;
|
|
275
|
+
flush(`👍 ${plusOne} · ${Math.max(stored, list.length)} comments`);
|
|
276
|
+
|
|
277
|
+
// S6: every linked issue is named by number, ascending, never counted; a
|
|
278
|
+
// capped page stays honest with a trailing ellipsis.
|
|
279
|
+
const linked = (Array.isArray(entry.linkedIssues) ? entry.linkedIssues : [])
|
|
280
|
+
.filter((number) => Number.isInteger(number) && number > 0);
|
|
281
|
+
if (linked.length > 0) {
|
|
282
|
+
const block = linkedIssuesBlock(linked, entry.linkedIssuesTruncated === true, width, measure);
|
|
283
|
+
const base = out.length;
|
|
284
|
+
for (const line of block.lines) out.push(line);
|
|
285
|
+
if (links !== null) {
|
|
286
|
+
for (const range of block.ranges) {
|
|
287
|
+
links.push({ line: base + range.line, start: range.start, end: range.end, number: range.number });
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// S3: the two summary blocks, in the contract's order and only when the read
|
|
293
|
+
// carried the numbers they summarise.
|
|
294
|
+
const files = numberOrNull(entry.changedFiles);
|
|
295
|
+
const additions = numberOrNull(entry.additions);
|
|
296
|
+
const deletions = numberOrNull(entry.deletions);
|
|
297
|
+
const commits = numberOrNull(entry.commits);
|
|
298
|
+
if (files !== null || additions !== null || deletions !== null || commits !== null) {
|
|
299
|
+
out.push(emphasize('Changes'));
|
|
300
|
+
if (files !== null) {
|
|
301
|
+
const plus = additions === null ? '' : ` +${additions}`;
|
|
302
|
+
const minus = deletions === null ? '' : ` -${deletions}`;
|
|
303
|
+
flush(`${plural(files, 'file', 'files')} changed${plus}${minus}`);
|
|
304
|
+
}
|
|
305
|
+
if (commits !== null) {
|
|
306
|
+
const age = Number.isFinite(Date.parse(entry.committedAt)) ? ` ${relativeTime(entry.committedAt, nowMs)}` : '';
|
|
307
|
+
flush(`${plural(commits, 'commit', 'commits')}${age}`);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const checks = entry.checks && typeof entry.checks === 'object' ? entry.checks : null;
|
|
312
|
+
if (checks !== null) {
|
|
313
|
+
const total = numberOrNull(checks.total);
|
|
314
|
+
const failed = numberOrNull(checks.failed) || 0;
|
|
315
|
+
const pending = numberOrNull(checks.pending) || 0;
|
|
316
|
+
const stateWord = String(checks.state || '').toUpperCase();
|
|
317
|
+
out.push(emphasize('Checks'));
|
|
318
|
+
if (total === null) {
|
|
319
|
+
flush(failed > 0 ? `${plural(failed, 'check', 'checks')} failed` : 'checks unknown');
|
|
320
|
+
} else if (total === 0) {
|
|
321
|
+
flush('no checks');
|
|
322
|
+
} else {
|
|
323
|
+
let word;
|
|
324
|
+
if (failed > 0) word = `${failed} failed`;
|
|
325
|
+
else if (stateWord === 'SUCCESS') word = 'all passed';
|
|
326
|
+
else if (stateWord === 'PENDING' || pending > 0) word = 'pending';
|
|
327
|
+
else if (stateWord === 'NONE') word = 'no checks';
|
|
328
|
+
else word = stateWord === '' ? 'unknown' : stateWord.toLowerCase();
|
|
329
|
+
flush(`${plural(total, 'check', 'checks')} · ${word}`);
|
|
330
|
+
}
|
|
331
|
+
const failing = (Array.isArray(checks.failing) ? checks.failing : []).filter((name) => typeof name === 'string' && name !== '');
|
|
332
|
+
if (failing.length > 0) flush(`failing: ${failing.join(', ')}`);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// A relation that could not be read paints NOTHING: the pane stays quiet,
|
|
336
|
+
// exactly as it does for a relation the pull request does not have.
|
|
337
|
+
out.push('');
|
|
338
|
+
for (const row of wrap(entry.body || '(no description)')) out.push(row);
|
|
339
|
+
list.forEach((comment, at) => {
|
|
340
|
+
out.push('');
|
|
341
|
+
out.push(paint('border', `─ ${commentAuthor(comment)} · ${relativeTime(comment.createdAt, nowMs)} ─`));
|
|
342
|
+
const body = typeof comment.body === 'string' ? comment.body : '';
|
|
343
|
+
for (const row of wrap(body)) out.push(row);
|
|
344
|
+
if (at === list.length - 1) out.push(paint('dim', '(end of pull request)'));
|
|
345
|
+
});
|
|
346
|
+
if (list.length === 0) {
|
|
347
|
+
out.push('');
|
|
348
|
+
out.push(paint('dim', '(end of pull request)'));
|
|
349
|
+
}
|
|
350
|
+
return out;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
module.exports = { pullRequestDetailLines, relativeTime, wrapText, createWrapCache, defaultWrapCache };
|