starlight-annotations 0.8.0 → 0.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/CHANGELOG.md +12 -0
- package/index.d.ts +12 -0
- package/package.json +1 -1
- package/server.d.ts +15 -1
- package/src/client/annotations.js +71 -15
- package/src/client/i18n.js +60 -0
- package/src/client/overview.js +27 -4
- package/src/client/shared.js +7 -0
- package/src/client/styles.css +39 -0
- package/src/core.js +43 -4
- package/src/server/github.js +33 -4
- package/src/server/index.js +18 -2
- package/src/server/issue.js +59 -0
- package/src/server/notify.js +5 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# starlight-annotations
|
|
2
2
|
|
|
3
|
+
## 0.10.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- ba3c36b: With `issues: true` in the GitHub options (or `{ repo }` for another repository), every open thread has **Open issue**: the server opens a GitHub issue with the quote, a link back and the whole conversation, labelled with the note's kind, then resolves the note and links the issue in the panel and on the overview page. The credential needs Issues read/write. `onChange` receives the new `issue` action, which Slack and Teams post.
|
|
8
|
+
|
|
9
|
+
## 0.9.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 61b2bef: Notes can have a kind (question, problem, proposal or decision), shown as a label and filtered on the overview page. **+ Note on this page** writes a note about the whole page rather than a passage. In the file, a thread has an optional `kind`, and a page note has a `target` without a `selector`. Slack and Teams titles name the kind ("Ada added a question on …").
|
|
14
|
+
|
|
3
15
|
## 0.8.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/index.d.ts
CHANGED
|
@@ -68,6 +68,18 @@ export type AnnotationStrings = {
|
|
|
68
68
|
fresh: string;
|
|
69
69
|
freshCount: string;
|
|
70
70
|
mentions: string;
|
|
71
|
+
kind: string;
|
|
72
|
+
noKind: string;
|
|
73
|
+
allKinds: string;
|
|
74
|
+
kindQuestion: string;
|
|
75
|
+
kindIssue: string;
|
|
76
|
+
kindProposal: string;
|
|
77
|
+
kindDecision: string;
|
|
78
|
+
wholePage: string;
|
|
79
|
+
pageNote: string;
|
|
80
|
+
openIssue: string;
|
|
81
|
+
confirmIssue: string;
|
|
82
|
+
issue: string;
|
|
71
83
|
};
|
|
72
84
|
|
|
73
85
|
export interface StarlightAnnotationsOptions {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "starlight-annotations",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "🖍️ Let readers highlight text and leave notes on Starlight docs. Notes are committed to your Git repository on GitHub, GitLab, Gitea or Forgejo.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Alessandro Rosa",
|
package/server.d.ts
CHANGED
|
@@ -20,6 +20,14 @@ export interface Storage {
|
|
|
20
20
|
mutate: (doc: AnnotationDocument) => { annotation: Record<string, unknown>; message: string },
|
|
21
21
|
user: User,
|
|
22
22
|
): Promise<{ annotation: Record<string, unknown>; annotations: Record<string, unknown>[] }>;
|
|
23
|
+
/** Opens an issue for a thread. When present, the panel offers "Open issue". Optional. */
|
|
24
|
+
createIssue?(input: {
|
|
25
|
+
page: string;
|
|
26
|
+
thread: Record<string, any>;
|
|
27
|
+
replies: Record<string, any>[];
|
|
28
|
+
url: string;
|
|
29
|
+
user: User;
|
|
30
|
+
}): Promise<{ number: number; url: string }>;
|
|
23
31
|
}
|
|
24
32
|
|
|
25
33
|
export interface Auth {
|
|
@@ -38,7 +46,7 @@ export interface Auth {
|
|
|
38
46
|
openContact?(sealed: string): Promise<string | null>;
|
|
39
47
|
}
|
|
40
48
|
|
|
41
|
-
export type AnnotationAction = 'create' | 'reply' | 'resolve' | 'reopen' | 'edit' | 'anchor' | 'delete';
|
|
49
|
+
export type AnnotationAction = 'create' | 'reply' | 'resolve' | 'reopen' | 'edit' | 'anchor' | 'issue' | 'delete';
|
|
42
50
|
|
|
43
51
|
/** What `onChange` receives after every saved change. */
|
|
44
52
|
export interface AnnotationEvent {
|
|
@@ -110,6 +118,12 @@ export interface GitHubStorageOptions {
|
|
|
110
118
|
dir?: string;
|
|
111
119
|
/** Rewrite the commit message, e.g. to fit your commit convention. */
|
|
112
120
|
commitMessage?: (message: string, page: string) => string;
|
|
121
|
+
/**
|
|
122
|
+
* Let readers turn a thread into a GitHub issue, which resolves the note.
|
|
123
|
+
* `true` opens issues in `repo`; `{ repo }` in another repository. The token
|
|
124
|
+
* or GitHub App needs Issues read/write there.
|
|
125
|
+
*/
|
|
126
|
+
issues?: boolean | { repo?: string };
|
|
113
127
|
}
|
|
114
128
|
|
|
115
129
|
export interface GitHubAppOptions {
|
|
@@ -12,7 +12,7 @@ import { anchor, buildIndex as indexText, skipSelector } from './anchoring.js';
|
|
|
12
12
|
import { strings } from './i18n.js';
|
|
13
13
|
import { isNew, knownPeople, markSeen, rememberPeople, seenTimes } from './memory.js';
|
|
14
14
|
import { attachMentions } from './mentions.js';
|
|
15
|
-
import { h, loadMarkdown, quoteText, renderMarkdown } from './shared.js';
|
|
15
|
+
import { h, kindLabel, KINDS, loadMarkdown, quoteText, renderMarkdown } from './shared.js';
|
|
16
16
|
|
|
17
17
|
const BASE = import.meta.env.BASE_URL.replace(/\/$/, '');
|
|
18
18
|
const SKIP = skipSelector(config.exclude);
|
|
@@ -169,6 +169,7 @@ async function start(root) {
|
|
|
169
169
|
annotations: initial.annotations,
|
|
170
170
|
user: initial.user,
|
|
171
171
|
mode: initial.mode,
|
|
172
|
+
issues: Boolean(initial.issues), // the server can turn a thread into an issue
|
|
172
173
|
index: null,
|
|
173
174
|
anchors: new Map(), // id -> { start, end, range }
|
|
174
175
|
pending: null, // the selector of the selection being annotated
|
|
@@ -253,6 +254,7 @@ async function start(root) {
|
|
|
253
254
|
state.index = buildIndex(root);
|
|
254
255
|
state.anchors.clear();
|
|
255
256
|
for (const thread of threads()) {
|
|
257
|
+
if (!thread.target?.selector) continue;
|
|
256
258
|
const found = anchor(state.index, thread.target.selector);
|
|
257
259
|
if (found) state.anchors.set(thread.id, { start: found[0], end: found[1], range: rangeFor(state.index, ...found) });
|
|
258
260
|
}
|
|
@@ -320,9 +322,20 @@ async function start(root) {
|
|
|
320
322
|
);
|
|
321
323
|
}
|
|
322
324
|
|
|
323
|
-
|
|
325
|
+
// `kind` is given for the first note of a thread (null when it has none):
|
|
326
|
+
// the editor then lets the writer pick one. onSave gets (text, kind).
|
|
327
|
+
function editor(placeholder, onSave, onCancel, { initial = '', kind } = {}) {
|
|
324
328
|
const area = h('textarea', { rows: 4, placeholder, maxlength: 5000, 'aria-label': placeholder });
|
|
325
329
|
area.value = initial;
|
|
330
|
+
const kindSelect =
|
|
331
|
+
kind === undefined
|
|
332
|
+
? null
|
|
333
|
+
: h(
|
|
334
|
+
'select',
|
|
335
|
+
{ class: 'annot-kind-select', 'aria-label': T.kind },
|
|
336
|
+
h('option', { value: '' }, T.noKind),
|
|
337
|
+
KINDS.map((value) => h('option', { value, selected: kind === value }, kindLabel(value, T))),
|
|
338
|
+
);
|
|
326
339
|
const mentions = attachMentions(
|
|
327
340
|
area,
|
|
328
341
|
() =>
|
|
@@ -376,7 +389,7 @@ async function start(root) {
|
|
|
376
389
|
save.addEventListener('click', async () => {
|
|
377
390
|
if (!area.value.trim()) return area.focus();
|
|
378
391
|
busy(true);
|
|
379
|
-
const ok = await onSave(area.value);
|
|
392
|
+
const ok = await onSave(area.value, kindSelect ? kindSelect.value || null : undefined);
|
|
380
393
|
if (!ok) busy(false);
|
|
381
394
|
});
|
|
382
395
|
area.addEventListener('keydown', (event) => {
|
|
@@ -405,13 +418,20 @@ async function start(root) {
|
|
|
405
418
|
'div',
|
|
406
419
|
{ class: 'annot-actions' },
|
|
407
420
|
save,
|
|
421
|
+
kindSelect,
|
|
408
422
|
h('button', { type: 'button', onclick: onCancel }, T.cancel),
|
|
409
423
|
h('a', { class: 'annot-hint', href: 'https://www.markdownguide.org/basic-syntax/', target: '_blank', rel: 'noopener noreferrer' }, T.markdown),
|
|
410
424
|
),
|
|
411
425
|
);
|
|
412
426
|
}
|
|
413
427
|
|
|
428
|
+
// The quoted passage, or "Whole page" for a note about the page.
|
|
429
|
+
function issueLink(issue) {
|
|
430
|
+
return h('a', { class: 'annot-issue', href: issue.url, target: '_blank', rel: 'noopener noreferrer' }, `${T.issue} #${issue.number} ↗`);
|
|
431
|
+
}
|
|
432
|
+
|
|
414
433
|
function quote(selector) {
|
|
434
|
+
if (!selector) return h('div', { class: 'annot-quote annot-whole-page' }, T.wholePage);
|
|
415
435
|
return h('blockquote', { class: 'annot-quote' }, quoteText(selector));
|
|
416
436
|
}
|
|
417
437
|
|
|
@@ -437,6 +457,7 @@ async function start(root) {
|
|
|
437
457
|
}
|
|
438
458
|
|
|
439
459
|
function threadCard(thread, anchored) {
|
|
460
|
+
const whole = !thread.target?.selector;
|
|
440
461
|
const card = h('article', {
|
|
441
462
|
class: `annot-thread${thread.resolved ? ' resolved' : ''}${state.active === thread.id ? ' active' : ''}`,
|
|
442
463
|
'data-id': thread.id,
|
|
@@ -485,24 +506,25 @@ async function start(root) {
|
|
|
485
506
|
if (state.editing !== item.id || !own(item)) return renderMarkdown(h('div', { class: 'annot-text annot-md' }), item.body);
|
|
486
507
|
return editor(
|
|
487
508
|
item.replyTo ? T.replyPlaceholder : T.placeholder,
|
|
488
|
-
async (value) => {
|
|
489
|
-
|
|
509
|
+
async (value, kind) => {
|
|
510
|
+
const sameKind = kind === undefined || kind === (item.kind ?? null);
|
|
511
|
+
if (value.trim() === item.body && sameKind) {
|
|
490
512
|
stopEditing();
|
|
491
513
|
return true;
|
|
492
514
|
}
|
|
493
|
-
const saved = await send({ action: 'edit', id: item.id, body: value });
|
|
515
|
+
const saved = await send({ action: 'edit', id: item.id, body: value, ...(kind === undefined ? {} : { kind }) });
|
|
494
516
|
if (!saved) return false;
|
|
495
517
|
stopEditing();
|
|
496
518
|
return true;
|
|
497
519
|
},
|
|
498
520
|
stopEditing,
|
|
499
|
-
item.body,
|
|
521
|
+
{ initial: item.body, kind: item.replyTo ? undefined : (item.kind ?? null) },
|
|
500
522
|
);
|
|
501
523
|
}
|
|
502
524
|
|
|
503
525
|
// A thread whose text is gone: attach it to the passage it is about now.
|
|
504
526
|
function moveBox() {
|
|
505
|
-
if (anchored || !state.user) return [];
|
|
527
|
+
if (anchored || whole || !state.user) return [];
|
|
506
528
|
if (state.moving !== thread.id)
|
|
507
529
|
return [h('div', { class: 'annot-actions' }, h('button', { type: 'button', onclick: () => startMoving(thread.id) }, T.move))];
|
|
508
530
|
return [
|
|
@@ -519,9 +541,11 @@ async function start(root) {
|
|
|
519
541
|
h(
|
|
520
542
|
'button',
|
|
521
543
|
{ type: 'button', class: 'annot-quote-button', disabled: !anchored, onclick: () => focusThread(thread.id, true) },
|
|
522
|
-
quote(thread.target
|
|
544
|
+
quote(thread.target?.selector),
|
|
523
545
|
),
|
|
546
|
+
...(thread.kind ? [h('span', { class: `annot-kind annot-kind-${thread.kind}` }, kindLabel(thread.kind, T))] : []),
|
|
524
547
|
...(thread.resolved ? [h('span', { class: 'annot-badge' }, T.resolved)] : []),
|
|
548
|
+
...(thread.issue ? [issueLink(thread.issue)] : []),
|
|
525
549
|
...moveBox(),
|
|
526
550
|
h('div', { class: `annot-message${fresh(thread) ? ' annot-fresh' : ''}`, 'data-msg': thread.id }, meta(thread), text(thread)),
|
|
527
551
|
...repliesOf(thread.id).map((reply) =>
|
|
@@ -550,6 +574,24 @@ async function start(root) {
|
|
|
550
574
|
{ class: 'annot-actions' },
|
|
551
575
|
h('button', { type: 'button', onclick: () => openReply(null) }, T.reply),
|
|
552
576
|
h('button', { type: 'button', onclick: () => send({ action: 'resolve', id: thread.id, resolved: !thread.resolved }) }, thread.resolved ? T.reopen : T.resolve),
|
|
577
|
+
state.issues && !thread.issue && !thread.resolved
|
|
578
|
+
? h(
|
|
579
|
+
'button',
|
|
580
|
+
{
|
|
581
|
+
type: 'button',
|
|
582
|
+
onclick: async (event) => {
|
|
583
|
+
if (!confirm(T.confirmIssue)) return;
|
|
584
|
+
event.currentTarget.disabled = true;
|
|
585
|
+
if (!(await send({ action: 'issue', id: thread.id }))) return;
|
|
586
|
+
// The note is now resolved: keep it in view, with its link.
|
|
587
|
+
state.showResolved = true;
|
|
588
|
+
resolvedBox.checked = true;
|
|
589
|
+
focusThread(thread.id, false);
|
|
590
|
+
},
|
|
591
|
+
},
|
|
592
|
+
T.openIssue,
|
|
593
|
+
)
|
|
594
|
+
: null,
|
|
553
595
|
...ownActions(thread, T.confirmDelete),
|
|
554
596
|
),
|
|
555
597
|
);
|
|
@@ -566,8 +608,11 @@ async function start(root) {
|
|
|
566
608
|
freshCount.hidden = news === 0;
|
|
567
609
|
freshCount.textContent = T.freshCount.replace('{n}', String(news));
|
|
568
610
|
const parts = [];
|
|
569
|
-
if (state.user)
|
|
570
|
-
|
|
611
|
+
if (state.user) {
|
|
612
|
+
parts.push(userLine());
|
|
613
|
+
if (!state.pending && !state.moving)
|
|
614
|
+
parts.push(h('button', { type: 'button', class: 'annot-page-note', onclick: () => composePageNote() }, `+ ${T.pageNote}`));
|
|
615
|
+
} else parts.push(loginLink());
|
|
571
616
|
if (state.error) parts.push(h('p', { class: 'annot-error', role: 'alert' }, state.error));
|
|
572
617
|
if (state.pending) {
|
|
573
618
|
parts.push(
|
|
@@ -575,12 +620,12 @@ async function start(root) {
|
|
|
575
620
|
'section',
|
|
576
621
|
{ class: 'annot-new' },
|
|
577
622
|
h('strong', {}, T.newNote),
|
|
578
|
-
quote(state.pending),
|
|
623
|
+
quote(state.pending.type === 'Page' ? null : state.pending),
|
|
579
624
|
state.user
|
|
580
625
|
? editor(
|
|
581
626
|
T.placeholder,
|
|
582
|
-
async (text) => {
|
|
583
|
-
const created = await send({ action: 'create', target: state.pending, body: text });
|
|
627
|
+
async (text, kind) => {
|
|
628
|
+
const created = await send({ action: 'create', target: state.pending, body: text, ...(kind ? { kind } : {}) });
|
|
584
629
|
if (!created) return false;
|
|
585
630
|
state.pending = null;
|
|
586
631
|
focusThread(created.id, false);
|
|
@@ -590,6 +635,7 @@ async function start(root) {
|
|
|
590
635
|
state.pending = null;
|
|
591
636
|
render();
|
|
592
637
|
},
|
|
638
|
+
{ kind: null },
|
|
593
639
|
)
|
|
594
640
|
: loginLink(),
|
|
595
641
|
),
|
|
@@ -598,9 +644,12 @@ async function start(root) {
|
|
|
598
644
|
const anchored = all
|
|
599
645
|
.filter((thread) => visible(thread) && state.anchors.has(thread.id))
|
|
600
646
|
.sort((a, b) => state.anchors.get(a.id).start - state.anchors.get(b.id).start);
|
|
601
|
-
|
|
647
|
+
// Notes about the whole page come first; they have no passage to lose.
|
|
648
|
+
const whole = all.filter((thread) => visible(thread) && !thread.target?.selector);
|
|
649
|
+
const orphans = all.filter((thread) => visible(thread) && thread.target?.selector && !state.anchors.has(thread.id));
|
|
602
650
|
if (all.length === 0 && !state.pending)
|
|
603
651
|
parts.push(h('p', { class: 'annot-empty' }, T.empty, overviewUrl ? [' ', h('a', { href: overviewUrl }, T.seeAll)] : null));
|
|
652
|
+
parts.push(...whole.map((thread) => threadCard(thread, false)));
|
|
604
653
|
parts.push(...anchored.map((thread) => threadCard(thread, true)));
|
|
605
654
|
if (orphans.length) parts.push(h('h3', { class: 'annot-orphans' }, T.orphans), ...orphans.map((thread) => threadCard(thread, false)));
|
|
606
655
|
body.replaceChildren(...parts.filter(Boolean));
|
|
@@ -668,6 +717,13 @@ async function start(root) {
|
|
|
668
717
|
selectButton.style.left = `${Math.min(window.scrollX + rect.right - selectButton.offsetWidth, window.scrollX + document.documentElement.clientWidth - selectButton.offsetWidth - 8)}px`;
|
|
669
718
|
}
|
|
670
719
|
|
|
720
|
+
function composePageNote() {
|
|
721
|
+
loadMarkdown();
|
|
722
|
+
state.pending = { type: 'Page' };
|
|
723
|
+
render();
|
|
724
|
+
setOpen(true);
|
|
725
|
+
}
|
|
726
|
+
|
|
671
727
|
async function compose() {
|
|
672
728
|
if (!selected) return;
|
|
673
729
|
if (state.moving) {
|
package/src/client/i18n.js
CHANGED
|
@@ -69,6 +69,18 @@ const en = {
|
|
|
69
69
|
fresh: 'New',
|
|
70
70
|
freshCount: '{n} new',
|
|
71
71
|
mentions: 'People',
|
|
72
|
+
kind: 'Type',
|
|
73
|
+
noKind: 'No type',
|
|
74
|
+
allKinds: 'All types',
|
|
75
|
+
kindQuestion: 'Question',
|
|
76
|
+
kindIssue: 'Problem',
|
|
77
|
+
kindProposal: 'Proposal',
|
|
78
|
+
kindDecision: 'Decision',
|
|
79
|
+
wholePage: 'Whole page',
|
|
80
|
+
pageNote: 'Note on this page',
|
|
81
|
+
openIssue: 'Open issue',
|
|
82
|
+
confirmIssue: 'Open a GitHub issue with this conversation? The note will be resolved.',
|
|
83
|
+
issue: 'Issue',
|
|
72
84
|
};
|
|
73
85
|
|
|
74
86
|
const it = {
|
|
@@ -139,6 +151,18 @@ const it = {
|
|
|
139
151
|
fresh: 'Nuova',
|
|
140
152
|
freshCount: '{n} nuove',
|
|
141
153
|
mentions: 'Persone',
|
|
154
|
+
kind: 'Tipo',
|
|
155
|
+
noKind: 'Nessun tipo',
|
|
156
|
+
allKinds: 'Tutti i tipi',
|
|
157
|
+
kindQuestion: 'Domanda',
|
|
158
|
+
kindIssue: 'Problema',
|
|
159
|
+
kindProposal: 'Proposta',
|
|
160
|
+
kindDecision: 'Decisione',
|
|
161
|
+
wholePage: 'Tutta la pagina',
|
|
162
|
+
pageNote: 'Nota sulla pagina',
|
|
163
|
+
openIssue: 'Apri issue',
|
|
164
|
+
confirmIssue: 'Aprire una issue su GitHub con questa conversazione? La nota verrà risolta.',
|
|
165
|
+
issue: 'Issue',
|
|
142
166
|
};
|
|
143
167
|
|
|
144
168
|
const de = {
|
|
@@ -209,6 +233,18 @@ const de = {
|
|
|
209
233
|
fresh: 'Neu',
|
|
210
234
|
freshCount: '{n} neu',
|
|
211
235
|
mentions: 'Personen',
|
|
236
|
+
kind: 'Art',
|
|
237
|
+
noKind: 'Ohne Art',
|
|
238
|
+
allKinds: 'Alle Arten',
|
|
239
|
+
kindQuestion: 'Frage',
|
|
240
|
+
kindIssue: 'Problem',
|
|
241
|
+
kindProposal: 'Vorschlag',
|
|
242
|
+
kindDecision: 'Entscheidung',
|
|
243
|
+
wholePage: 'Ganze Seite',
|
|
244
|
+
pageNote: 'Notiz zur Seite',
|
|
245
|
+
openIssue: 'Issue öffnen',
|
|
246
|
+
confirmIssue: 'Ein GitHub-Issue mit dieser Unterhaltung öffnen? Die Notiz wird als erledigt markiert.',
|
|
247
|
+
issue: 'Issue',
|
|
212
248
|
};
|
|
213
249
|
|
|
214
250
|
const fr = {
|
|
@@ -279,6 +315,18 @@ const fr = {
|
|
|
279
315
|
fresh: 'Nouveau',
|
|
280
316
|
freshCount: '{n} nouveaux',
|
|
281
317
|
mentions: 'Personnes',
|
|
318
|
+
kind: 'Type',
|
|
319
|
+
noKind: 'Sans type',
|
|
320
|
+
allKinds: 'Tous les types',
|
|
321
|
+
kindQuestion: 'Question',
|
|
322
|
+
kindIssue: 'Problème',
|
|
323
|
+
kindProposal: 'Proposition',
|
|
324
|
+
kindDecision: 'Décision',
|
|
325
|
+
wholePage: 'Toute la page',
|
|
326
|
+
pageNote: 'Note sur la page',
|
|
327
|
+
openIssue: 'Ouvrir une issue',
|
|
328
|
+
confirmIssue: 'Ouvrir une issue GitHub avec cette conversation ? La note sera résolue.',
|
|
329
|
+
issue: 'Issue',
|
|
282
330
|
};
|
|
283
331
|
|
|
284
332
|
const es = {
|
|
@@ -349,6 +397,18 @@ const es = {
|
|
|
349
397
|
fresh: 'Nueva',
|
|
350
398
|
freshCount: '{n} nuevas',
|
|
351
399
|
mentions: 'Personas',
|
|
400
|
+
kind: 'Tipo',
|
|
401
|
+
noKind: 'Sin tipo',
|
|
402
|
+
allKinds: 'Todos los tipos',
|
|
403
|
+
kindQuestion: 'Pregunta',
|
|
404
|
+
kindIssue: 'Problema',
|
|
405
|
+
kindProposal: 'Propuesta',
|
|
406
|
+
kindDecision: 'Decisión',
|
|
407
|
+
wholePage: 'Toda la página',
|
|
408
|
+
pageNote: 'Nota sobre la página',
|
|
409
|
+
openIssue: 'Abrir issue',
|
|
410
|
+
confirmIssue: '¿Abrir una issue de GitHub con esta conversación? La nota se resolverá.',
|
|
411
|
+
issue: 'Issue',
|
|
352
412
|
};
|
|
353
413
|
|
|
354
414
|
export const builtIn = { en, it, de, fr, es };
|
package/src/client/overview.js
CHANGED
|
@@ -5,7 +5,7 @@ import { anchor, buildIndex, skipSelector } from './anchoring.js';
|
|
|
5
5
|
import { createBackend } from './backend.js';
|
|
6
6
|
import { strings } from './i18n.js';
|
|
7
7
|
import { isNew, rememberPeople, seenTimes } from './memory.js';
|
|
8
|
-
import { h, quoteText, renderMarkdown } from './shared.js';
|
|
8
|
+
import { h, kindLabel, KINDS, quoteText, renderMarkdown } from './shared.js';
|
|
9
9
|
|
|
10
10
|
const BASE = import.meta.env.BASE_URL.replace(/\/$/, '');
|
|
11
11
|
const T = strings(document.documentElement.lang, config.translations);
|
|
@@ -53,6 +53,7 @@ async function start(container) {
|
|
|
53
53
|
status: ['open', 'new', 'changed', 'resolved', 'all'].includes(params.get('status')) ? params.get('status') : 'open',
|
|
54
54
|
author: params.get('author') ?? '',
|
|
55
55
|
text: params.get('q') ?? '',
|
|
56
|
+
kind: KINDS.includes(params.get('kind')) || params.get('kind') === 'none' ? params.get('kind') : '',
|
|
56
57
|
};
|
|
57
58
|
|
|
58
59
|
const changed = new Set(); // ids of open threads whose text is gone
|
|
@@ -82,6 +83,18 @@ async function start(container) {
|
|
|
82
83
|
.sort((a, b) => a[1].localeCompare(b[1]))
|
|
83
84
|
.map(([login, name]) => h('option', { value: login, selected: state.author === login }, name)),
|
|
84
85
|
);
|
|
86
|
+
const kind = h(
|
|
87
|
+
'select',
|
|
88
|
+
{ onchange: (event) => update({ kind: event.target.value }) },
|
|
89
|
+
h('option', { value: '' }, T.allKinds),
|
|
90
|
+
[...KINDS, 'none'].map((value) =>
|
|
91
|
+
h(
|
|
92
|
+
'option',
|
|
93
|
+
{ value, selected: state.kind === value },
|
|
94
|
+
`${value === 'none' ? T.noKind : kindLabel(value, T)} (${threads.filter((entry) => (entry.thread.kind ?? 'none') === value).length})`,
|
|
95
|
+
),
|
|
96
|
+
),
|
|
97
|
+
);
|
|
85
98
|
const search = h('input', {
|
|
86
99
|
type: 'search',
|
|
87
100
|
value: state.text,
|
|
@@ -96,6 +109,7 @@ async function start(container) {
|
|
|
96
109
|
{ class: 'annot-overview-filters not-content' },
|
|
97
110
|
h('label', {}, T.showing, status),
|
|
98
111
|
h('label', {}, T.author, author),
|
|
112
|
+
h('label', {}, T.kind, kind),
|
|
99
113
|
search,
|
|
100
114
|
),
|
|
101
115
|
list,
|
|
@@ -106,6 +120,7 @@ async function start(container) {
|
|
|
106
120
|
const query = new URLSearchParams();
|
|
107
121
|
if (state.status !== 'open') query.set('status', state.status);
|
|
108
122
|
if (state.author) query.set('author', state.author);
|
|
123
|
+
if (state.kind) query.set('kind', state.kind);
|
|
109
124
|
if (state.text) query.set('q', state.text);
|
|
110
125
|
const qs = String(query);
|
|
111
126
|
history.replaceState(null, '', `${location.pathname}${qs ? `?${qs}` : ''}`);
|
|
@@ -118,10 +133,12 @@ async function start(container) {
|
|
|
118
133
|
if (state.status === 'resolved' && !thread.resolved) return false;
|
|
119
134
|
if (state.status === 'changed' && (thread.resolved || !changed.has(thread.id))) return false;
|
|
120
135
|
const messages = [thread, ...replies];
|
|
136
|
+
if (state.kind && (thread.kind ?? 'none') !== state.kind) return false;
|
|
121
137
|
if (state.author && !messages.some((item) => item.author.login === state.author)) return false;
|
|
122
138
|
const text = state.text.trim().toLowerCase();
|
|
123
139
|
if (!text) return true;
|
|
124
|
-
|
|
140
|
+
const quoted = thread.target?.selector ? quoteText(thread.target.selector) : '';
|
|
141
|
+
return [quoted, ...messages.map((item) => item.body)].some((value) => value.toLowerCase().includes(text));
|
|
125
142
|
}
|
|
126
143
|
|
|
127
144
|
function card({ page, thread, replies, fresh }) {
|
|
@@ -130,7 +147,10 @@ async function start(container) {
|
|
|
130
147
|
return h(
|
|
131
148
|
'article',
|
|
132
149
|
{ class: `annot-thread annot-overview-card${thread.resolved ? ' resolved' : ''}` },
|
|
133
|
-
|
|
150
|
+
thread.target?.selector
|
|
151
|
+
? h('blockquote', { class: 'annot-quote' }, quoteText(thread.target.selector))
|
|
152
|
+
: h('div', { class: 'annot-quote annot-whole-page' }, T.wholePage),
|
|
153
|
+
thread.kind ? h('span', { class: `annot-kind annot-kind-${thread.kind}` }, kindLabel(thread.kind, T)) : null,
|
|
134
154
|
h(
|
|
135
155
|
'div',
|
|
136
156
|
{ class: 'annot-meta' },
|
|
@@ -138,6 +158,9 @@ async function start(container) {
|
|
|
138
158
|
' · ',
|
|
139
159
|
when,
|
|
140
160
|
thread.resolved ? h('span', { class: 'annot-badge' }, T.resolved) : null,
|
|
161
|
+
thread.issue
|
|
162
|
+
? h('a', { class: 'annot-issue', href: thread.issue.url, target: '_blank', rel: 'noopener noreferrer' }, `${T.issue} #${thread.issue.number} ↗`)
|
|
163
|
+
: null,
|
|
141
164
|
fresh ? h('span', { class: 'annot-badge annot-fresh-label' }, T.fresh) : null,
|
|
142
165
|
!thread.resolved && changed.has(thread.id) ? h('span', { class: 'annot-badge annot-changed' }, T.textChanged) : null,
|
|
143
166
|
),
|
|
@@ -189,7 +212,7 @@ async function start(container) {
|
|
|
189
212
|
if (!root) return; // Not a page we can read: say nothing.
|
|
190
213
|
const index = buildIndex(root, skip);
|
|
191
214
|
for (const entry of threads)
|
|
192
|
-
if (entry.page === page && !entry.thread.resolved && !anchor(index, entry.thread.target.selector)) changed.add(entry.thread.id);
|
|
215
|
+
if (entry.page === page && !entry.thread.resolved && entry.thread.target?.selector && !anchor(index, entry.thread.target.selector)) changed.add(entry.thread.id);
|
|
193
216
|
});
|
|
194
217
|
counts.changed = changed.size;
|
|
195
218
|
status.querySelector('option[value="changed"]').textContent = option('changed');
|
package/src/client/shared.js
CHANGED
|
@@ -71,3 +71,10 @@ export function quoteText(selector) {
|
|
|
71
71
|
const exact = squash(selector.exact);
|
|
72
72
|
return exact.length > 220 ? `${exact.slice(0, 130).trimEnd()} … ${exact.slice(-70).trimStart()}` : exact;
|
|
73
73
|
}
|
|
74
|
+
|
|
75
|
+
export { KINDS } from '../core.js';
|
|
76
|
+
|
|
77
|
+
// "question" -> T.kindQuestion
|
|
78
|
+
export function kindLabel(kind, T) {
|
|
79
|
+
return T[`kind${kind[0].toUpperCase()}${kind.slice(1)}`] ?? kind;
|
|
80
|
+
}
|
package/src/client/styles.css
CHANGED
|
@@ -201,6 +201,45 @@
|
|
|
201
201
|
.annot-mentions li span {
|
|
202
202
|
color: var(--sl-color-gray-3);
|
|
203
203
|
}
|
|
204
|
+
.annot-kind {
|
|
205
|
+
align-self: flex-start;
|
|
206
|
+
padding: 0 0.4rem;
|
|
207
|
+
border-radius: 0.25rem;
|
|
208
|
+
font-size: var(--sl-text-xs);
|
|
209
|
+
font-weight: 600;
|
|
210
|
+
}
|
|
211
|
+
.annot-kind-question {
|
|
212
|
+
background: var(--sl-color-blue-low);
|
|
213
|
+
color: var(--sl-color-blue-high);
|
|
214
|
+
}
|
|
215
|
+
.annot-kind-issue {
|
|
216
|
+
background: var(--sl-color-red-low);
|
|
217
|
+
color: var(--sl-color-red-high);
|
|
218
|
+
}
|
|
219
|
+
.annot-kind-proposal {
|
|
220
|
+
background: var(--sl-color-green-low);
|
|
221
|
+
color: var(--sl-color-green-high);
|
|
222
|
+
}
|
|
223
|
+
.annot-kind-decision {
|
|
224
|
+
background: var(--sl-color-purple-low);
|
|
225
|
+
color: var(--sl-color-purple-high);
|
|
226
|
+
}
|
|
227
|
+
.annot-whole-page {
|
|
228
|
+
border-left-style: dashed;
|
|
229
|
+
font-style: normal;
|
|
230
|
+
}
|
|
231
|
+
.annot-page-note {
|
|
232
|
+
align-self: flex-start;
|
|
233
|
+
}
|
|
234
|
+
.annot-kind-select {
|
|
235
|
+
margin-left: auto;
|
|
236
|
+
}
|
|
237
|
+
.annot-issue {
|
|
238
|
+
align-self: flex-start;
|
|
239
|
+
margin-left: 0.4rem;
|
|
240
|
+
font-size: var(--sl-text-xs);
|
|
241
|
+
font-weight: 600;
|
|
242
|
+
}
|
|
204
243
|
.annot-badge.annot-changed {
|
|
205
244
|
margin-left: 0.4rem;
|
|
206
245
|
background: var(--sl-color-orange-low);
|
package/src/core.js
CHANGED
|
@@ -15,6 +15,9 @@ const MAX_EXACT = 2000;
|
|
|
15
15
|
const MAX_EDGE = 200;
|
|
16
16
|
const MAX_CONTEXT = 64;
|
|
17
17
|
|
|
18
|
+
// What a thread is, when its writer says: shown as a label, used as a filter.
|
|
19
|
+
export const KINDS = ['question', 'issue', 'proposal', 'decision'];
|
|
20
|
+
|
|
18
21
|
export class AnnotationError extends Error {
|
|
19
22
|
constructor(status, message) {
|
|
20
23
|
super(message);
|
|
@@ -102,12 +105,27 @@ function selector(target) {
|
|
|
102
105
|
};
|
|
103
106
|
}
|
|
104
107
|
|
|
108
|
+
// A thread is about a passage (a selector), or about the whole page:
|
|
109
|
+
// `target: { type: 'Page' }` in the change, stored as a target without a
|
|
110
|
+
// selector.
|
|
111
|
+
function targetOf(target) {
|
|
112
|
+
return target?.type === 'Page' ? {} : { selector: selector(target) };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function kindOf(value) {
|
|
116
|
+
if (value === undefined || value === null || value === '') return undefined;
|
|
117
|
+
if (!KINDS.includes(value)) throw new AnnotationError(400, 'Unknown kind.');
|
|
118
|
+
return value;
|
|
119
|
+
}
|
|
120
|
+
|
|
105
121
|
// A change is one of:
|
|
106
|
-
// { action: 'create', target: { exact, prefix, suffix }, body }
|
|
122
|
+
// { action: 'create', target: { exact, prefix, suffix } | { type: 'Page' }, body, kind? }
|
|
107
123
|
// { action: 'reply', replyTo, body }
|
|
108
124
|
// { action: 'resolve', id, resolved }
|
|
109
|
-
// { action: 'edit', id, body }
|
|
125
|
+
// { action: 'edit', id, body, kind? } the author changes their message
|
|
110
126
|
// { action: 'anchor', id, target } a thread moves to another passage
|
|
127
|
+
// { action: 'issue', id, issue: { number, url } } the thread became an issue
|
|
128
|
+
// (the handler fills `issue` after creating it)
|
|
111
129
|
// { action: 'delete', id }
|
|
112
130
|
// It returns the annotation it touched, and a commit message.
|
|
113
131
|
export function applyChange(doc, change, user, now = new Date()) {
|
|
@@ -127,10 +145,12 @@ export function applyChange(doc, change, user, now = new Date()) {
|
|
|
127
145
|
id: crypto.randomUUID(),
|
|
128
146
|
created,
|
|
129
147
|
author: writer,
|
|
130
|
-
target:
|
|
148
|
+
target: targetOf(change.target),
|
|
131
149
|
body: text(change.body, MAX_BODY, 'note'),
|
|
132
150
|
resolved: false,
|
|
133
151
|
};
|
|
152
|
+
const kind = kindOf(change.kind);
|
|
153
|
+
if (kind) annotation.kind = kind;
|
|
134
154
|
doc.annotations.push(annotation);
|
|
135
155
|
return { annotation, message: `docs(annotations): note on ${doc.page}` };
|
|
136
156
|
}
|
|
@@ -161,6 +181,12 @@ export function applyChange(doc, change, user, now = new Date()) {
|
|
|
161
181
|
const annotation = find(change.id);
|
|
162
182
|
if (annotation.author?.login !== user.login) throw new AnnotationError(403, 'Only the author can edit a note.');
|
|
163
183
|
annotation.body = text(change.body, MAX_BODY, annotation.replyTo ? 'reply' : 'note');
|
|
184
|
+
// A thread's kind changes with it; leaving `kind` out keeps it.
|
|
185
|
+
if (!annotation.replyTo && 'kind' in change) {
|
|
186
|
+
const kind = kindOf(change.kind);
|
|
187
|
+
if (kind) annotation.kind = kind;
|
|
188
|
+
else delete annotation.kind;
|
|
189
|
+
}
|
|
164
190
|
annotation.edited = created;
|
|
165
191
|
return { annotation, message: `docs(annotations): edit note on ${doc.page}` };
|
|
166
192
|
}
|
|
@@ -169,11 +195,24 @@ export function applyChange(doc, change, user, now = new Date()) {
|
|
|
169
195
|
// attaches the thread to the passage it is now about.
|
|
170
196
|
const annotation = find(change.id);
|
|
171
197
|
if (annotation.replyTo) throw new AnnotationError(400, 'Only a thread can be moved.');
|
|
172
|
-
annotation.target =
|
|
198
|
+
annotation.target = targetOf(change.target);
|
|
173
199
|
annotation.movedBy = author;
|
|
174
200
|
annotation.movedAt = created;
|
|
175
201
|
return { annotation, message: `docs(annotations): move note on ${doc.page}` };
|
|
176
202
|
}
|
|
203
|
+
case 'issue': {
|
|
204
|
+
const annotation = find(change.id);
|
|
205
|
+
if (annotation.replyTo) throw new AnnotationError(400, 'Only a thread can become an issue.');
|
|
206
|
+
if (annotation.issue) throw new AnnotationError(409, 'This note already has an issue.');
|
|
207
|
+
const { number, url } = change.issue ?? {};
|
|
208
|
+
if (!Number.isInteger(number) || number < 1 || !/^https:\/\//.test(String(url))) throw new AnnotationError(400, 'Invalid issue.');
|
|
209
|
+
annotation.issue = { number, url };
|
|
210
|
+
// The conversation goes on in the issue: the note is done.
|
|
211
|
+
annotation.resolved = true;
|
|
212
|
+
annotation.resolvedBy = author;
|
|
213
|
+
annotation.resolvedAt = created;
|
|
214
|
+
return { annotation, message: `docs(annotations): open issue #${number} for a note on ${doc.page}` };
|
|
215
|
+
}
|
|
177
216
|
case 'delete': {
|
|
178
217
|
const annotation = find(change.id);
|
|
179
218
|
if (annotation.author?.login !== user.login) throw new AnnotationError(403, 'Only the author can delete a note.');
|
package/src/server/github.js
CHANGED
|
@@ -13,9 +13,10 @@
|
|
|
13
13
|
// Server credentials: a token, or `app` ({ appId, privateKey }) for a GitHub
|
|
14
14
|
// App installed on `repo` (see github-app.js).
|
|
15
15
|
|
|
16
|
-
import { filePath, pageFromPath } from '../core.js';
|
|
16
|
+
import { AnnotationError, filePath, pageFromPath } from '../core.js';
|
|
17
17
|
import { githubAppToken } from './github-app.js';
|
|
18
18
|
import { gitStorage } from './git-storage.js';
|
|
19
|
+
import { issueContent } from './issue.js';
|
|
19
20
|
import { oauthAuth } from './oauth.js';
|
|
20
21
|
import { decodeText, encodeText, required, restClient } from './util.js';
|
|
21
22
|
|
|
@@ -45,17 +46,20 @@ function serverToken({ repo, token, app }, where) {
|
|
|
45
46
|
*/
|
|
46
47
|
export function github(options) {
|
|
47
48
|
const token = options.token || options.app ? serverToken(options, 'github') : undefined;
|
|
48
|
-
|
|
49
|
+
// Issues in another repository need an installation token for that one.
|
|
50
|
+
const elsewhere = options.app && options.issues?.repo && options.issues.repo !== options.repo;
|
|
51
|
+
const issues = elsewhere ? { ...options.issues, token: githubAppToken({ ...options.app, repo: options.issues.repo }) } : options.issues;
|
|
52
|
+
const shared = { ...options, token, app: undefined, issues };
|
|
49
53
|
return { storage: githubStorage(shared), auth: githubAuth(shared) };
|
|
50
54
|
}
|
|
51
55
|
|
|
52
56
|
/** @param {import('../../server').GitHubStorageOptions} options */
|
|
53
|
-
export function githubStorage({ repo, token, app, branch = 'annotations', dir = 'annotations', commitMessage }) {
|
|
57
|
+
export function githubStorage({ repo, token, app, branch = 'annotations', dir = 'annotations', commitMessage, issues }) {
|
|
54
58
|
required({ repo }, 'githubStorage');
|
|
55
59
|
const api = client(serverToken({ repo, token, app }, 'githubStorage'));
|
|
56
60
|
const contentsPath = (page) => `/repos/${repo}/contents/${filePath(page, dir).split('/').map(encodeURIComponent).join('/')}`;
|
|
57
61
|
|
|
58
|
-
|
|
62
|
+
const storage = gitStorage({
|
|
59
63
|
mode: 'github',
|
|
60
64
|
commitMessage,
|
|
61
65
|
|
|
@@ -102,6 +106,31 @@ export function githubStorage({ repo, token, app, branch = 'annotations', dir =
|
|
|
102
106
|
if (!response.ok && response.status !== 422) throw new Error(`GitHub create branch ${response.status}: ${await response.text()}`);
|
|
103
107
|
},
|
|
104
108
|
});
|
|
109
|
+
|
|
110
|
+
// With `issues`, a thread can become a GitHub issue, in `repo` or in
|
|
111
|
+
// `issues.repo`. The server credential opens it: a GitHub App needs the
|
|
112
|
+
// repository permission "Issues: Read and write".
|
|
113
|
+
if (issues) {
|
|
114
|
+
const issueRepo = issues === true ? repo : issues.repo || repo;
|
|
115
|
+
const issueApi = issueRepo === repo ? api : client(issues.token ?? serverToken({ repo: issueRepo, token, app }, 'githubStorage issues'));
|
|
116
|
+
storage.createIssue = async (input) => {
|
|
117
|
+
const { title, body, labels } = issueContent({ ...input, profile: (login) => `https://github.com/${encodeURIComponent(login)}` });
|
|
118
|
+
const open = (withLabels) =>
|
|
119
|
+
issueApi.raw(`/repos/${issueRepo}/issues`, { method: 'POST', body: JSON.stringify({ title, body, ...(withLabels.length ? { labels: withLabels } : {}) }) });
|
|
120
|
+
let response = await open(labels);
|
|
121
|
+
// Labels the token may not create: open the issue without them.
|
|
122
|
+
if (response.status === 422 && labels.length) response = await open([]);
|
|
123
|
+
if (!response.ok) {
|
|
124
|
+
const detail = await response.text();
|
|
125
|
+
if (response.status === 403 || response.status === 404 || response.status === 410)
|
|
126
|
+
throw new AnnotationError(502, `Could not open an issue on ${issueRepo}: issues may be turned off there, or the server credential cannot write issues.`);
|
|
127
|
+
throw new Error(`GitHub create issue ${response.status}: ${detail}`);
|
|
128
|
+
}
|
|
129
|
+
const issue = await response.json();
|
|
130
|
+
return { number: issue.number, url: issue.html_url };
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
return storage;
|
|
105
134
|
}
|
|
106
135
|
|
|
107
136
|
/** @param {import('../../server').GitHubAuthOptions} options */
|
package/src/server/index.js
CHANGED
|
@@ -107,6 +107,7 @@ export function createAnnotationsHandler({ storage, auth, prefix = ROUTE_PREFIX,
|
|
|
107
107
|
user: user && { login: user.login, name: user.name },
|
|
108
108
|
mode: auth?.mode ?? storage.mode ?? 'api',
|
|
109
109
|
canSignIn: Boolean(auth?.route),
|
|
110
|
+
issues: Boolean(storage.createIssue),
|
|
110
111
|
},
|
|
111
112
|
200,
|
|
112
113
|
revoked && auth.clearSession ? { 'Set-Cookie': auth.clearSession } : {},
|
|
@@ -131,10 +132,24 @@ export function createAnnotationsHandler({ storage, auth, prefix = ROUTE_PREFIX,
|
|
|
131
132
|
const error = auth.noAccess ? auth.noAccess(user.login) : 'You may no longer annotate these docs.';
|
|
132
133
|
return json({ error, signedOut: true }, 403, auth.clearSession ? { 'Set-Cookie': auth.clearSession } : {});
|
|
133
134
|
}
|
|
134
|
-
const
|
|
135
|
+
const body = await request.json();
|
|
136
|
+
const page = checkPage(body.page);
|
|
137
|
+
let change = body.change;
|
|
138
|
+
// A thread becomes an issue: open it first, then record it on the note.
|
|
139
|
+
if (change?.action === 'issue') {
|
|
140
|
+
if (!storage.createIssue) return json({ error: 'Issues are not turned on for these notes.' }, 400);
|
|
141
|
+
const doc = await storage.load(page);
|
|
142
|
+
const thread = doc.annotations.find((item) => item.id === change.id);
|
|
143
|
+
if (!thread) return json({ error: 'Annotation not found.' }, 404);
|
|
144
|
+
if (thread.replyTo) return json({ error: 'Only a thread can become an issue.' }, 400);
|
|
145
|
+
if (thread.issue) return json({ error: 'This note already has an issue.' }, 409);
|
|
146
|
+
const replies = doc.annotations.filter((item) => item.replyTo === thread.id);
|
|
147
|
+
const issue = await storage.createIssue({ page, thread, replies, url: linkTo(page, request, url, thread.id), user });
|
|
148
|
+
change = { action: 'issue', id: thread.id, issue };
|
|
149
|
+
}
|
|
135
150
|
// With `emails`, new notes carry the writer's email, sealed.
|
|
136
151
|
const writer = auth?.sealContact && user.email ? { ...user, contact: await auth.sealContact(user.email) } : user;
|
|
137
|
-
const saved = await storage.update(
|
|
152
|
+
const saved = await storage.update(page, (doc) => applyChange(doc, change, writer), writer);
|
|
138
153
|
const result = { ...saved, annotation: withoutContact(saved.annotation), annotations: saved.annotations.map(withoutContact) };
|
|
139
154
|
if (listeners.length) {
|
|
140
155
|
const deleted = change.action === 'delete';
|
|
@@ -173,6 +188,7 @@ export function staticAuth(user) {
|
|
|
173
188
|
* list?(): Promise<{ page: string, annotations: object[] }[]>,
|
|
174
189
|
* update(page: string, mutate: (doc: AnnotationDocument) => { annotation: object, message: string }, user: User):
|
|
175
190
|
* Promise<{ annotation: object, annotations: object[] }>,
|
|
191
|
+
* createIssue?(input: { page: string, thread: object, replies: object[], url: string, user: User }): Promise<{ number: number, url: string }>,
|
|
176
192
|
* }} Storage
|
|
177
193
|
* @typedef {{
|
|
178
194
|
* mode?: string,
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// The issue a thread becomes: a title from its first words, the quoted
|
|
2
|
+
// passage, a link back to the note, and the whole conversation.
|
|
3
|
+
import { quoteOf } from './notify.js';
|
|
4
|
+
|
|
5
|
+
// GitHub labels for the kinds of note.
|
|
6
|
+
const LABELS = { question: 'question', issue: 'problem', proposal: 'proposal', decision: 'decision' };
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @param {{
|
|
10
|
+
* page: string,
|
|
11
|
+
* thread: Record<string, any>,
|
|
12
|
+
* replies: Record<string, any>[],
|
|
13
|
+
* url: string,
|
|
14
|
+
* user: { login: string, name?: string },
|
|
15
|
+
* profile: (login: string) => string,
|
|
16
|
+
* }} input
|
|
17
|
+
* @returns {{ title: string, body: string, labels: string[] }}
|
|
18
|
+
*/
|
|
19
|
+
export function issueContent({ page, thread, replies, url, user, profile }) {
|
|
20
|
+
// People are links to their profile, not "@login": opening an issue should
|
|
21
|
+
// not notify everyone in the thread. Mentions they wrote themselves stay.
|
|
22
|
+
const person = (who) => `[${who.name || who.login}](${profile(who.login)})`;
|
|
23
|
+
const quote = quoteOf(thread);
|
|
24
|
+
const message = (item) => `**${person(item.author)}** · ${when(item.created)}${item.edited ? ' (edited)' : ''}\n\n${item.body}`;
|
|
25
|
+
const body = [
|
|
26
|
+
quote ? quote.split('\n').map((line) => `> ${line}`).join('\n') : '**Whole page**',
|
|
27
|
+
`[Open the note on ${page}](${url})`,
|
|
28
|
+
...[thread, ...replies].map(message),
|
|
29
|
+
`<sub>Opened by ${person(user)} from the review notes.</sub>`,
|
|
30
|
+
].join('\n\n---\n\n');
|
|
31
|
+
return {
|
|
32
|
+
title: titleOf(thread.body) || `Note on ${page}`,
|
|
33
|
+
body,
|
|
34
|
+
labels: thread.kind && LABELS[thread.kind] ? [LABELS[thread.kind]] : [],
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// The first line of a Markdown message, as plain text, cut at a word.
|
|
39
|
+
function titleOf(markdown) {
|
|
40
|
+
const line =
|
|
41
|
+
String(markdown ?? '')
|
|
42
|
+
.replace(/```[\s\S]*?```/g, ' ')
|
|
43
|
+
.split('\n')
|
|
44
|
+
.map((value) => value.trim())
|
|
45
|
+
.find(Boolean) ?? '';
|
|
46
|
+
const plain = line
|
|
47
|
+
.replace(/!?\[([^\]]*)\]\([^)]*\)/g, '$1')
|
|
48
|
+
.replace(/^[>#\-*+\s]+|^\d+\.\s+/g, '')
|
|
49
|
+
.replace(/[*_~`]/g, '')
|
|
50
|
+
.trim();
|
|
51
|
+
if (plain.length <= 80) return plain;
|
|
52
|
+
const cut = plain.slice(0, 80);
|
|
53
|
+
return `${cut.slice(0, cut.lastIndexOf(' ') > 40 ? cut.lastIndexOf(' ') : 80).trimEnd()}…`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// "2026-11-24T10:05:00Z" -> "2026-11-24 10:05 UTC"
|
|
57
|
+
function when(iso) {
|
|
58
|
+
return `${String(iso).slice(0, 10)} ${String(iso).slice(11, 16)} UTC`;
|
|
59
|
+
}
|
package/src/server/notify.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// let you reach people too, with your own login -> address map.
|
|
9
9
|
|
|
10
10
|
// What the Slack and Teams senders post by default: not edits and moves.
|
|
11
|
-
const ACTIONS = ['create', 'reply', 'resolve', 'reopen', 'delete'];
|
|
11
|
+
const ACTIONS = ['create', 'reply', 'resolve', 'reopen', 'issue', 'delete'];
|
|
12
12
|
|
|
13
13
|
// "@ada" and "@ada-l" in a message, not inside an email address or code span.
|
|
14
14
|
const MENTION = /(?<![\w`.@/])@([a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38})(?![\w-])/gi;
|
|
@@ -57,13 +57,16 @@ export function quoteOf(thread) {
|
|
|
57
57
|
*/
|
|
58
58
|
export function describeChange(event) {
|
|
59
59
|
const who = event.user.name;
|
|
60
|
+
// "Ada added a question on …" when the note has a kind.
|
|
61
|
+
const what = { question: 'a question', issue: 'a problem', proposal: 'a proposal', decision: 'a decision' }[event.annotation?.kind] ?? 'a note';
|
|
60
62
|
const title = {
|
|
61
|
-
create: `${who} added
|
|
63
|
+
create: `${who} added ${what} on ${event.page}`,
|
|
62
64
|
reply: `${who} replied on ${event.page}`,
|
|
63
65
|
resolve: `${who} resolved a note on ${event.page}`,
|
|
64
66
|
reopen: `${who} reopened a note on ${event.page}`,
|
|
65
67
|
edit: `${who} edited a note on ${event.page}`,
|
|
66
68
|
anchor: `${who} moved a note on ${event.page}`,
|
|
69
|
+
issue: `${who} opened issue #${event.annotation?.issue?.number} for a note on ${event.page}`,
|
|
67
70
|
delete: `${who} deleted a note on ${event.page}`,
|
|
68
71
|
}[event.action];
|
|
69
72
|
const quote = quoteOf(event.thread);
|