@nanocollective/roster 0.1.0-alpha.8 → 0.1.0-beta.1
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 -0
- package/dist/cli.js +4084 -1936
- package/dist/worker/assets/assets/css/base.css +312 -0
- package/dist/worker/assets/assets/css/brain.css +116 -0
- package/dist/worker/assets/assets/css/diff.css +33 -0
- package/dist/worker/assets/assets/css/graph.css +39 -0
- package/dist/worker/assets/assets/css/health.css +75 -0
- package/dist/worker/assets/assets/css/home.css +101 -0
- package/dist/worker/assets/assets/css/inbox.css +199 -0
- package/dist/worker/assets/assets/css/layout.css +175 -0
- package/dist/worker/assets/assets/css/markdown.css +96 -0
- package/dist/worker/assets/assets/css/runs.css +13 -0
- package/dist/worker/assets/assets/css/search.css +48 -0
- package/dist/worker/assets/assets/css/setup.css +194 -0
- package/dist/worker/assets/assets/js/api.js +161 -0
- package/dist/worker/assets/assets/js/app.js +465 -0
- package/dist/worker/assets/assets/js/dialog.js +196 -0
- package/dist/worker/assets/assets/js/dom.js +131 -0
- package/dist/worker/assets/assets/js/homesort.js +174 -0
- package/dist/worker/assets/assets/js/icons.js +142 -0
- package/dist/worker/assets/assets/js/inflight.js +18 -0
- package/dist/worker/assets/assets/js/lightbox.js +273 -0
- package/dist/worker/assets/assets/js/md.js +406 -0
- package/dist/worker/assets/assets/js/mdedit.js +84 -0
- package/dist/worker/assets/assets/js/mention.js +264 -0
- package/dist/worker/assets/assets/js/readiness.js +70 -0
- package/dist/worker/assets/assets/js/refresh.js +197 -0
- package/dist/worker/assets/assets/js/router.js +20 -0
- package/dist/worker/assets/assets/js/search.js +366 -0
- package/dist/worker/assets/assets/js/state.js +213 -0
- package/dist/worker/assets/assets/js/textdiff.js +96 -0
- package/dist/worker/assets/assets/js/views/app.js +145 -0
- package/dist/worker/assets/assets/js/views/brain.js +260 -0
- package/dist/worker/assets/assets/js/views/changed.js +157 -0
- package/dist/worker/assets/assets/js/views/checklist.js +115 -0
- package/dist/worker/assets/assets/js/views/credential.js +84 -0
- package/dist/worker/assets/assets/js/views/docs.js +174 -0
- package/dist/worker/assets/assets/js/views/files.js +139 -0
- package/dist/worker/assets/assets/js/views/graph.js +436 -0
- package/dist/worker/assets/assets/js/views/health.js +304 -0
- package/dist/worker/assets/assets/js/views/hire.js +593 -0
- package/dist/worker/assets/assets/js/views/home.js +585 -0
- package/dist/worker/assets/assets/js/views/inbox.js +1558 -0
- package/dist/worker/assets/assets/js/views/memory.js +150 -0
- package/dist/worker/assets/assets/js/views/org.js +195 -0
- package/dist/worker/assets/assets/js/views/orgedit.js +240 -0
- package/dist/worker/assets/assets/js/views/paste.js +216 -0
- package/dist/worker/assets/assets/js/views/prompt.js +457 -0
- package/dist/worker/assets/assets/js/views/repos.js +97 -0
- package/dist/worker/assets/assets/js/views/runonce.js +94 -0
- package/dist/worker/assets/assets/js/views/runs.js +182 -0
- package/dist/worker/assets/assets/js/views/setup.js +557 -0
- package/dist/worker/assets/assets/js/views/staff.js +291 -0
- package/dist/worker/assets/assets/js/views/todo.js +62 -0
- package/dist/worker/assets/assets/js/yaml.js +134 -0
- package/dist/worker/assets/docs-images/brain.jpg +0 -0
- package/dist/worker/assets/docs-images/home.jpg +0 -0
- package/dist/worker/assets/docs-images/org.jpg +0 -0
- package/dist/worker/assets/docs-images/prompt.jpg +0 -0
- package/dist/worker/assets/docs-images/setup-org.jpg +0 -0
- package/dist/worker/assets/docs-images/setup-plan.jpg +0 -0
- package/dist/worker/assets/docs-images/staff.jpg +0 -0
- package/dist/worker/assets/index.html +82 -0
- package/dist/worker/index.js +4430 -0
- package/docs/README.md +2 -2
- package/docs/architecture.md +1 -1
- package/docs/charters/analyst.md +65 -0
- package/docs/charters/community.md +63 -0
- package/docs/charters/designer.md +65 -0
- package/docs/charters/devops.md +65 -0
- package/docs/charters/pm.md +70 -0
- package/docs/charters/qa.md +65 -0
- package/docs/charters/writer.md +63 -0
- package/docs/commands.md +13 -3
- package/docs/concepts.md +33 -20
- package/docs/cost.md +3 -3
- package/docs/developing.md +27 -9
- package/docs/doctor-codes.md +3 -1
- package/docs/export.md +2 -0
- package/docs/getting-started.md +44 -27
- package/docs/hosting.md +89 -43
- package/docs/images/brain.jpg +0 -0
- package/docs/images/home.jpg +0 -0
- package/docs/images/org.jpg +0 -0
- package/docs/images/prompt.jpg +0 -0
- package/docs/images/staff.jpg +0 -0
- package/docs/manual-steps.md +3 -2
- package/docs/org-yaml.md +3 -0
- package/docs/portal.md +143 -45
- package/docs/prompts.md +6 -0
- package/docs/security.md +57 -11
- package/docs/session-workflow.md +14 -0
- package/docs/staff-yaml.md +17 -1
- package/docs/upgrading.md +3 -3
- package/docs/writing-a-charter.md +19 -6
- package/package.json +4 -3
- package/templates/brain/.github/workflows/%%STAFF%%-daily.yaml +20 -1
- package/templates/brain/.github/workflows/%%STAFF%%-mention.yaml +53 -13
- package/templates/brain/staff.yaml +4 -1
- package/templates/briefs/amend.md +4 -3
- package/templates/briefs/priorities.md +46 -0
- package/templates/ops/.github/workflows/session.yaml +137 -3
- package/templates/ops/compose.mjs +35 -8
- package/templates/ops/org/operating.md +29 -10
- package/templates/ops/prompts/daily.md +23 -4
- package/templates/ops/prompts/mention.md +19 -0
- package/templates/ops/run-record.mjs +5 -3
- package/templates/portal/css/base.css +34 -0
- package/templates/portal/css/health.css +14 -1
- package/templates/portal/css/home.css +101 -0
- package/templates/portal/css/inbox.css +21 -4
- package/templates/portal/css/layout.css +29 -3
- package/templates/portal/css/markdown.css +19 -0
- package/templates/portal/css/search.css +48 -0
- package/templates/portal/css/setup.css +79 -4
- package/templates/portal/index.html +15 -9
- package/templates/portal/js/api.js +30 -4
- package/templates/portal/js/app.js +90 -7
- package/templates/portal/js/dialog.js +36 -0
- package/templates/portal/js/homesort.js +174 -0
- package/templates/portal/js/icons.js +41 -0
- package/templates/portal/js/inflight.js +18 -0
- package/templates/portal/js/md.js +5 -2
- package/templates/portal/js/mdedit.js +84 -0
- package/templates/portal/js/readiness.js +70 -0
- package/templates/portal/js/refresh.js +10 -2
- package/templates/portal/js/search.js +366 -0
- package/templates/portal/js/state.js +11 -5
- package/templates/portal/js/views/app.js +1 -2
- package/templates/portal/js/views/brain.js +1 -1
- package/templates/portal/js/views/checklist.js +19 -4
- package/templates/portal/js/views/credential.js +42 -51
- package/templates/portal/js/views/health.js +11 -6
- package/templates/portal/js/views/hire.js +593 -0
- package/templates/portal/js/views/home.js +585 -0
- package/templates/portal/js/views/inbox.js +237 -68
- package/templates/portal/js/views/org.js +31 -111
- package/templates/portal/js/views/orgedit.js +240 -0
- package/templates/portal/js/views/paste.js +111 -66
- package/templates/portal/js/views/prompt.js +94 -40
- package/templates/portal/js/views/repos.js +10 -10
- package/templates/portal/js/views/runs.js +21 -4
- package/templates/portal/js/views/setup.js +130 -163
- package/templates/portal/js/views/staff.js +181 -301
- package/templates/portal/js/views/todo.js +62 -0
|
@@ -0,0 +1,1558 @@
|
|
|
1
|
+
/* The inbox: everything open across the org, and the thread beside it. */
|
|
2
|
+
|
|
3
|
+
import { getLabels, getPr, getThread, post, upload } from "../api.js";
|
|
4
|
+
import { askText, askYes } from "../dialog.js";
|
|
5
|
+
import { ago, el, esc, markCurrent, skeleton } from "../dom.js";
|
|
6
|
+
import { icon, iconHTML, staffIcon } from "../icons.js";
|
|
7
|
+
import { mdlite } from "../md.js";
|
|
8
|
+
import { attachMentions } from "../mention.js";
|
|
9
|
+
import { ensureInbox, refreshAll, stampCounts } from "../refresh.js";
|
|
10
|
+
import { humanLabel, humansOf, isHuman, S, writeHash } from "../state.js";
|
|
11
|
+
import { renderDiff } from "./changed.js";
|
|
12
|
+
|
|
13
|
+
/* The labels roster itself creates, and what each one means about urgency. Everything else is
|
|
14
|
+
the org's own vocabulary and stays plain: colouring a word this file has never heard of
|
|
15
|
+
would be guessing. */
|
|
16
|
+
const LABEL_TONE = {
|
|
17
|
+
decision: "hot", blocked: "hot", review: "warm", submit: "warm",
|
|
18
|
+
idea: "cool", build: "cool", setup: "cool", data: "cool",
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A label's tone.
|
|
23
|
+
*
|
|
24
|
+
* `roster hire` puts a label on every tracker named after the human's marker, so "this is on a
|
|
25
|
+
* person" is a label like `will` or `sam` — it used to be spelled `will` in the map above,
|
|
26
|
+
* which coloured exactly one org's and left every other org's looking like an ordinary tag.
|
|
27
|
+
* It comes off org.yaml now, so it is right wherever this runs.
|
|
28
|
+
*/
|
|
29
|
+
function tone(label) {
|
|
30
|
+
if (LABEL_TONE[label]) return LABEL_TONE[label];
|
|
31
|
+
const name = String(label).toLowerCase();
|
|
32
|
+
return humansOf().some(
|
|
33
|
+
(h) => String(h.marker ?? "").toLowerCase() === name ||
|
|
34
|
+
String(h.github ?? "").toLowerCase() === name,
|
|
35
|
+
)
|
|
36
|
+
? "hot"
|
|
37
|
+
: "";
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The staff member this repo is the tracker for, or null.
|
|
42
|
+
*
|
|
43
|
+
* A staff member's caller workflow lives in their own brain repo and gates on their `@handle`
|
|
44
|
+
* appearing there. So a mention is a mechanism in exactly one repository per person, and
|
|
45
|
+
* decoration in every other — including the product repos, where the pull requests are.
|
|
46
|
+
*
|
|
47
|
+
* That asymmetry is invisible on the page otherwise: the reply box takes `@cto` anywhere and
|
|
48
|
+
* posts it anywhere, and the difference between "asked the CTO" and "typed their name" is a
|
|
49
|
+
* workflow file in another repository. This is what the two things below use to say so.
|
|
50
|
+
*/
|
|
51
|
+
function listener(repo) {
|
|
52
|
+
return S.data.staff.find((s) => s.brain && s.brain === repo) ?? null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The handles mentioned in some text, as staff members. */
|
|
56
|
+
function mentioned(text) {
|
|
57
|
+
const said = String(text ?? "");
|
|
58
|
+
return S.data.staff.filter((s) => {
|
|
59
|
+
const at = String(s.mention ?? "@" + s.handle);
|
|
60
|
+
return new RegExp("(^|\\s)" + at.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + "(\\s|$)", "i").test(said);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Half-written replies, by thread, for as long as the page is open. */
|
|
65
|
+
const DRAFTS = new Map();
|
|
66
|
+
|
|
67
|
+
/** A pull request's commits and diff, once fetched. Same lifetime, same reason. */
|
|
68
|
+
const PRS = new Map();
|
|
69
|
+
|
|
70
|
+
/* Bookkeeping. Real history, worth being able to see, but not what you opened the thread
|
|
71
|
+
to read — so a run of it folds away. */
|
|
72
|
+
const QUIET = new Set([
|
|
73
|
+
"labeled", "unlabeled", "assigned", "unassigned", "renamed",
|
|
74
|
+
"review-requested", "ready-for-review",
|
|
75
|
+
]);
|
|
76
|
+
|
|
77
|
+
/* Whose work an item is. The inbox is org-wide, so without this the CTO's product PRs and
|
|
78
|
+
the CMO's are one undifferentiated list — which is the complaint.
|
|
79
|
+
In descending order of confidence: it lives in their brain, their own app wrote it, a peer
|
|
80
|
+
addressed it to them with a from-<handle> label, it is assigned to their app, or the
|
|
81
|
+
shared public identity wrote it in a repo they work in.
|
|
82
|
+
That last one matches both of them on purpose. Both agents push through the same robot, so
|
|
83
|
+
the honest answer is "one of these two" — better than hiding real work behind a filter. */
|
|
84
|
+
export function belongsTo(item, s) {
|
|
85
|
+
if (!s) return true;
|
|
86
|
+
if (item.repo === s.brain) return true;
|
|
87
|
+
const solo = s.soloBots ?? [];
|
|
88
|
+
if (solo.includes(item.author)) return true;
|
|
89
|
+
if ((item.labels ?? []).some((l) => l === "from-" + s.handle || l === s.handle)) return true;
|
|
90
|
+
if ((item.assignees ?? []).some((a) => solo.includes(a))) return true;
|
|
91
|
+
if ((s.sharedBots ?? []).includes(item.author) && (s.worksIn ?? []).includes(item.repo)) return true;
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/* Threads read so far, by repo#number, kept for the session. Each is reused while its
|
|
96
|
+
updatedAt matches the list's, so a thread is fetched again only when it has changed. */
|
|
97
|
+
const THREADS = new Map();
|
|
98
|
+
|
|
99
|
+
export const viewInbox = (m) => inboxScreen(m, {});
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The same screen, scoped to pull requests.
|
|
103
|
+
*
|
|
104
|
+
* Its own place in the sidebar because open PRs are a different question from an inbox: an
|
|
105
|
+
* inbox is what is waiting on you, and a PR is work that is finished and waiting on a merge.
|
|
106
|
+
* Everything else — the threads, the reactions, the commits and the diff — is the one
|
|
107
|
+
* implementation, because a PR is a thread with more on it and not a second kind of screen.
|
|
108
|
+
*/
|
|
109
|
+
export const viewPrs = (m) => inboxScreen(m, { prs: true });
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* One thread, drawn into `host` on its own: the header, its actions, the reply box and the
|
|
113
|
+
* conversation, with no list beside it. Home opens a card this way, in a side sheet.
|
|
114
|
+
*
|
|
115
|
+
* It is the same screen as Trackers, built off-page, with only its viewer kept. Replying,
|
|
116
|
+
* closing and merging repaint a list nobody can see and then reopen this thread, which is
|
|
117
|
+
* what they do on Trackers too.
|
|
118
|
+
*/
|
|
119
|
+
export function threadInto(host, ref) {
|
|
120
|
+
/* Read fresh. Home can be minutes behind GitHub, and the reason to open something is usually
|
|
121
|
+
to read the reply that made its row change. Reading it again also brings the row up to
|
|
122
|
+
date, so Home is right when the sheet closes. */
|
|
123
|
+
const item = (S.inbox?.items ?? []).find((i) => i.repo === ref.repo && i.number === ref.number);
|
|
124
|
+
if (item) {
|
|
125
|
+
THREADS.delete(item.repo + "#" + item.number);
|
|
126
|
+
item.partial = true;
|
|
127
|
+
}
|
|
128
|
+
host.append(inboxScreen(el("div"), { prs: ref.kind === "pr", only: ref }));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function inboxScreen(m, opts) {
|
|
132
|
+
/* "Pending work", not "Pull requests". Every one of these is a piece of work a staff member
|
|
133
|
+
has finished and cannot land on their own, which is the thing you are being asked about.
|
|
134
|
+
That it arrives as a pull request is how it is delivered, not what it is. */
|
|
135
|
+
m.append(el("h1", { textContent: opts.prs ? "Pending work" : "Trackers" }));
|
|
136
|
+
const sub = el("p", {
|
|
137
|
+
className: "sub",
|
|
138
|
+
textContent: opts.prs
|
|
139
|
+
? "Work the staff have finished and cannot land themselves."
|
|
140
|
+
: "Every issue on each staff member's tracker and the product repos. What needs you is on Home.",
|
|
141
|
+
});
|
|
142
|
+
m.append(sub);
|
|
143
|
+
|
|
144
|
+
const search = el("input", {
|
|
145
|
+
type: "search",
|
|
146
|
+
placeholder: "Filter by title, label, repo…",
|
|
147
|
+
value: S.query,
|
|
148
|
+
});
|
|
149
|
+
/* Open or closed, as a toggle. Who and what (a staff member, what is on you, decisions)
|
|
150
|
+
moved to the sidebar under Inbox, where a row of dropdowns used to be. */
|
|
151
|
+
if (S.inboxState === "all") S.inboxState = "";
|
|
152
|
+
const toggle = el("div", { className: "modes inboxstate" });
|
|
153
|
+
for (const [value, label] of [["", "Open"], ["closed", "Closed"]]) {
|
|
154
|
+
const b = el("button", { className: "mode", textContent: label });
|
|
155
|
+
b.classList.toggle("on", (S.inboxState || "") === value);
|
|
156
|
+
b.onclick = () => {
|
|
157
|
+
S.inboxState = value;
|
|
158
|
+
for (const x of toggle.children) x.classList.toggle("on", x === b);
|
|
159
|
+
writeHash(false);
|
|
160
|
+
paint();
|
|
161
|
+
};
|
|
162
|
+
toggle.append(b);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const refresh = el("button", { className: "iconbtn", title: "Refresh from GitHub" });
|
|
166
|
+
refresh.innerHTML = '<span class="sync">' + iconHTML("refresh") + "</span>";
|
|
167
|
+
const controls = [search, toggle, refresh];
|
|
168
|
+
// A pull request comes from a branch, so there is nothing here that could open one.
|
|
169
|
+
if (!opts.prs) {
|
|
170
|
+
const newBtn = el("button", { className: "ghbtn", textContent: "New issue" });
|
|
171
|
+
newBtn.onclick = () => {
|
|
172
|
+
delete viewer.dataset.wait;
|
|
173
|
+
newIssueForm(viewer);
|
|
174
|
+
};
|
|
175
|
+
controls.push(newBtn);
|
|
176
|
+
}
|
|
177
|
+
m.append(el("div", { className: "row inboxbar", style: "margin-bottom:16px" }, controls));
|
|
178
|
+
|
|
179
|
+
const split = el("div", { className: "split" });
|
|
180
|
+
const list = el("div", { className: "tree" });
|
|
181
|
+
const viewer = el("div", { className: "viewer" });
|
|
182
|
+
split.append(list, viewer);
|
|
183
|
+
m.append(split);
|
|
184
|
+
|
|
185
|
+
search.oninput = () => { S.query = search.value; writeHash(false); paint(); };
|
|
186
|
+
refresh.onclick = () => { refresh.classList.add("spin"); load(true); };
|
|
187
|
+
|
|
188
|
+
if (S.inbox) { stampCounts(); paint(); restore(); } else load(false);
|
|
189
|
+
if (opts.only) return viewer;
|
|
190
|
+
|
|
191
|
+
/** A `?t=` in the URL names a thread. It used to be read into the state and then never
|
|
192
|
+
acted on, because only the already-loaded branch opened one. */
|
|
193
|
+
function restore() {
|
|
194
|
+
if (opts.only) {
|
|
195
|
+
openThread(opts.only);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (!S.inboxOpen) return;
|
|
199
|
+
// The two screens share one open thread, and each holds half the org. Whatever was open on
|
|
200
|
+
// the other one is not in this list, so it is dropped rather than opened beside it.
|
|
201
|
+
if (!!opts.prs !== (S.inboxOpen.kind === "pr")) {
|
|
202
|
+
S.inboxOpen = null;
|
|
203
|
+
writeHash(false);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
openThread(S.inboxOpen);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Fetch, through the one request the shell may already have in flight.
|
|
211
|
+
*
|
|
212
|
+
* Waiting looks like what is coming: rows in the list, a thread in the viewer. The reads run
|
|
213
|
+
* across every repo in the org, so on a cold cache this is seconds, and seconds of a blank
|
|
214
|
+
* panel beside a blank panel reads as a page that has failed rather than one that is working.
|
|
215
|
+
*/
|
|
216
|
+
async function load(force) {
|
|
217
|
+
sub.dataset.busy = "1";
|
|
218
|
+
list.replaceChildren(
|
|
219
|
+
el("p", { className: "skhead", textContent: "Asking GitHub…" }),
|
|
220
|
+
...skeleton("row", 7),
|
|
221
|
+
);
|
|
222
|
+
/* The flag is what makes the placeholder safe to remove: you can open New issue while this
|
|
223
|
+
is still running, and the arriving inbox must not throw away what you have started
|
|
224
|
+
typing. Anything that writes real content into the viewer clears it. */
|
|
225
|
+
if (!S.inboxOpen) {
|
|
226
|
+
viewer.dataset.wait = "1";
|
|
227
|
+
viewer.replaceChildren(...skeleton("head", 1), ...skeleton("line", 6));
|
|
228
|
+
}
|
|
229
|
+
try {
|
|
230
|
+
await ensureInbox(force);
|
|
231
|
+
} catch (e) {
|
|
232
|
+
refresh.classList.remove("spin");
|
|
233
|
+
delete sub.dataset.busy;
|
|
234
|
+
clearPlaceholder();
|
|
235
|
+
list.replaceChildren(
|
|
236
|
+
el("p", { className: "empty err", textContent: "Could not reach GitHub: " + e.message }),
|
|
237
|
+
);
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
refresh.classList.remove("spin");
|
|
241
|
+
delete sub.dataset.busy;
|
|
242
|
+
stampCounts();
|
|
243
|
+
paint();
|
|
244
|
+
restore();
|
|
245
|
+
// Nothing was selected, so the placeholder thread has nothing to become.
|
|
246
|
+
clearPlaceholder();
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** Take the waiting shapes away, and leave alone anything that replaced them. */
|
|
250
|
+
function clearPlaceholder() {
|
|
251
|
+
if (viewer.dataset.wait !== "1") return;
|
|
252
|
+
delete viewer.dataset.wait;
|
|
253
|
+
viewer.replaceChildren();
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function paint() {
|
|
257
|
+
if (!S.inbox) return;
|
|
258
|
+
const q = S.query.trim().toLowerCase();
|
|
259
|
+
// "On you" is on any of the humans this org answers to, not only the first one.
|
|
260
|
+
const onAHuman = (i) => (i.assignees ?? []).some(isHuman);
|
|
261
|
+
|
|
262
|
+
// The sidebar's filters are the inbox's. Pending work has no control for them, so it ignores them.
|
|
263
|
+
const staffPick = opts.prs ? "" : S.inboxStaff;
|
|
264
|
+
// "Issues" is the product repos: every repo a staff member works in.
|
|
265
|
+
const products = new Set(S.data.staff.flatMap((s) => s.worksIn ?? []));
|
|
266
|
+
const issuesOnly = staffPick === "@issues";
|
|
267
|
+
const unreadOnly = staffPick === "@unread";
|
|
268
|
+
const whoseStaff = staffPick && !issuesOnly ? S.data.staff.find((s) => s.handle === staffPick) : null;
|
|
269
|
+
/* The two screens partition the org rather than overlap on it. Pending work is every pull
|
|
270
|
+
request; the inbox is everything else. An inbox that also listed the PRs said the same
|
|
271
|
+
thing twice and made the badge beside it a number you could not act on. */
|
|
272
|
+
const mine = S.inbox.items
|
|
273
|
+
/* A staff member's link is their tracker: what is in their repo, whoever filed it. Matching
|
|
274
|
+
on who filed or was named put an issue the CMO filed for the CTO under both of them. */
|
|
275
|
+
.filter((i) =>
|
|
276
|
+
unreadOnly ? Boolean(i.unread) : issuesOnly ? products.has(i.repo) : !whoseStaff || i.repo === whoseStaff.brain,
|
|
277
|
+
)
|
|
278
|
+
.filter((i) => (i.kind === "pr") === !!opts.prs);
|
|
279
|
+
const isOpen = (i) => i.state === "OPEN";
|
|
280
|
+
const scoped = mine.filter(
|
|
281
|
+
S.inboxState === "closed" ? (i) => !isOpen(i) : S.inboxState === "all" ? () => true : isOpen,
|
|
282
|
+
);
|
|
283
|
+
|
|
284
|
+
let items = scoped.filter(
|
|
285
|
+
(i) => !q || (i.title + " " + i.repo + " " + i.labels.join(" ") + " #" + i.number)
|
|
286
|
+
.toLowerCase().includes(q),
|
|
287
|
+
);
|
|
288
|
+
const filter = opts.prs ? "" : S.inboxFilter;
|
|
289
|
+
if (filter === "mine") items = items.filter(onAHuman);
|
|
290
|
+
else if (filter === "decision") items = items.filter((i) => i.labels.includes("decision"));
|
|
291
|
+
/* `s=pr` was the inbox's "Open work (PRs)" scope, and Pending work is now that screen. An
|
|
292
|
+
old bookmark carrying it is ignored rather than honoured into an empty list. */
|
|
293
|
+
|
|
294
|
+
const open = mine.filter(isOpen);
|
|
295
|
+
const onYou = open.filter(onAHuman).length;
|
|
296
|
+
const shut = mine.length - open.length;
|
|
297
|
+
/* Pending work owns the pull requests now, so this is a pointer to that screen rather than
|
|
298
|
+
a count of anything on this list. Scoped the same way, or the two would not add up. */
|
|
299
|
+
const prs = S.inbox.items.filter(
|
|
300
|
+
(i) => i.kind === "pr" && isOpen(i) && belongsTo(i, whoseStaff),
|
|
301
|
+
).length;
|
|
302
|
+
const where = whoseStaff
|
|
303
|
+
? " for <b>" + esc(whoseStaff.name) + "</b>"
|
|
304
|
+
: " across " + (S.inbox.repos ?? []).length + " repos";
|
|
305
|
+
/* On the PR screen the count that matters is not "how many are open" — it is how many are
|
|
306
|
+
green and still sitting there, because that is the pile you are the bottleneck on. */
|
|
307
|
+
const failing = open.filter((i) => i.checks === "failing").length;
|
|
308
|
+
const ready = open.filter((i) => i.checks === "passing").length;
|
|
309
|
+
sub.innerHTML =
|
|
310
|
+
(S.inboxState === "closed"
|
|
311
|
+
? shut + " closed in the last 45 days" + where
|
|
312
|
+
: opts.prs
|
|
313
|
+
? open.length + " open" + where + " · <b>" + ready + " with checks passing</b>" +
|
|
314
|
+
(failing ? " · " + failing + " failing" : "") +
|
|
315
|
+
(S.inboxState === "all" ? " · " + shut + " closed or merged" : "")
|
|
316
|
+
: open.length + " open" + where + " · <b>" + onYou + " on " +
|
|
317
|
+
esc(humanLabel()) + "</b> · " + prs + " in Pending work" +
|
|
318
|
+
(S.inboxState === "all" ? " · " + shut + " closed" : "")) +
|
|
319
|
+
(S.inbox.fetchedAt ? ' <span class="meta">· checked ' + ago(S.inbox.fetchedAt) + "</span>" : "");
|
|
320
|
+
|
|
321
|
+
list.replaceChildren();
|
|
322
|
+
for (const e of S.inbox.errors ?? []) {
|
|
323
|
+
list.append(el("div", { className: "tdir err", textContent: e }));
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// Unread first, then newest first, flat. Grouping by repo buried a fresh comment under
|
|
327
|
+
// whichever project happened to sort first; the project moves onto the row instead.
|
|
328
|
+
items = items
|
|
329
|
+
.slice()
|
|
330
|
+
.sort(
|
|
331
|
+
(a, b) =>
|
|
332
|
+
Number(Boolean(b.unread)) - Number(Boolean(a.unread)) ||
|
|
333
|
+
String(b.updatedAt).localeCompare(String(a.updatedAt)),
|
|
334
|
+
);
|
|
335
|
+
if (!items.length) {
|
|
336
|
+
list.append(el("p", { className: "empty", textContent: "Nothing matches." }));
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
for (const i of items) {
|
|
341
|
+
const shutState = i.state === "MERGED" ? "merged" : i.state === "OPEN" ? "" : "closed";
|
|
342
|
+
const b = el("button", { className: "irow" + (shutState ? " shut" : "") + (i.unread ? " unread" : "") });
|
|
343
|
+
const yours = onAHuman(i);
|
|
344
|
+
const chips = i.labels
|
|
345
|
+
.slice(0, 3)
|
|
346
|
+
.map((l) => '<span class="chip ' + tone(l) + '">' + esc(l) + "</span>")
|
|
347
|
+
.join("");
|
|
348
|
+
b.innerHTML =
|
|
349
|
+
'<div class="ititle">' +
|
|
350
|
+
(yours ? '<span class="dot" title="assigned to ' + esc(humanLabel()) + '"></span>' : "") +
|
|
351
|
+
esc(i.title) + "</div>" +
|
|
352
|
+
'<div class="imeta">' +
|
|
353
|
+
'<span class="repo">' + esc(i.repo.split("/")[1]) + "</span>" +
|
|
354
|
+
(shutState
|
|
355
|
+
? '<span class="ist ' + shutState + '" title="' + esc(i.state) + '">' +
|
|
356
|
+
iconHTML(shutState === "merged" ? "merged" : "issue-closed") + "</span>"
|
|
357
|
+
: "") +
|
|
358
|
+
'<span class="num">' + (i.kind === "pr" ? "PR " : "") + "#" + i.number + "</span>" +
|
|
359
|
+
(i.checks && i.checks !== "none"
|
|
360
|
+
? '<span class="ck ' + i.checks + '">' + checkGlyph(i.checks) + "</span>" : "") +
|
|
361
|
+
/* Green checks on a branch that no longer applies is the one case where the row
|
|
362
|
+
reads as ready and is not. It has to say so here, not three clicks in. */
|
|
363
|
+
(i.mergeable === "CONFLICTING"
|
|
364
|
+
? '<span class="chip conflict" title="This branch conflicts with its base">' +
|
|
365
|
+
"conflicts</span>"
|
|
366
|
+
: "") +
|
|
367
|
+
// How much conversation is on a thread, which is most of what tells a live one from
|
|
368
|
+
// something that was filed and never answered.
|
|
369
|
+
((i.commentCount ?? i.comments.length)
|
|
370
|
+
? '<span class="cc" title="' + (i.commentCount ?? i.comments.length) + ' comments">' +
|
|
371
|
+
iconHTML("review") + (i.commentCount ?? i.comments.length) + "</span>"
|
|
372
|
+
: "") +
|
|
373
|
+
chips +
|
|
374
|
+
'<span class="when">' + ago(i.updatedAt) + "</span>" +
|
|
375
|
+
"</div>";
|
|
376
|
+
b.dataset.ref = i.repo + "#" + i.number;
|
|
377
|
+
b.setAttribute("aria-current", String(S.inboxOpen?.repo === i.repo && S.inboxOpen?.number === i.number));
|
|
378
|
+
b.onclick = () => {
|
|
379
|
+
markCurrent(list, b);
|
|
380
|
+
S.inboxOpen = { repo: i.repo, number: i.number, kind: i.kind };
|
|
381
|
+
writeHash(false);
|
|
382
|
+
openThread(S.inboxOpen);
|
|
383
|
+
};
|
|
384
|
+
list.append(b);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/* Everything is already loaded, so opening a thread is a render, not a request. */
|
|
389
|
+
function openThread(ref) {
|
|
390
|
+
const item = (S.inbox?.items ?? []).find(
|
|
391
|
+
(i) => i.repo === ref.repo && i.number === ref.number,
|
|
392
|
+
);
|
|
393
|
+
if (!item) {
|
|
394
|
+
viewer.replaceChildren(
|
|
395
|
+
el("p", { className: "empty", textContent: "That one is no longer open. Refresh." }),
|
|
396
|
+
);
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
const row = list.querySelector('[data-ref="' + item.repo + "#" + item.number + '"]');
|
|
400
|
+
if (row) markCurrent(list, row);
|
|
401
|
+
// Opening it is reading it: cleared here at once, and on GitHub in the background.
|
|
402
|
+
if (item.unread) {
|
|
403
|
+
const thread = item.unread.thread;
|
|
404
|
+
item.unread = null;
|
|
405
|
+
row?.classList.remove("unread");
|
|
406
|
+
stampCounts();
|
|
407
|
+
post({ thread, ref: item.repo + "#" + item.number }, "/api/notifications/read").catch(() => {});
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/* The list carries no bodies or timelines (carrying them cost most of an hour's GitHub
|
|
411
|
+
allowance per load), so a thread is read when it is opened, and kept until GitHub says
|
|
412
|
+
it has changed. Reopening one costs nothing. */
|
|
413
|
+
if (item.partial) {
|
|
414
|
+
const key = item.repo + "#" + item.number;
|
|
415
|
+
const kept = THREADS.get(key);
|
|
416
|
+
const keep = { role: item.role, unread: item.unread };
|
|
417
|
+
if (kept && kept.updatedAt === item.updatedAt) {
|
|
418
|
+
Object.assign(item, kept, keep, { partial: false });
|
|
419
|
+
} else {
|
|
420
|
+
viewer.dataset.want = key;
|
|
421
|
+
viewer.replaceChildren(...skeleton("head", 1), ...skeleton("line", 8));
|
|
422
|
+
getThread(item.repo, item.number, item.kind)
|
|
423
|
+
.then((fresh) => {
|
|
424
|
+
if (!fresh || fresh.error) throw new Error(fresh?.error ?? "could not read it");
|
|
425
|
+
THREADS.set(key, fresh);
|
|
426
|
+
Object.assign(item, fresh, keep, { partial: false });
|
|
427
|
+
})
|
|
428
|
+
.catch((e) => {
|
|
429
|
+
item.partial = false;
|
|
430
|
+
item.loadError = String(e.message || e);
|
|
431
|
+
})
|
|
432
|
+
.finally(() => {
|
|
433
|
+
// Somebody may have opened another thread while this one was loading.
|
|
434
|
+
if (viewer.dataset.want === key) openThread(ref);
|
|
435
|
+
});
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
const head = el("div", { className: "thead" });
|
|
441
|
+
head.innerHTML =
|
|
442
|
+
'<div class="meta">' + esc(item.repo) + " · " + (item.kind === "pr" ? "PR " : "") + "#" + item.number +
|
|
443
|
+
' · <span class="' + (item.state === "OPEN" ? "ok" : "") + '">' + esc(item.state) + "</span>" +
|
|
444
|
+
" · " + esc(item.author) + " · " + ago(item.updatedAt) +
|
|
445
|
+
// The labels sit on this line, after the time, rather than taking a line of their own.
|
|
446
|
+
(item.labels.length
|
|
447
|
+
? '<span class="tmetalabels">' +
|
|
448
|
+
item.labels.map((l) => '<span class="chip ' + tone(l) + '">' + esc(l) + "</span>").join("") +
|
|
449
|
+
"</span>"
|
|
450
|
+
: "") +
|
|
451
|
+
"</div>" +
|
|
452
|
+
"<h3>" + esc(item.title) + "</h3>" +
|
|
453
|
+
(item.mergeable === "CONFLICTING"
|
|
454
|
+
? '<p class="tconflict">This branch conflicts with its base and cannot be merged ' +
|
|
455
|
+
"until someone rebases or merges the base into it.</p>"
|
|
456
|
+
: "") +
|
|
457
|
+
"";
|
|
458
|
+
head.append(threadActions(item));
|
|
459
|
+
delete viewer.dataset.wait;
|
|
460
|
+
viewer.replaceChildren(head);
|
|
461
|
+
|
|
462
|
+
/* A pull request is a conversation, a set of commits and a diff. The inbox carries the
|
|
463
|
+
first; the other two are a click away rather than in every refresh of every repo.
|
|
464
|
+
An issue has only the conversation, so it stays flat in the viewer rather than paying
|
|
465
|
+
for a wrapper that would only ever hold one thing. */
|
|
466
|
+
const pane = item.kind === "pr" ? el("div") : viewer;
|
|
467
|
+
if (item.kind === "pr") viewer.append(prTabs(item, pane), pane);
|
|
468
|
+
if (item.loadError) {
|
|
469
|
+
pane.append(el("p", { className: "err", textContent: "Couldn't load the conversation: " + item.loadError }));
|
|
470
|
+
delete item.loadError;
|
|
471
|
+
item.partial = true; // so opening it again tries again
|
|
472
|
+
}
|
|
473
|
+
conversation(pane, item);
|
|
474
|
+
viewer.scrollTop = 0;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/** Appends; whoever is swapping panes owns clearing them. */
|
|
478
|
+
function conversation(pane, item) {
|
|
479
|
+
/* Newest first, opening post last. GitHub's own order puts the answer you came for at the
|
|
480
|
+
bottom of a year of bookkeeping, and the thing you do most on this screen is read what
|
|
481
|
+
just happened. The title and the actions are in the header, so nothing you need is
|
|
482
|
+
further down than the first screenful. */
|
|
483
|
+
const from = pane.children.length;
|
|
484
|
+
for (const node of timeline(item, openThread)) pane.append(node);
|
|
485
|
+
pane.append(
|
|
486
|
+
comment({
|
|
487
|
+
author: item.author, when: item.createdAt, body: item.body, first: true,
|
|
488
|
+
repo: item.repo, reactions: item.reactions,
|
|
489
|
+
}),
|
|
490
|
+
);
|
|
491
|
+
/* Whatever ends up first drops its own top rule. The header already draws a line under
|
|
492
|
+
itself, and with the thread reversed the first thing under it is any of three shapes. */
|
|
493
|
+
pane.children[from]?.classList?.add("lead");
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Conversation, commits, files — for pull requests only.
|
|
498
|
+
*
|
|
499
|
+
* The detail is fetched once per thread and kept, so switching back and forth is free. A
|
|
500
|
+
* failure is shown in the pane rather than swallowed: "no diff" and "GitHub would not give
|
|
501
|
+
* me the diff" are different answers.
|
|
502
|
+
*/
|
|
503
|
+
function prTabs(item, pane) {
|
|
504
|
+
const bar = el("div", { className: "tabs" });
|
|
505
|
+
const key = item.repo + "#" + item.number;
|
|
506
|
+
let detail = PRS.get(key) ?? null;
|
|
507
|
+
|
|
508
|
+
const tabs = [
|
|
509
|
+
["conversation", "Conversation", () => { pane.replaceChildren(); conversation(pane, item); }],
|
|
510
|
+
["commits", "Commits", () => paintCommits(pane, detail)],
|
|
511
|
+
["files", "Files", () => paintFiles(pane, detail, item)],
|
|
512
|
+
];
|
|
513
|
+
|
|
514
|
+
const pick = async (id) => {
|
|
515
|
+
for (const b of bar.children) b.setAttribute("aria-current", String(b.dataset.tab === id));
|
|
516
|
+
if (id === "conversation") {
|
|
517
|
+
pane.replaceChildren();
|
|
518
|
+
conversation(pane, item);
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
521
|
+
if (!detail) {
|
|
522
|
+
pane.replaceChildren(el("p", { className: "empty", textContent: "Asking GitHub…" }));
|
|
523
|
+
try {
|
|
524
|
+
detail = await getPr(item.repo, item.number);
|
|
525
|
+
PRS.set(key, detail);
|
|
526
|
+
} catch (e) {
|
|
527
|
+
pane.replaceChildren(el("p", { className: "empty err", textContent: e.message }));
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
if (detail.error) {
|
|
532
|
+
pane.replaceChildren(el("p", { className: "empty err", textContent: detail.error }));
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
tabs.find((t) => t[0] === id)[2]();
|
|
536
|
+
};
|
|
537
|
+
|
|
538
|
+
for (const [id, label] of tabs) {
|
|
539
|
+
const b = el("button", { className: "tab", textContent: label });
|
|
540
|
+
b.dataset.tab = id;
|
|
541
|
+
b.setAttribute("aria-current", String(id === "conversation"));
|
|
542
|
+
b.onclick = () => pick(id);
|
|
543
|
+
bar.append(b);
|
|
544
|
+
}
|
|
545
|
+
return bar;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
function paintCommits(pane, d) {
|
|
549
|
+
pane.replaceChildren(
|
|
550
|
+
el("p", { className: "meta", style: "margin:14px 0 10px",
|
|
551
|
+
textContent: d.commits.length + " commits · " + d.head + " → " + d.base }),
|
|
552
|
+
);
|
|
553
|
+
if (!d.commits.length) {
|
|
554
|
+
pane.append(el("p", { className: "empty", textContent: "No commits on this branch yet." }));
|
|
555
|
+
return;
|
|
556
|
+
}
|
|
557
|
+
for (const c of d.commits) {
|
|
558
|
+
const row = el("div", { className: "prcommit" });
|
|
559
|
+
row.append(
|
|
560
|
+
el("a", { className: "sha", href: c.url, target: "_blank", rel: "noopener", textContent: c.sha }),
|
|
561
|
+
el("span", { className: "subj", textContent: c.subject }),
|
|
562
|
+
el("span", { className: "meta", textContent: c.author + (c.date ? " · " + ago(c.date) : "") }),
|
|
563
|
+
);
|
|
564
|
+
pane.append(row);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
function paintFiles(pane, d, item) {
|
|
569
|
+
pane.replaceChildren(
|
|
570
|
+
el("p", { className: "meta", style: "margin:14px 0 10px",
|
|
571
|
+
textContent: d.changedFiles + " files · +" + d.additions + " −" + d.deletions }),
|
|
572
|
+
);
|
|
573
|
+
if (!d.files.length) {
|
|
574
|
+
pane.append(el("p", { className: "empty", textContent: "This pull request changes nothing." }));
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
for (const f of d.files) {
|
|
578
|
+
/* renderDiff reads a git diff, so each file's patch is given the header the API leaves
|
|
579
|
+
off. A file with no patch is binary or too big for GitHub to send one — say which. */
|
|
580
|
+
if (!f.patch) {
|
|
581
|
+
const wrap = el("div", { className: "dblock" });
|
|
582
|
+
const h = el("div", { className: "dfile" });
|
|
583
|
+
h.innerHTML = "<b>" + esc(f.path) + "</b>" +
|
|
584
|
+
'<span class="p">+' + f.additions + '</span><span class="m">−' + f.deletions + "</span>";
|
|
585
|
+
wrap.append(h, el("p", { className: "dempty",
|
|
586
|
+
textContent: "No patch: this file is binary or too large for the API to send one." }));
|
|
587
|
+
pane.append(wrap);
|
|
588
|
+
continue;
|
|
589
|
+
}
|
|
590
|
+
const blocks = renderDiff("diff --git a/" + f.path + " b/" + f.path + "\n" + f.patch);
|
|
591
|
+
/* The ask goes in the file's own heading, because "this file is wrong" is the thing you
|
|
592
|
+
want to say while looking at one file, and the alternative is describing in prose which
|
|
593
|
+
of thirty files you meant. The hunk goes with it, so the agent gets the part you were
|
|
594
|
+
reading rather than the whole diff and a guess. */
|
|
595
|
+
const head = blocks[0]?.children?.[0];
|
|
596
|
+
if (item && head && String(head.className ?? "").includes("dfile")) {
|
|
597
|
+
head.append(replyAboutFile(item, f));
|
|
598
|
+
}
|
|
599
|
+
for (const block of blocks) pane.append(block);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
/**
|
|
604
|
+
* The same reply box, opened about one file.
|
|
605
|
+
*
|
|
606
|
+
* "This bit is wrong" is what you want to say while looking at one file, and the alternative
|
|
607
|
+
* is describing in prose which of thirty files you meant. It is not a second kind of thing:
|
|
608
|
+
* it opens the composer the Reply button opens, with the file remembered, so the hunk rides
|
|
609
|
+
* along to whoever you name in it.
|
|
610
|
+
*/
|
|
611
|
+
function replyAboutFile(item, f) {
|
|
612
|
+
const b = el("button", {
|
|
613
|
+
className: "ghbtn askfile",
|
|
614
|
+
textContent: "Reply",
|
|
615
|
+
title: "Reply about " + f.path,
|
|
616
|
+
});
|
|
617
|
+
b.onclick = async () => {
|
|
618
|
+
b.disabled = true;
|
|
619
|
+
try {
|
|
620
|
+
// Same reason as the header's Reply: the wait is after the box closes, not during it.
|
|
621
|
+
const r = await openReply(item, f, () => {
|
|
622
|
+
b.textContent = "Replying…";
|
|
623
|
+
});
|
|
624
|
+
b.textContent = r ? (r.warning ? "sent, with a warning" : "sent") : "Reply";
|
|
625
|
+
} catch (e) {
|
|
626
|
+
b.textContent = e.message;
|
|
627
|
+
}
|
|
628
|
+
b.disabled = false;
|
|
629
|
+
};
|
|
630
|
+
return b;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
* Reply, close, merge — at the top of the thread, next to the title.
|
|
635
|
+
*
|
|
636
|
+
* They used to sit under the last comment, which meant scrolling a long thread to the end to
|
|
637
|
+
* answer it, and then the thread put the newest thing there too. The actions are about the
|
|
638
|
+
* thread rather than about its last message, so they belong where the thread starts. Writing
|
|
639
|
+
* happens in a dialog for the same reason: a box you can only reach by scrolling is a box you
|
|
640
|
+
* stop using.
|
|
641
|
+
*
|
|
642
|
+
* All of it goes out as the human, through their own `gh`, so it is indistinguishable from
|
|
643
|
+
* doing it on the site.
|
|
644
|
+
*/
|
|
645
|
+
function threadActions(item) {
|
|
646
|
+
const key = item.repo + "#" + item.number;
|
|
647
|
+
const status = el("span", { className: "meta" });
|
|
648
|
+
const buttons = [];
|
|
649
|
+
|
|
650
|
+
const busy = (on, msg) => {
|
|
651
|
+
for (const b of buttons) b.disabled = on;
|
|
652
|
+
status.textContent = msg ?? "";
|
|
653
|
+
status.className = "meta";
|
|
654
|
+
};
|
|
655
|
+
// busy(false) clears the status line, so it goes first: the other way round wiped the
|
|
656
|
+
// error as it was written, and a refused merge looked like nothing happening at all.
|
|
657
|
+
const failed = (e) => {
|
|
658
|
+
busy(false);
|
|
659
|
+
status.textContent = e.message;
|
|
660
|
+
status.className = "meta err";
|
|
661
|
+
};
|
|
662
|
+
|
|
663
|
+
/* A reply you started and did not send survives closing the dialog, and comes back the
|
|
664
|
+
next time you open it rather than being lost to a stray Escape. `compose` is kept for
|
|
665
|
+
the close button below, which also takes a parting comment. */
|
|
666
|
+
const compose = ({ title, hint, confirm, allowEmpty }) =>
|
|
667
|
+
askText({
|
|
668
|
+
title,
|
|
669
|
+
hint,
|
|
670
|
+
confirm,
|
|
671
|
+
allowEmpty,
|
|
672
|
+
value: DRAFTS.get(key) ?? "",
|
|
673
|
+
placeholder:
|
|
674
|
+
"Reply as " + (humansOf().length === 1 ? humansOf()[0].github : "yourself") + "…",
|
|
675
|
+
decorate: (ta) => {
|
|
676
|
+
ta.oninput = () => {
|
|
677
|
+
if (ta.value) DRAFTS.set(key, ta.value);
|
|
678
|
+
else DRAFTS.delete(key);
|
|
679
|
+
};
|
|
680
|
+
return attachBox(ta, () => item.repo).node;
|
|
681
|
+
},
|
|
682
|
+
});
|
|
683
|
+
|
|
684
|
+
/* One button, because there was no way to tell the two apart. Reply reaches whoever you
|
|
685
|
+
named in it; see `openReply`. */
|
|
686
|
+
const reply = el("button", { className: "ghbtn primary", textContent: "Reply" });
|
|
687
|
+
|
|
688
|
+
/* Posting a comment is a round trip to GitHub through `gh`, and on a cold connection that
|
|
689
|
+
is seconds of a button that still says "Reply" and still takes clicks. Saying nothing
|
|
690
|
+
reads as a page that ignored you, which is how the same comment gets sent twice. */
|
|
691
|
+
const sending = (on) => {
|
|
692
|
+
busy(on, on ? "sending…" : "");
|
|
693
|
+
reply.textContent = on ? "Replying…" : "Reply";
|
|
694
|
+
};
|
|
695
|
+
|
|
696
|
+
reply.onclick = async () => {
|
|
697
|
+
let r;
|
|
698
|
+
try {
|
|
699
|
+
r = await openReply(item, null, () => sending(true));
|
|
700
|
+
} catch (e) {
|
|
701
|
+
sending(false);
|
|
702
|
+
failed(e);
|
|
703
|
+
return;
|
|
704
|
+
}
|
|
705
|
+
// Closed the box without sending: nothing ever started, so there is nothing to put back.
|
|
706
|
+
if (!r) {
|
|
707
|
+
sending(false);
|
|
708
|
+
return;
|
|
709
|
+
}
|
|
710
|
+
/* Repaint only when something was said on this thread, which is always true here: `ask`
|
|
711
|
+
posts the comment too. A warning means the tracker issue went up and the comment did
|
|
712
|
+
not, and then the status line is the only thing that says so. */
|
|
713
|
+
if (r.warning) {
|
|
714
|
+
sending(false);
|
|
715
|
+
status.className = "meta err";
|
|
716
|
+
status.textContent = r.warning;
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
/* Held across the reload as well as the post. The reply is not on screen until the
|
|
720
|
+
thread repaints, and a button that said "Reply" again before then would be claiming
|
|
721
|
+
it was done over a thread that still did not show it. */
|
|
722
|
+
await reloadThread(item);
|
|
723
|
+
sending(false);
|
|
724
|
+
};
|
|
725
|
+
buttons.push(reply);
|
|
726
|
+
|
|
727
|
+
const closeBtn = el("button", {
|
|
728
|
+
className: "ghbtn",
|
|
729
|
+
textContent: item.state === "OPEN" ? "Close" : "Reopen",
|
|
730
|
+
});
|
|
731
|
+
closeBtn.onclick = async () => {
|
|
732
|
+
const closing = item.state === "OPEN";
|
|
733
|
+
let body;
|
|
734
|
+
if (closing) {
|
|
735
|
+
// Closing is the one thing here that is awkward to undo from a phone later, so it asks
|
|
736
|
+
// — and since it is asking anyway, it takes a parting comment.
|
|
737
|
+
body = await compose({
|
|
738
|
+
title: "Close " + item.repo + " #" + item.number + "?",
|
|
739
|
+
hint: "Anything you write here is posted as a comment first. Leave it empty to just close.",
|
|
740
|
+
confirm: "Close it",
|
|
741
|
+
allowEmpty: true,
|
|
742
|
+
});
|
|
743
|
+
if (body === null) return;
|
|
744
|
+
}
|
|
745
|
+
busy(true, closing ? "closing…" : "reopening…");
|
|
746
|
+
try {
|
|
747
|
+
await post({
|
|
748
|
+
action: closing ? "close" : "reopen",
|
|
749
|
+
repo: item.repo,
|
|
750
|
+
number: item.number,
|
|
751
|
+
body: body || undefined,
|
|
752
|
+
});
|
|
753
|
+
DRAFTS.delete(key);
|
|
754
|
+
/* What changed is known, so it is changed here rather than re-reading every repo,
|
|
755
|
+
which redrew the whole inbox for one issue. The next refresh confirms it. */
|
|
756
|
+
const me = humansOf()[0]?.github ?? "you";
|
|
757
|
+
const now = new Date().toISOString();
|
|
758
|
+
item.events = [
|
|
759
|
+
...(item.events ?? []),
|
|
760
|
+
...(body ? [{ type: "comment", actor: me, createdAt: now, body }] : []),
|
|
761
|
+
{ type: closing ? "closed" : "reopened", actor: me, createdAt: now },
|
|
762
|
+
];
|
|
763
|
+
item.state = closing ? "CLOSED" : "OPEN";
|
|
764
|
+
item.updatedAt = now;
|
|
765
|
+
stampCounts();
|
|
766
|
+
paint();
|
|
767
|
+
openThread({ repo: item.repo, number: item.number, kind: item.kind });
|
|
768
|
+
} catch (e) { failed(e); }
|
|
769
|
+
};
|
|
770
|
+
buttons.push(closeBtn);
|
|
771
|
+
|
|
772
|
+
const row = el("div", { className: "row tacts" }, buttons);
|
|
773
|
+
|
|
774
|
+
/* Merging cannot be undone with another click, so it asks first and names what it is about
|
|
775
|
+
to merge. It does not ask *how*: squash, merge commit or rebase is a question about git
|
|
776
|
+
rather than about this pull request, and the repository has already answered it in its
|
|
777
|
+
own settings. The server reads it from there. */
|
|
778
|
+
if (item.kind === "pr" && item.state === "OPEN") {
|
|
779
|
+
const merge = el("button", { className: "ghbtn", textContent: "Merge" });
|
|
780
|
+
/* A conflicted branch cannot be merged by anyone, so the button says why instead of
|
|
781
|
+
spending a round trip to come back with GitHub's version of the same sentence. */
|
|
782
|
+
if (item.mergeable === "CONFLICTING") {
|
|
783
|
+
merge.disabled = true;
|
|
784
|
+
merge.title = "This branch conflicts with its base";
|
|
785
|
+
}
|
|
786
|
+
merge.onclick = async () => {
|
|
787
|
+
const yes = await askYes({
|
|
788
|
+
title: "Merge " + item.repo + " #" + item.number + " into its base branch?",
|
|
789
|
+
confirm: "Merge",
|
|
790
|
+
});
|
|
791
|
+
if (!yes) return;
|
|
792
|
+
busy(true, "merging…");
|
|
793
|
+
try {
|
|
794
|
+
await post({ action: "merge", repo: item.repo, number: item.number });
|
|
795
|
+
// As with closing: the change is known, so it is made here rather than re-reading every repo.
|
|
796
|
+
item.state = "MERGED";
|
|
797
|
+
item.updatedAt = new Date().toISOString();
|
|
798
|
+
stampCounts();
|
|
799
|
+
paint();
|
|
800
|
+
openThread({ repo: item.repo, number: item.number, kind: item.kind });
|
|
801
|
+
} catch (e) { failed(e); }
|
|
802
|
+
};
|
|
803
|
+
/* The branch rules want an approving review before a merge. Approve is your review,
|
|
804
|
+
given on purpose; Merge never gives it for you, so it waits until there is one. */
|
|
805
|
+
if (item.reviewDecision === "REVIEW_REQUIRED" && item.mergeable !== "CONFLICTING") {
|
|
806
|
+
merge.disabled = true;
|
|
807
|
+
merge.title = "Approve it first: the branch rules need an approving review";
|
|
808
|
+
const approve = el("button", { className: "ghbtn primary", textContent: "Approve" });
|
|
809
|
+
approve.onclick = async () => {
|
|
810
|
+
busy(true, "approving…");
|
|
811
|
+
try {
|
|
812
|
+
await post({ action: "approve", repo: item.repo, number: item.number });
|
|
813
|
+
item.reviewDecision = "APPROVED";
|
|
814
|
+
openThread({ repo: item.repo, number: item.number, kind: item.kind });
|
|
815
|
+
} catch (e) { failed(e); }
|
|
816
|
+
};
|
|
817
|
+
buttons.push(approve);
|
|
818
|
+
row.append(approve);
|
|
819
|
+
}
|
|
820
|
+
buttons.push(merge);
|
|
821
|
+
row.append(merge);
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
row.append(status);
|
|
825
|
+
// Last, and pushed to the far end: it is the way out of this screen rather than one of the
|
|
826
|
+
// things you do on it. Same shape as the rest, so the row reads as one set of controls.
|
|
827
|
+
row.append(
|
|
828
|
+
el("a", {
|
|
829
|
+
className: "ghbtn out",
|
|
830
|
+
href: item.url,
|
|
831
|
+
target: "_blank",
|
|
832
|
+
rel: "noopener",
|
|
833
|
+
textContent: "Open in GitHub",
|
|
834
|
+
}),
|
|
835
|
+
);
|
|
836
|
+
return row;
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
async function reloadThread(item) {
|
|
840
|
+
// Re-read just this one, so a reply appears without paying for the whole org again.
|
|
841
|
+
try {
|
|
842
|
+
const fresh = await getThread(item.repo, item.number, item.kind);
|
|
843
|
+
if (fresh && !fresh.error) {
|
|
844
|
+
const at = S.inbox.items.findIndex(
|
|
845
|
+
(i) => i.repo === item.repo && i.number === item.number,
|
|
846
|
+
);
|
|
847
|
+
if (at >= 0) {
|
|
848
|
+
const old = S.inbox.items[at];
|
|
849
|
+
THREADS.set(item.repo + "#" + item.number, fresh);
|
|
850
|
+
// A single thread does not know which part of the org it is in, or whether it is unread.
|
|
851
|
+
S.inbox.items[at] = { ...old, ...fresh, role: old.role, unread: old.unread, partial: false };
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
} catch {
|
|
855
|
+
/* the comment posted; a stale pane is not worth an error */
|
|
856
|
+
}
|
|
857
|
+
paint();
|
|
858
|
+
// The thread is newest first, so what you just wrote is the first thing on it.
|
|
859
|
+
openThread({ repo: item.repo, number: item.number, kind: item.kind });
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
/* -------------------------- one composer, one box ------------------------- */
|
|
864
|
+
|
|
865
|
+
/**
|
|
866
|
+
* Reply to a thread, and reach whoever you named while doing it.
|
|
867
|
+
*
|
|
868
|
+
* There used to be two buttons on a thread, Reply and "Ask a staff member", and nothing on the
|
|
869
|
+
* page said which one you wanted. They did almost the same thing: both put your words on the
|
|
870
|
+
* thread, and both could open a request on somebody's tracker. The only real difference was
|
|
871
|
+
* that one of them made you pick a name from a dropdown, which is a worse way of saying who you
|
|
872
|
+
* mean than typing their name in the sentence.
|
|
873
|
+
*
|
|
874
|
+
* So there is one box. Type `@cto` in it, and if a comment here would not reach them the offer
|
|
875
|
+
* to open it on their tracker appears underneath, ticked. One press does both.
|
|
876
|
+
*
|
|
877
|
+
* @param anchor the file this is about, when it was opened from a diff. Its hunk rides along.
|
|
878
|
+
* @returns the result of the write, or null if nothing was written.
|
|
879
|
+
*/
|
|
880
|
+
/**
|
|
881
|
+
* @param onSend Called once, the moment the box is submitted and the writing starts.
|
|
882
|
+
*
|
|
883
|
+
* The dialog and the send are one `await` to whoever called this, so a caller cannot tell the
|
|
884
|
+
* two apart by itself — and the two want opposite things from a button. While the box is open
|
|
885
|
+
* you are still typing and the button has to stay as it was; once it closes there is a request
|
|
886
|
+
* in flight against GitHub that can take seconds, and that is what needs saying.
|
|
887
|
+
*/
|
|
888
|
+
/**
|
|
889
|
+
* Who a reply is for, by default: the staff member whose tracker the issue is on, or whose App
|
|
890
|
+
* opened it. They are only woken by an @mention, so a reply without one reached nobody.
|
|
891
|
+
*/
|
|
892
|
+
export function addressee(item) {
|
|
893
|
+
const staff = S.data?.staff ?? [];
|
|
894
|
+
const s =
|
|
895
|
+
staff.find((x) => x.brain === item.repo) ??
|
|
896
|
+
staff.find((x) => (x.soloBots ?? []).includes(item.author));
|
|
897
|
+
if (!s) return "";
|
|
898
|
+
return (s.mention || "@" + s.handle) + " ";
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
async function openReply(item, anchor, onSend) {
|
|
902
|
+
const key = item.repo + "#" + item.number + (anchor ? " · " + anchor.path : "");
|
|
903
|
+
let deaf = null;
|
|
904
|
+
|
|
905
|
+
const body = await askText({
|
|
906
|
+
title: "Reply to " + item.repo + " #" + item.number,
|
|
907
|
+
hint: anchor ? anchor.path : item.title,
|
|
908
|
+
confirm: "Comment",
|
|
909
|
+
value: DRAFTS.get(key) ?? addressee(item),
|
|
910
|
+
/* It goes out through whoever's `gh` is signed in here, which is only knowably one person
|
|
911
|
+
when the org has one. With two it would be a guess, and a wrong name on a reply box is
|
|
912
|
+
worse than no name. */
|
|
913
|
+
placeholder: "Reply as " + (humansOf().length === 1 ? humansOf()[0].github : "yourself") + "…",
|
|
914
|
+
decorate: (ta) => {
|
|
915
|
+
ta.oninput = () => {
|
|
916
|
+
if (ta.value) DRAFTS.set(key, ta.value);
|
|
917
|
+
else DRAFTS.delete(key);
|
|
918
|
+
};
|
|
919
|
+
deaf = deafNote(ta, item, anchor);
|
|
920
|
+
// Typing starts after the @mention, not in front of it.
|
|
921
|
+
setTimeout(() => {
|
|
922
|
+
ta.selectionStart = ta.selectionEnd = ta.value.length;
|
|
923
|
+
}, 0);
|
|
924
|
+
return el("div", {}, [attachBox(ta, () => item.repo).node, deaf.node]);
|
|
925
|
+
},
|
|
926
|
+
});
|
|
927
|
+
if (!body) return null;
|
|
928
|
+
onSend?.();
|
|
929
|
+
|
|
930
|
+
/* One press, both writes. `ask` posts the comment itself when told to, so these are not two
|
|
931
|
+
requests racing: the tracker issue goes up first because it is the half that actually
|
|
932
|
+
reaches anybody, and the comment on the thread carries a link to it.
|
|
933
|
+
|
|
934
|
+
Who to reach comes off the text that was submitted rather than off what was in the box
|
|
935
|
+
while it was being typed, so a handle you typed and then deleted is not asked. */
|
|
936
|
+
const reaching = listener(item.repo) ? [] : mentioned(body);
|
|
937
|
+
const to = deaf?.declined() ? null : reaching[0];
|
|
938
|
+
if (!to) {
|
|
939
|
+
DRAFTS.delete(key);
|
|
940
|
+
return post({ action: "comment", repo: item.repo, number: item.number, body });
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
const detail = PRS.get(item.repo + "#" + item.number);
|
|
944
|
+
const r = await post({
|
|
945
|
+
action: "ask",
|
|
946
|
+
repo: to.brain,
|
|
947
|
+
ask: {
|
|
948
|
+
staff: {
|
|
949
|
+
handle: to.handle,
|
|
950
|
+
name: to.name,
|
|
951
|
+
mention: to.mention ?? "@" + to.handle,
|
|
952
|
+
brain: to.brain,
|
|
953
|
+
},
|
|
954
|
+
pr: {
|
|
955
|
+
repo: item.repo,
|
|
956
|
+
number: item.number,
|
|
957
|
+
title: item.title ?? "",
|
|
958
|
+
url: item.url ?? "",
|
|
959
|
+
kind: item.kind,
|
|
960
|
+
// The branch names only. The rest of the detail is commits and every file's patch, and
|
|
961
|
+
// none of it belongs in a request that is about a sentence.
|
|
962
|
+
head: detail?.head,
|
|
963
|
+
base: detail?.base,
|
|
964
|
+
},
|
|
965
|
+
body,
|
|
966
|
+
...(anchor ? { anchor: { path: anchor.path, patch: anchor.patch } } : {}),
|
|
967
|
+
},
|
|
968
|
+
alsoOnPr: true,
|
|
969
|
+
});
|
|
970
|
+
DRAFTS.delete(key);
|
|
971
|
+
return r;
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
/**
|
|
975
|
+
* "You typed a name nobody here answers to." And then an offer to fix it.
|
|
976
|
+
*
|
|
977
|
+
* The `@` list offers every staff member in every box, and posting one on a product repo looks
|
|
978
|
+
* exactly like posting one on a tracker: it goes up, it renders as a chip, and nothing happens.
|
|
979
|
+
*
|
|
980
|
+
* Saying so is not enough. An earlier version told you to post the comment and then go and
|
|
981
|
+
* press the other button, which is the round trip this whole lane exists to remove, with a
|
|
982
|
+
* lecture in front of it. If the box knows who you meant and knows a comment here will not
|
|
983
|
+
* reach them, it should offer to reach them.
|
|
984
|
+
*/
|
|
985
|
+
function deafNote(ta, on, anchor) {
|
|
986
|
+
const line = el("span", {});
|
|
987
|
+
const box = el("input", { type: "checkbox", checked: true, id: "reply-alsoask" });
|
|
988
|
+
const offer = el("label", { className: "meta", htmlFor: "reply-alsoask" }, [
|
|
989
|
+
box,
|
|
990
|
+
el("span", {
|
|
991
|
+
textContent:
|
|
992
|
+
" open it on their tracker too, with a link to this" +
|
|
993
|
+
(anchor ? " and the diff for " + anchor.path : ""),
|
|
994
|
+
}),
|
|
995
|
+
]);
|
|
996
|
+
const note = el("div", { className: "meta err", style: "margin:8px 0 0" }, [line, offer]);
|
|
997
|
+
|
|
998
|
+
const check = () => {
|
|
999
|
+
const deaf = listener(on.repo) ? [] : mentioned(ta.value);
|
|
1000
|
+
note.hidden = !deaf.length;
|
|
1001
|
+
line.textContent = deaf.length
|
|
1002
|
+
? deaf.map((s) => s.mention ?? "@" + s.handle).join(" and ") +
|
|
1003
|
+
" is not woken by a comment on " + on.repo + ": it is not their tracker. "
|
|
1004
|
+
: "";
|
|
1005
|
+
};
|
|
1006
|
+
ta.addEventListener("input", check);
|
|
1007
|
+
check();
|
|
1008
|
+
/* Only whether the offer was declined. Who, and whether there is anybody at all, is worked
|
|
1009
|
+
out from the text that was actually submitted. */
|
|
1010
|
+
return { node: note, declined: () => !box.checked };
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
/* ------------------------------- the thread ------------------------------ */
|
|
1014
|
+
|
|
1015
|
+
/**
|
|
1016
|
+
* A thread's history, newest first: comments and reviews as cards, references as lines, and a
|
|
1017
|
+
* run of bookkeeping folded behind one disclosure.
|
|
1018
|
+
*
|
|
1019
|
+
* A run of exactly one stays inline. Hiding "added the build label" behind a click costs
|
|
1020
|
+
* more attention than reading it does.
|
|
1021
|
+
*
|
|
1022
|
+
* Reversed rather than rendered in GitHub's order, because the question this screen answers is
|
|
1023
|
+
* "what just happened", and the answer was at the bottom of everything that happened before it.
|
|
1024
|
+
*/
|
|
1025
|
+
function timeline(item, openThread) {
|
|
1026
|
+
const out = [];
|
|
1027
|
+
let quiet = [];
|
|
1028
|
+
|
|
1029
|
+
const flush = () => {
|
|
1030
|
+
if (!quiet.length) return;
|
|
1031
|
+
if (quiet.length === 1) out.push(eventLine(quiet[0], item, openThread));
|
|
1032
|
+
else out.push(folded(quiet, item, openThread));
|
|
1033
|
+
quiet = [];
|
|
1034
|
+
};
|
|
1035
|
+
|
|
1036
|
+
for (const e of [...(item.events ?? [])].reverse()) {
|
|
1037
|
+
if (QUIET.has(e.type)) { quiet.push(e); continue; }
|
|
1038
|
+
flush();
|
|
1039
|
+
if (e.type === "comment") {
|
|
1040
|
+
out.push(
|
|
1041
|
+
comment({
|
|
1042
|
+
author: e.actor, when: e.createdAt, body: e.body, repo: item.repo,
|
|
1043
|
+
reactions: e.reactions,
|
|
1044
|
+
}),
|
|
1045
|
+
);
|
|
1046
|
+
} else if (e.type === "review" && (e.body ?? "").trim()) {
|
|
1047
|
+
out.push(
|
|
1048
|
+
comment({
|
|
1049
|
+
author: e.actor, when: e.createdAt, body: e.body, repo: item.repo,
|
|
1050
|
+
badge: reviewWord(e.state),
|
|
1051
|
+
}),
|
|
1052
|
+
);
|
|
1053
|
+
} else {
|
|
1054
|
+
out.push(eventLine(e, item, openThread));
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
flush();
|
|
1058
|
+
return out;
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
function folded(events, item, openThread) {
|
|
1062
|
+
const box = el("div");
|
|
1063
|
+
const btn = el("button", { className: "tevmore" });
|
|
1064
|
+
btn.setAttribute("aria-expanded", "false");
|
|
1065
|
+
btn.append(
|
|
1066
|
+
icon("chevron", "caret"),
|
|
1067
|
+
el("span", { textContent: events.length + " more events" }),
|
|
1068
|
+
);
|
|
1069
|
+
const body = el("div", { className: "tevquiet" }, events.map((e) => eventLine(e, item, openThread)));
|
|
1070
|
+
body.hidden = true;
|
|
1071
|
+
btn.onclick = () => {
|
|
1072
|
+
body.hidden = !body.hidden;
|
|
1073
|
+
btn.setAttribute("aria-expanded", String(!body.hidden));
|
|
1074
|
+
};
|
|
1075
|
+
box.append(btn, body);
|
|
1076
|
+
return box;
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
/* One icon per kind of thing that can happen to a thread. Labels and people repeat on
|
|
1080
|
+
purpose: "added the build label" and "removed" are the same kind of event, and the verb
|
|
1081
|
+
next to it is what tells them apart. */
|
|
1082
|
+
const GLYPH = {
|
|
1083
|
+
"cross-referenced": "crossref", referenced: "commit", closed: "closed",
|
|
1084
|
+
reopened: "reopened", merged: "merged",
|
|
1085
|
+
review: "review", "review-requested": "review", "ready-for-review": "review",
|
|
1086
|
+
labeled: "label", unlabeled: "label", assigned: "person", unassigned: "person",
|
|
1087
|
+
renamed: "rename",
|
|
1088
|
+
};
|
|
1089
|
+
|
|
1090
|
+
function reviewWord(state) {
|
|
1091
|
+
return state === "APPROVED" ? "approved" :
|
|
1092
|
+
state === "CHANGES_REQUESTED" ? "requested changes" : "reviewed";
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
/** One event as a line: a marker, what happened, and whatever it points at. */
|
|
1096
|
+
function eventLine(e, item, openThread) {
|
|
1097
|
+
const d = el("div", { className: "tev " + e.type });
|
|
1098
|
+
const mark = el("span", { className: "tico" });
|
|
1099
|
+
mark.innerHTML = iconHTML(GLYPH[e.type] ?? "dot");
|
|
1100
|
+
d.append(mark);
|
|
1101
|
+
const body = el("div", { className: "tbody" });
|
|
1102
|
+
d.append(body);
|
|
1103
|
+
|
|
1104
|
+
const said = (html) => {
|
|
1105
|
+
body.insertAdjacentHTML(
|
|
1106
|
+
"beforeend",
|
|
1107
|
+
"<b>" + esc(e.actor || "someone") + "</b> " + html +
|
|
1108
|
+
' <span class="twhen">· ' + esc(ago(e.createdAt)) + "</span>",
|
|
1109
|
+
);
|
|
1110
|
+
};
|
|
1111
|
+
|
|
1112
|
+
switch (e.type) {
|
|
1113
|
+
case "cross-referenced":
|
|
1114
|
+
said("mentioned this in");
|
|
1115
|
+
body.append(xref(e.source, item, openThread));
|
|
1116
|
+
break;
|
|
1117
|
+
|
|
1118
|
+
case "referenced": {
|
|
1119
|
+
const where = e.commit?.repo && e.commit.repo !== item.repo ? " in " + esc(e.commit.repo) : "";
|
|
1120
|
+
said("added a commit that references this" + where);
|
|
1121
|
+
if (e.commit) {
|
|
1122
|
+
body.append(
|
|
1123
|
+
el("a", {
|
|
1124
|
+
className: "tcommit",
|
|
1125
|
+
href: e.commit.url,
|
|
1126
|
+
target: "_blank",
|
|
1127
|
+
rel: "noopener",
|
|
1128
|
+
textContent: e.commit.subject || e.commit.sha,
|
|
1129
|
+
title: e.commit.sha,
|
|
1130
|
+
}),
|
|
1131
|
+
);
|
|
1132
|
+
}
|
|
1133
|
+
break;
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
case "closed":
|
|
1137
|
+
said(e.closer ? "closed this as completed by" : "closed this");
|
|
1138
|
+
if (e.closer) body.append(xref({ ...e.closer, kind: "pr", state: "MERGED", repo: item.repo }, item, openThread));
|
|
1139
|
+
break;
|
|
1140
|
+
|
|
1141
|
+
case "reopened": said("reopened this"); break;
|
|
1142
|
+
case "merged": said("merged this"); break;
|
|
1143
|
+
case "review": said(reviewWord(e.state) + " this"); break;
|
|
1144
|
+
case "ready-for-review": said("marked this ready for review"); break;
|
|
1145
|
+
case "review-requested": said("requested a review from <b>" + esc(e.assignee) + "</b>"); break;
|
|
1146
|
+
case "labeled": said("added the <b>" + esc(e.label) + "</b> label"); break;
|
|
1147
|
+
case "unlabeled": said("removed the <b>" + esc(e.label) + "</b> label"); break;
|
|
1148
|
+
case "assigned": said("assigned <b>" + esc(e.assignee) + "</b>"); break;
|
|
1149
|
+
case "unassigned": said("unassigned <b>" + esc(e.assignee) + "</b>"); break;
|
|
1150
|
+
case "renamed": said("renamed this from “" + esc(e.from) + "”"); break;
|
|
1151
|
+
default: said(e.type);
|
|
1152
|
+
}
|
|
1153
|
+
return d;
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
/** The issue or PR an event points at. Open it here if it is one of ours; GitHub if not. */
|
|
1157
|
+
function xref(source, item, openThread) {
|
|
1158
|
+
const state = String(source.state ?? "OPEN").toLowerCase();
|
|
1159
|
+
const b = el("button", { className: "xref" });
|
|
1160
|
+
const glyph =
|
|
1161
|
+
state === "merged" ? "merged" :
|
|
1162
|
+
state === "closed" ? "issue-closed" :
|
|
1163
|
+
state === "draft" ? "draft" : "issue-open";
|
|
1164
|
+
const st = el("span", { className: "st " + state, title: state });
|
|
1165
|
+
st.innerHTML = iconHTML(glyph);
|
|
1166
|
+
b.append(
|
|
1167
|
+
st,
|
|
1168
|
+
el("span", { className: "t", textContent: source.title || "#" + source.number }),
|
|
1169
|
+
el("span", {
|
|
1170
|
+
className: "n",
|
|
1171
|
+
textContent: (source.repo && source.repo !== item.repo ? source.repo.split("/")[1] + " " : "") +
|
|
1172
|
+
"#" + source.number,
|
|
1173
|
+
}),
|
|
1174
|
+
);
|
|
1175
|
+
// Open it in the portal when it is something the inbox already holds; otherwise GitHub,
|
|
1176
|
+
// because a closed issue is not in the inbox and there is nothing here to show.
|
|
1177
|
+
b.onclick = () => {
|
|
1178
|
+
const known = (S.inbox?.items ?? []).find(
|
|
1179
|
+
(i) => i.repo === source.repo && i.number === source.number,
|
|
1180
|
+
);
|
|
1181
|
+
if (known) {
|
|
1182
|
+
S.inboxOpen = { repo: known.repo, number: known.number, kind: known.kind };
|
|
1183
|
+
writeHash(false);
|
|
1184
|
+
openThread(S.inboxOpen);
|
|
1185
|
+
return;
|
|
1186
|
+
}
|
|
1187
|
+
if (source.url) open(source.url, "_blank", "noopener");
|
|
1188
|
+
};
|
|
1189
|
+
return b;
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
/* Who wrote something, as a person would say it: a staff member by their role, with their
|
|
1193
|
+
icon; one of the humans by name; anyone else by their login. */
|
|
1194
|
+
function whoWrote(login) {
|
|
1195
|
+
const s = (S.data?.staff ?? []).find((x) => (x.soloBots ?? []).includes(login));
|
|
1196
|
+
if (s) return { name: s.name, glyph: staffIcon(s), kind: "staff" };
|
|
1197
|
+
if (isHuman(login)) {
|
|
1198
|
+
const h = humansOf().find((x) => x.github === login);
|
|
1199
|
+
return { name: h?.name ?? login, glyph: "person", kind: "human" };
|
|
1200
|
+
}
|
|
1201
|
+
return { name: login || "?", glyph: "person", kind: "other" };
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
/* A comment is a card: a header strip saying who and when, then what they said. As text
|
|
1205
|
+
between thin rules, it was hard to see where one message ended and the next began. */
|
|
1206
|
+
function comment({ author, when, body, first, repo, badge, reactions }) {
|
|
1207
|
+
const who = whoWrote(author);
|
|
1208
|
+
const d = el("div", { className: "cmt " + who.kind + (first ? " first" : "") });
|
|
1209
|
+
const head = el("div", { className: "chead" });
|
|
1210
|
+
head.append(icon(who.glyph, "ic"), el("b", { textContent: who.name }));
|
|
1211
|
+
if (who.name !== author && author) head.append(el("span", { className: "clogin", textContent: author }));
|
|
1212
|
+
if (badge) head.append(el("span", { className: "pill", textContent: badge }));
|
|
1213
|
+
head.append(
|
|
1214
|
+
el("span", { className: "cwhen", title: new Date(when).toLocaleString(), textContent: ago(when) }),
|
|
1215
|
+
);
|
|
1216
|
+
d.append(head);
|
|
1217
|
+
const bodyEl = el("div", { className: "cbodywrap" });
|
|
1218
|
+
bodyEl.append(el("div", { className: "md cbody", innerHTML: mdlite(body || "_no description_", { repo }) }));
|
|
1219
|
+
const marks = reactionRow(reactions);
|
|
1220
|
+
if (marks) bodyEl.append(marks);
|
|
1221
|
+
d.append(bodyEl);
|
|
1222
|
+
return d;
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
/* GitHub's eight, by their API names. An agent that has picked something up puts 👀 on it, and
|
|
1226
|
+
that acknowledgement is most of why these are worth rendering at all: without it a person
|
|
1227
|
+
posts a comment and has no way to see it landed short of opening GitHub. */
|
|
1228
|
+
const REACTION = {
|
|
1229
|
+
THUMBS_UP: "👍", THUMBS_DOWN: "👎", LAUGH: "😄", HOORAY: "🎉",
|
|
1230
|
+
CONFUSED: "😕", HEART: "❤️", ROCKET: "🚀", EYES: "👀",
|
|
1231
|
+
};
|
|
1232
|
+
|
|
1233
|
+
function reactionRow(reactions) {
|
|
1234
|
+
const list = (reactions ?? []).filter((r) => r.count > 0);
|
|
1235
|
+
if (!list.length) return null;
|
|
1236
|
+
const row = el("div", { className: "reacts" });
|
|
1237
|
+
for (const r of list) {
|
|
1238
|
+
const extra = r.count - r.by.length;
|
|
1239
|
+
row.append(
|
|
1240
|
+
el("span", {
|
|
1241
|
+
className: "react",
|
|
1242
|
+
title: r.by.join(", ") + (extra > 0 ? " and " + extra + " more" : ""),
|
|
1243
|
+
textContent: (REACTION[r.content] ?? "•") + " " + r.count,
|
|
1244
|
+
}),
|
|
1245
|
+
);
|
|
1246
|
+
}
|
|
1247
|
+
return row;
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
function checkGlyph(state) {
|
|
1251
|
+
return iconHTML(state === "passing" ? "check" : state === "failing" ? "close" : "dot");
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
/* --------------------------------- new issue -------------------------------- */
|
|
1255
|
+
|
|
1256
|
+
/**
|
|
1257
|
+
* Ask one of the staff for something.
|
|
1258
|
+
*
|
|
1259
|
+
* One question, one dropdown: **who is this for**. It used to be two — a staff member and a
|
|
1260
|
+
* repo — which asked you to know that an issue reaches an agent by landing in their brain repo
|
|
1261
|
+
* *and* saying their `@handle`, and let you set the pair to a combination that reaches nobody.
|
|
1262
|
+
* Neither of those is a decision worth having; both follow from the name you picked.
|
|
1263
|
+
*
|
|
1264
|
+
* So the repo is their brain, the mention goes in the body and is kept in step with the choice,
|
|
1265
|
+
* and where it is going is said on the page rather than chosen on it.
|
|
1266
|
+
*/
|
|
1267
|
+
function newIssueForm(viewer) {
|
|
1268
|
+
const box = el("div");
|
|
1269
|
+
const title = el("input", { type: "search", placeholder: "Title", style: "width:100%" });
|
|
1270
|
+
const body = el("textarea", {
|
|
1271
|
+
placeholder: "What do you want them to do? (markdown)",
|
|
1272
|
+
rows: 8,
|
|
1273
|
+
value: "",
|
|
1274
|
+
});
|
|
1275
|
+
const status = el("span", { className: "meta" });
|
|
1276
|
+
const create = el("button", { className: "ghbtn primary", textContent: "Send it" });
|
|
1277
|
+
|
|
1278
|
+
const mentionOf = (s) => s.mention ?? "@" + s.handle;
|
|
1279
|
+
const chosen = () => S.data.staff.find((x) => x.handle === who.value) ?? null;
|
|
1280
|
+
const repoOf = () => chosen()?.brain ?? "";
|
|
1281
|
+
|
|
1282
|
+
const picked = labelPicker(repoOf);
|
|
1283
|
+
const files = attachBox(body, repoOf);
|
|
1284
|
+
// The recipient's mention is written in for you; this is for the second one, when an issue
|
|
1285
|
+
// needs somebody else to see it too.
|
|
1286
|
+
attachMentions(body);
|
|
1287
|
+
|
|
1288
|
+
const who = el("select", { title: "Whose brain this goes to" });
|
|
1289
|
+
who.append(
|
|
1290
|
+
...S.data.staff.map((s) =>
|
|
1291
|
+
el("option", {
|
|
1292
|
+
value: s.handle,
|
|
1293
|
+
textContent: s.name + (s.brain ? "" : " · no brain repo"),
|
|
1294
|
+
}),
|
|
1295
|
+
),
|
|
1296
|
+
);
|
|
1297
|
+
if (!S.data.staff.length) {
|
|
1298
|
+
who.append(el("option", { value: "", textContent: "nobody has been hired yet" }));
|
|
1299
|
+
}
|
|
1300
|
+
who.value = S.inboxStaff || S.data.staff[0]?.handle || "";
|
|
1301
|
+
|
|
1302
|
+
/* The mention is the mechanism: their workflow gates on it, so a body without one is a note
|
|
1303
|
+
nobody is woken by. It is written in for you, and rewritten when you change your mind —
|
|
1304
|
+
leaving the last person's `@handle` at the top would send the issue to one staff member
|
|
1305
|
+
and address it to another. */
|
|
1306
|
+
const MENTIONS = S.data.staff.map(mentionOf);
|
|
1307
|
+
const retarget = (to) => {
|
|
1308
|
+
const at = mentionOf(to);
|
|
1309
|
+
let text = String(body.value ?? "");
|
|
1310
|
+
for (const old of MENTIONS) {
|
|
1311
|
+
if (old === at) continue;
|
|
1312
|
+
text = text.replace(new RegExp("^\\s*" + old.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + "\\s*"), "");
|
|
1313
|
+
}
|
|
1314
|
+
body.value = text.includes(at) ? text : at + " " + text.replace(/^\s+/, "");
|
|
1315
|
+
};
|
|
1316
|
+
|
|
1317
|
+
who.onchange = () => {
|
|
1318
|
+
const s = chosen();
|
|
1319
|
+
if (!s) return;
|
|
1320
|
+
retarget(s);
|
|
1321
|
+
picked.load();
|
|
1322
|
+
hint();
|
|
1323
|
+
};
|
|
1324
|
+
|
|
1325
|
+
/* Where it lands and what wakes them, said out loud. Somebody who deletes the mention from
|
|
1326
|
+
the body has quietly turned a request into a note, and this is the only thing that says so. */
|
|
1327
|
+
const forWhom = el("p", { className: "meta", style: "margin:9px 0 0" });
|
|
1328
|
+
const hint = () => {
|
|
1329
|
+
const s = chosen();
|
|
1330
|
+
if (!s) {
|
|
1331
|
+
forWhom.textContent = "There is nobody to send this to yet. Hire a staff member first.";
|
|
1332
|
+
create.disabled = true;
|
|
1333
|
+
return;
|
|
1334
|
+
}
|
|
1335
|
+
if (!s.brain) {
|
|
1336
|
+
forWhom.textContent =
|
|
1337
|
+
s.name + " has no brain repo in their manifest, so there is nowhere to put this.";
|
|
1338
|
+
create.disabled = true;
|
|
1339
|
+
return;
|
|
1340
|
+
}
|
|
1341
|
+
create.disabled = false;
|
|
1342
|
+
forWhom.textContent =
|
|
1343
|
+
"Goes to " + s.brain + ". " +
|
|
1344
|
+
(String(body.value ?? "").includes(mentionOf(s))
|
|
1345
|
+
? mentionOf(s) + " in the body is what wakes them, usually within a minute."
|
|
1346
|
+
: "Put " + mentionOf(s) + " back in the body, or nothing will wake them.");
|
|
1347
|
+
};
|
|
1348
|
+
body.addEventListener("input", hint);
|
|
1349
|
+
|
|
1350
|
+
if (chosen()) retarget(chosen());
|
|
1351
|
+
picked.load();
|
|
1352
|
+
hint();
|
|
1353
|
+
|
|
1354
|
+
create.onclick = async () => {
|
|
1355
|
+
const s = chosen();
|
|
1356
|
+
if (!s?.brain) return;
|
|
1357
|
+
if (!title.value.trim()) { title.focus(); return; }
|
|
1358
|
+
create.disabled = true;
|
|
1359
|
+
status.textContent = "creating…";
|
|
1360
|
+
status.className = "meta";
|
|
1361
|
+
try {
|
|
1362
|
+
const r = await post({
|
|
1363
|
+
action: "create",
|
|
1364
|
+
repo: s.brain,
|
|
1365
|
+
title: title.value,
|
|
1366
|
+
body: body.value,
|
|
1367
|
+
labels: picked.chosen(),
|
|
1368
|
+
});
|
|
1369
|
+
/* The form is done once GitHub has the issue. What you sent is shown as what it now is,
|
|
1370
|
+
a thread in the inbox, open and selected, rather than a link out to github.com beside
|
|
1371
|
+
a form still holding what you typed. The filters are set so its row is on the list. */
|
|
1372
|
+
const number = Number(String(r.url ?? "").match(/\/issues\/(\d+)/)?.[1]);
|
|
1373
|
+
S.inboxOpen = number ? { repo: s.brain, number, kind: "issue" } : null;
|
|
1374
|
+
S.inboxState = "";
|
|
1375
|
+
S.inboxFilter = "";
|
|
1376
|
+
S.query = "";
|
|
1377
|
+
if (S.inboxStaff && S.inboxStaff !== s.handle) S.inboxStaff = s.handle;
|
|
1378
|
+
writeHash(false);
|
|
1379
|
+
status.textContent = "sent · opening it…";
|
|
1380
|
+
// It is sent either way. A refresh that fails must not read as a send that failed.
|
|
1381
|
+
await refreshAll(false).catch(() => {
|
|
1382
|
+
status.textContent = "sent · refresh to see it";
|
|
1383
|
+
});
|
|
1384
|
+
return;
|
|
1385
|
+
} catch (e) {
|
|
1386
|
+
status.textContent = e.message;
|
|
1387
|
+
status.className = "meta err";
|
|
1388
|
+
}
|
|
1389
|
+
create.disabled = false;
|
|
1390
|
+
};
|
|
1391
|
+
|
|
1392
|
+
box.append(
|
|
1393
|
+
el("h3", { style: "margin:0 0 12px;font:600 16px var(--sans)", textContent: "Ask a staff member" }),
|
|
1394
|
+
el("div", { className: "row", style: "margin-bottom:9px" }, [
|
|
1395
|
+
el("label", { className: "meta", textContent: "For", htmlFor: "newissue-who" }),
|
|
1396
|
+
Object.assign(who, { id: "newissue-who" }),
|
|
1397
|
+
]),
|
|
1398
|
+
el("div", { className: "row", style: "margin-bottom:9px" }, [title]),
|
|
1399
|
+
body,
|
|
1400
|
+
forWhom,
|
|
1401
|
+
files.node,
|
|
1402
|
+
picked.node,
|
|
1403
|
+
el("div", { className: "row", style: "margin-top:10px" }, [create, status]),
|
|
1404
|
+
);
|
|
1405
|
+
viewer.replaceChildren(box);
|
|
1406
|
+
}
|
|
1407
|
+
|
|
1408
|
+
/* --------------------------------- labels --------------------------------- */
|
|
1409
|
+
|
|
1410
|
+
/**
|
|
1411
|
+
* The repo's own labels, as toggles.
|
|
1412
|
+
*
|
|
1413
|
+
* This used to be a text box you typed comma-separated names into, which is a spelling test:
|
|
1414
|
+
* `from-cmo` and `from-CMO` are different labels and only one of them exists. The set is small
|
|
1415
|
+
* and it is knowable, so it is offered instead.
|
|
1416
|
+
*
|
|
1417
|
+
* When GitHub cannot be reached the labels already on items in the inbox stand in. They are
|
|
1418
|
+
* not the whole vocabulary, but they are real, and a picker with the common ones beats a
|
|
1419
|
+
* disabled one.
|
|
1420
|
+
*/
|
|
1421
|
+
function labelPicker(repoOf) {
|
|
1422
|
+
const node = el("div", { className: "labelpick" });
|
|
1423
|
+
const head = el("div", { className: "meta", textContent: "Labels" });
|
|
1424
|
+
const wrap = el("div", { className: "chips" });
|
|
1425
|
+
node.append(head, wrap);
|
|
1426
|
+
const chosen = new Set();
|
|
1427
|
+
|
|
1428
|
+
const paint = (labels, note) => {
|
|
1429
|
+
wrap.replaceChildren();
|
|
1430
|
+
head.textContent = "Labels" + (note ? " · " + note : "");
|
|
1431
|
+
if (!labels.length) {
|
|
1432
|
+
wrap.append(el("span", { className: "meta", textContent: "none on this repo" }));
|
|
1433
|
+
return;
|
|
1434
|
+
}
|
|
1435
|
+
for (const name of labels) {
|
|
1436
|
+
const b = el("button", { className: "chip pick " + tone(name), textContent: name });
|
|
1437
|
+
b.type = "button";
|
|
1438
|
+
b.setAttribute("aria-pressed", String(chosen.has(name)));
|
|
1439
|
+
b.onclick = () => {
|
|
1440
|
+
if (chosen.has(name)) chosen.delete(name);
|
|
1441
|
+
else chosen.add(name);
|
|
1442
|
+
b.setAttribute("aria-pressed", String(chosen.has(name)));
|
|
1443
|
+
};
|
|
1444
|
+
wrap.append(b);
|
|
1445
|
+
}
|
|
1446
|
+
};
|
|
1447
|
+
|
|
1448
|
+
const seen = (repo) => [
|
|
1449
|
+
...new Set((S.inbox?.items ?? []).filter((i) => i.repo === repo).flatMap((i) => i.labels ?? [])),
|
|
1450
|
+
].sort();
|
|
1451
|
+
|
|
1452
|
+
const load = async () => {
|
|
1453
|
+
const repo = repoOf();
|
|
1454
|
+
chosen.clear();
|
|
1455
|
+
if (!repo) { paint([]); return; }
|
|
1456
|
+
paint([], "asking GitHub…");
|
|
1457
|
+
try {
|
|
1458
|
+
const r = await getLabels(repo);
|
|
1459
|
+
if (r.error) paint(seen(repo), "GitHub said: " + r.error);
|
|
1460
|
+
else paint((r.labels ?? []).map((l) => l.name));
|
|
1461
|
+
} catch {
|
|
1462
|
+
paint(seen(repo), "offline, showing labels already in use");
|
|
1463
|
+
}
|
|
1464
|
+
};
|
|
1465
|
+
|
|
1466
|
+
return { node, load, chosen: () => [...chosen] };
|
|
1467
|
+
}
|
|
1468
|
+
|
|
1469
|
+
/* ------------------------------- attachments ------------------------------- */
|
|
1470
|
+
|
|
1471
|
+
/**
|
|
1472
|
+
* Files onto an issue.
|
|
1473
|
+
*
|
|
1474
|
+
* GitHub's own drag-and-drop attachments are minted by its web app and cannot be made with
|
|
1475
|
+
* `gh`, so a file dropped here is committed into the repo the issue is in and linked. That is
|
|
1476
|
+
* the better answer for this org anyway: every run clones the repo, so an agent opens the
|
|
1477
|
+
* screenshot off its own disk instead of being handed a URL it has no token for.
|
|
1478
|
+
*
|
|
1479
|
+
* Drop, pick or paste — paste is the one that matters, because a screenshot is on the
|
|
1480
|
+
* clipboard and never on disk.
|
|
1481
|
+
*/
|
|
1482
|
+
function attachBox(ta, repoOf) {
|
|
1483
|
+
const node = el("div", { className: "attach" });
|
|
1484
|
+
const pick = el("input", { type: "file", multiple: true, hidden: true });
|
|
1485
|
+
const btn = el("button", { className: "ghbtn", type: "button" });
|
|
1486
|
+
btn.append(icon("paperclip", "ic"), el("span", { textContent: "Attach files" }));
|
|
1487
|
+
const status = el("span", { className: "meta", textContent: "or drop them on the box above" });
|
|
1488
|
+
node.append(pick, btn, status);
|
|
1489
|
+
|
|
1490
|
+
const say = (text, bad) => {
|
|
1491
|
+
status.textContent = text;
|
|
1492
|
+
status.className = bad ? "meta err" : "meta";
|
|
1493
|
+
};
|
|
1494
|
+
|
|
1495
|
+
/* Written at the cursor, so an attachment lands where you were typing rather than at the
|
|
1496
|
+
end of whatever you had written. The repo path goes in beside the link: the link is for
|
|
1497
|
+
the person, the path is for the model. */
|
|
1498
|
+
const insert = (a) => {
|
|
1499
|
+
const name = a.path.split("/").pop();
|
|
1500
|
+
const media = /\.(png|jpe?g|gif|svg|webp|mp4|mov|webm|m4v)$/i.test(name);
|
|
1501
|
+
const text = (media ? "!" : "") + "[" + name + "](" + a.url + ")\n`" + a.path + "`\n";
|
|
1502
|
+
const at = ta.selectionStart ?? ta.value.length;
|
|
1503
|
+
const before = ta.value.slice(0, at);
|
|
1504
|
+
ta.value = before + (before && !before.endsWith("\n") ? "\n" : "") + text + ta.value.slice(at);
|
|
1505
|
+
ta.selectionStart = ta.selectionEnd = before.length + text.length + 1;
|
|
1506
|
+
ta.focus();
|
|
1507
|
+
};
|
|
1508
|
+
|
|
1509
|
+
const send = async (list) => {
|
|
1510
|
+
const repo = repoOf();
|
|
1511
|
+
if (!repo) { say("pick a repo first", true); return; }
|
|
1512
|
+
const files = [...list].filter((f) => f.size);
|
|
1513
|
+
if (!files.length) return;
|
|
1514
|
+
btn.disabled = true;
|
|
1515
|
+
for (const [n, f] of files.entries()) {
|
|
1516
|
+
say("uploading " + f.name + (files.length > 1 ? " (" + (n + 1) + "/" + files.length + ")" : "") + "…");
|
|
1517
|
+
try {
|
|
1518
|
+
const a = await upload(repo, f);
|
|
1519
|
+
insert(a);
|
|
1520
|
+
say(
|
|
1521
|
+
a.pushed
|
|
1522
|
+
? "committed " + a.path + " to " + repo
|
|
1523
|
+
: "committed locally but not pushed: " + a.note,
|
|
1524
|
+
!a.pushed,
|
|
1525
|
+
);
|
|
1526
|
+
} catch (e) {
|
|
1527
|
+
say(f.name + ": " + e.message, true);
|
|
1528
|
+
break;
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
btn.disabled = false;
|
|
1532
|
+
pick.value = "";
|
|
1533
|
+
};
|
|
1534
|
+
|
|
1535
|
+
btn.onclick = () => pick.click();
|
|
1536
|
+
pick.onchange = () => send(pick.files);
|
|
1537
|
+
|
|
1538
|
+
for (const zone of [node, ta]) {
|
|
1539
|
+
zone.addEventListener("dragover", (e) => {
|
|
1540
|
+
e.preventDefault();
|
|
1541
|
+
ta.classList.add("dropping");
|
|
1542
|
+
});
|
|
1543
|
+
zone.addEventListener("dragleave", () => ta.classList.remove("dropping"));
|
|
1544
|
+
zone.addEventListener("drop", (e) => {
|
|
1545
|
+
e.preventDefault();
|
|
1546
|
+
ta.classList.remove("dropping");
|
|
1547
|
+
send(e.dataTransfer?.files ?? []);
|
|
1548
|
+
});
|
|
1549
|
+
}
|
|
1550
|
+
ta.addEventListener("paste", (e) => {
|
|
1551
|
+
const files = [...(e.clipboardData?.files ?? [])];
|
|
1552
|
+
if (!files.length) return;
|
|
1553
|
+
e.preventDefault();
|
|
1554
|
+
send(files);
|
|
1555
|
+
});
|
|
1556
|
+
|
|
1557
|
+
return { node };
|
|
1558
|
+
}
|