cornfield 0.52.1 → 0.54.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/core/mentions.js +23 -0
- package/core/strings.js +2 -0
- package/explorer/css/node-panel.css +3 -1
- package/explorer/decision-model.js +2 -0
- package/explorer/engine/map-rect.js +8 -6
- package/explorer/engine/player.js +17 -11
- package/explorer/engine/sheets.js +8 -0
- package/explorer/instance.js +9 -1
- package/explorer/pieces/around.js +33 -4
- package/explorer/pieces/changes.js +32 -26
- package/explorer/pieces/decision.js +15 -8
- package/explorer/pieces/layers.js +1 -0
- package/explorer/pieces/map.js +6 -1
- package/explorer/pieces/proposal.js +41 -14
- package/explorer/pieces/scope-link.js +2 -2
- package/explorer/pieces/scope-proposal.js +158 -0
- package/explorer/pieces/scope.js +64 -1
- package/package.json +1 -1
- package/server/forge-forgejo.js +6 -4
- package/server/forge-github.js +5 -4
- package/server/forge-routes.js +18 -3
- package/server/forge.js +12 -7
- package/server/proposal-pulls.js +11 -3
- package/server/server.js +1 -1
- package/server/work-graph.js +506 -0
|
@@ -13,8 +13,10 @@
|
|
|
13
13
|
*
|
|
14
14
|
* @param {ParentNode} root where the elements go when `options.slots` names no place
|
|
15
15
|
* @param {ReturnType<typeof import('../instance.js').createInstance>} inst the instance; its map must be made (engine/render.js)
|
|
16
|
-
* @param {{ slots?: { bar?: Node, menu?: Node }, edit?: boolean }} [options] `edit: false` leaves out the what-if editor's two buttons (My edits, Edit):
|
|
17
|
-
* a host without the editor has nothing to put behind them
|
|
16
|
+
* @param {{ slots?: { bar?: Node, menu?: Node }, edit?: boolean, inline?: boolean }} [options] `edit: false` leaves out the what-if editor's two buttons (My edits, Edit):
|
|
17
|
+
* a host without the editor has nothing to put behind them. `inline` is the piece in a box of its own, in a root of its own (`<corn-proposal>`, pieces/around.js): the
|
|
18
|
+
* bar is a block that fills the box, not a panel over the map: no phone sheet, no Proposals menu, no what-if buttons, its keys and clicks are its own root's, and the picking of an
|
|
19
|
+
* edge on the map is the scope's (pieces/scope-proposal.js), whose proposal this is
|
|
18
20
|
* @returns {{ update: (props?: { proposal?: string | object | null, source?: string | null, view?: string, slug?: string | null, sha256?: string | null }) => Promise<boolean> | void, destroy: () => void, elements: Element[], renderBar: Function, paintWaitingLine: Function, toggleMenu: Function, closeMenu: Function }}
|
|
19
21
|
* `update({ proposal })` opens a proposal: a slug (fetched through `inst.fetch`, with `source` to name the copy), or the proposal itself (nothing is fetched:
|
|
20
22
|
* `slug`, `source` and `sha256` name it); `null` closes it. `update({ view })` switches Before, Diff or After. `update()` draws the bar again.
|
|
@@ -122,11 +124,14 @@ export function proposalRowHtml(entry, current) {
|
|
|
122
124
|
export function mount(root, inst, options = {}) {
|
|
123
125
|
const { state } = inst;
|
|
124
126
|
const scope = scopeOf(inst);
|
|
125
|
-
const
|
|
127
|
+
const inline = !!options.inline;
|
|
128
|
+
const html = markup({ edit: options.edit !== false && !inline });
|
|
126
129
|
const made = [
|
|
127
130
|
...place(inst, root, html.bar, options.slots, 'bar'),
|
|
128
|
-
...place(inst, root, html.menu, options.slots, 'menu'),
|
|
131
|
+
...(inline ? [] : place(inst, root, html.menu, options.slots, 'menu')),
|
|
129
132
|
];
|
|
133
|
+
/** What hears the clicks and keys of this piece: the instance's root, which holds the Work panel's Specs list too (cornfield's page), or the box's own root */
|
|
134
|
+
const hear = inline ? root : inst.root;
|
|
130
135
|
/** An element of this piece by id (the piece's own, whatever else the root holds) */
|
|
131
136
|
const own = (id) => {
|
|
132
137
|
for (const el of made) {
|
|
@@ -203,7 +208,7 @@ export function mount(root, inst, options = {}) {
|
|
|
203
208
|
// ---------------------------------------------------------------------------
|
|
204
209
|
function renderBar({ open = !!state.proposal } = {}) {
|
|
205
210
|
bar.hidden = !open;
|
|
206
|
-
if (!open) { closeMore(); toggleMode(false); collapseSheet(inst, 'proposal'); return; }
|
|
211
|
+
if (!open) { closeMore(); toggleMode(false); if (!inline) collapseSheet(inst, 'proposal'); return; }
|
|
207
212
|
|
|
208
213
|
bar.classList.remove('is-error');
|
|
209
214
|
own('proposal-message').hidden = true;
|
|
@@ -336,12 +341,15 @@ export function mount(root, inst, options = {}) {
|
|
|
336
341
|
const menuOpen = () => { const menu = own('proposal-menu'); return !!menu && !menu.hidden; };
|
|
337
342
|
|
|
338
343
|
function closeMenu() {
|
|
339
|
-
own('proposal-menu')
|
|
344
|
+
const menu = own('proposal-menu');
|
|
345
|
+
if (!menu) return; // a bar in a box of its own has no Proposals menu
|
|
346
|
+
menu.hidden = true;
|
|
340
347
|
own('proposal-btn').setAttribute('aria-expanded', 'false');
|
|
341
348
|
}
|
|
342
349
|
|
|
343
350
|
async function toggleMenu() {
|
|
344
351
|
const menu = own('proposal-menu');
|
|
352
|
+
if (!menu) return undefined;
|
|
345
353
|
if (menuOpen()) return closeMenu();
|
|
346
354
|
menu.hidden = false;
|
|
347
355
|
own('proposal-btn').setAttribute('aria-expanded', 'true');
|
|
@@ -351,6 +359,7 @@ export function mount(root, inst, options = {}) {
|
|
|
351
359
|
|
|
352
360
|
function renderMenu(loading = false) {
|
|
353
361
|
const menu = own('proposal-menu');
|
|
362
|
+
if (!menu) return;
|
|
354
363
|
const { entries: listing, problem: listingProblem, forgeProblem } = proposalListing(inst);
|
|
355
364
|
const current = state.proposal ? { slug: state.proposalSlug, source: state.proposalSource } : null;
|
|
356
365
|
let body;
|
|
@@ -391,7 +400,7 @@ export function mount(root, inst, options = {}) {
|
|
|
391
400
|
const ACTIONS = {
|
|
392
401
|
'toggle-proposals-menu': () => toggleMenu(),
|
|
393
402
|
'open-proposal': (el) => openProposal(inst, el.dataset.slug, el.dataset.source || null),
|
|
394
|
-
'close-proposal': () => closeProposal(inst),
|
|
403
|
+
'close-proposal': () => { closeProposal(inst); if (inline && state.canvas) state.canvas.focus(); }, // the bar is gone with the proposal: the focus goes to the map, never to the page
|
|
395
404
|
'proposal-whole': () => { setWholeMap(inst, !(state.review && state.review.whole)); drawBar(inst); }, // "Show the whole map": announced by engine/layers.js, the focus stays on the switch
|
|
396
405
|
'proposal-view': (el) => { setProposalView(inst, el.dataset.view); toggleMode(false); },
|
|
397
406
|
'toggle-proposal-mode': () => toggleMode(),
|
|
@@ -402,7 +411,7 @@ export function mount(root, inst, options = {}) {
|
|
|
402
411
|
};
|
|
403
412
|
|
|
404
413
|
// The root hears every control: the bar's, the menu's and a row of the Work panel's Specs list (`open-proposal`), as the document did
|
|
405
|
-
scope.listen(
|
|
414
|
+
scope.listen(hear, 'click', (e) => {
|
|
406
415
|
const target = e.target.closest ? e.target.closest('[data-action]') : null;
|
|
407
416
|
const action = target && Object.hasOwn(ACTIONS, target.dataset.action) && ACTIONS[target.dataset.action];
|
|
408
417
|
if (action) action(target);
|
|
@@ -412,6 +421,10 @@ export function mount(root, inst, options = {}) {
|
|
|
412
421
|
const wrap = own('proposal-wrap');
|
|
413
422
|
if (menuOpen() && wrap && !wrap.contains(e.target) && !(target && target.dataset.action === 'proposal-way')) closeMenu(); // (a bad link's Specs list opens it from outside)
|
|
414
423
|
});
|
|
424
|
+
// In a box of its own the root hears only the bar's clicks: a click anywhere else in the page (the map, the host's own page, another section) closes the ⋯ menu
|
|
425
|
+
// too, as it does on cornfield's page. The open menu holds the focus (on an item), and such a click takes it out of the bar: the menu closes when the focus
|
|
426
|
+
// leaves the bar (to nothing, or to anything outside it), which holds in a host's closed shadow root too and needs no listener on the page
|
|
427
|
+
if (inline) scope.listen(bar, 'focusout', (e) => { if (moreOpen() && !(e.relatedTarget && bar.contains(e.relatedTarget))) closeMore(); });
|
|
415
428
|
// Answer, on the bar's line (a run waits on this proposal): the Work panel opens on that run with its reply field focused (work:answer)
|
|
416
429
|
scope.listen(bar, 'click', (e) => {
|
|
417
430
|
const go = e.target.closest && e.target.closest('[data-waiting-answer]');
|
|
@@ -421,7 +434,7 @@ export function mount(root, inst, options = {}) {
|
|
|
421
434
|
const proposalsEntry = (workOn) => { const wrap = own('proposal-wrap'); if (wrap) wrap.hidden = !!workOn; };
|
|
422
435
|
scope.on('work:available', ({ on }) => proposalsEntry(on));
|
|
423
436
|
if (inst.ask('work:on')) proposalsEntry(true); // the Work panel started before this piece was mounted: it said so to nobody
|
|
424
|
-
scope.listen(
|
|
437
|
+
scope.listen(hear, 'keydown', (e) => {
|
|
425
438
|
if (e.key === 'Escape' && menuOpen()) closeMenu();
|
|
426
439
|
onMoreKey(e);
|
|
427
440
|
});
|
|
@@ -450,11 +463,25 @@ export function mount(root, inst, options = {}) {
|
|
|
450
463
|
scope.on('proposal:waiting', ({ run, key }) => paintWaitingLine(run, key));
|
|
451
464
|
scope.on('proposal:waiting-reset', () => { waitingSaid = null; waitingEl = null; });
|
|
452
465
|
scope.on('proposal', ({ change }) => { if (change === 'opened') closeMenu(); });
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
466
|
+
if (!inline) {
|
|
467
|
+
scope.own(bindEdgePicking(inst, (target, type, fn) => scope.listen(target, type, fn)));
|
|
468
|
+
initSheets(inst);
|
|
469
|
+
registerSheet(inst, 'proposal', bar, { stub: () => ({ title: (own('proposal-title') && own('proposal-title').textContent) || 'Proposal' }) });
|
|
470
|
+
scope.own(() => unregisterSheet(inst, 'proposal'));
|
|
471
|
+
// What the bar answers its neighbours in a box of one root: the part of the map it covers (the map frames into what is left), where the review column
|
|
472
|
+
// goes (under it, or in its body on a phone), and how far down it reaches (the column starts there)
|
|
473
|
+
scope.on('proposal:covers', () => (bar.hidden || !bar.isConnected ? undefined : { bottom: bar.getBoundingClientRect().bottom }));
|
|
474
|
+
scope.on('proposal:bar-bottom', () => (bar.hidden ? undefined : Math.round(bar.offsetTop + bar.offsetHeight + 8)));
|
|
475
|
+
scope.on('proposal:seat-column', ({ column, phone }) => {
|
|
476
|
+
const body = own('proposal-body');
|
|
477
|
+
if (phone && body) { if (column.parentElement !== body) body.appendChild(column); return true; }
|
|
478
|
+
if (bar.parentElement && column.parentElement !== bar.parentElement) bar.after(column);
|
|
479
|
+
return true;
|
|
480
|
+
});
|
|
481
|
+
const RO = inst.win && inst.win.ResizeObserver;
|
|
482
|
+
if (typeof RO === 'function') { const ro = new RO(() => inst.emit('proposal:bar-resize')); ro.observe(bar); scope.own(() => ro.disconnect()); }
|
|
483
|
+
}
|
|
484
|
+
scope.on('popup:open', () => (moreOpen() ? true : undefined)); // the player's Escape leaves a menu that has its own
|
|
458
485
|
|
|
459
486
|
scope.own(() => {
|
|
460
487
|
gone = true;
|
|
@@ -7,14 +7,14 @@
|
|
|
7
7
|
* `<corn-scope>`, or the first time a map has a `src` (pieces/map.js imports them then, as a chunk of the package's own).
|
|
8
8
|
*
|
|
9
9
|
* const join = joinScope(el, onChange) -> { inst, scope, leave } (a piece's shell calls it for the scope around it, if any)
|
|
10
|
-
* scopeInfo(inst) -> { theme, serverTheme, host, source, mountStatus } for a scope's instance, else null
|
|
10
|
+
* scopeInfo(inst) -> { theme, serverTheme, host, source, mountStatus, signIn } for a scope's instance, else null (`signIn()`: the server's sign-in, back to the page)
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
export const REQUEST = 'corn-scope-request';
|
|
14
14
|
export const CHANGED = 'corn-scope-changed';
|
|
15
15
|
|
|
16
16
|
/** What a piece may ask a scope for, per instance: set when a scope makes the instance */
|
|
17
|
-
export const infoOf = (inst) => inst.slot('scope', () => ({ theme: 'auto', serverTheme: null, host: null, source: null, mountStatus: null }));
|
|
17
|
+
export const infoOf = (inst) => inst.slot('scope', () => ({ theme: 'auto', serverTheme: null, host: null, source: null, mountStatus: null, signIn: () => '' }));
|
|
18
18
|
/**
|
|
19
19
|
* The scope's side of an instance, or null for a private one: its `theme`, its server theme (to adopt into a root), its element, its source (the
|
|
20
20
|
* load: engine/source.js) and how a piece shows the load's states (pieces/status.js `mount`)
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/pieces/scope-proposal
|
|
3
|
+
*
|
|
4
|
+
* The proposal a `<corn-scope>` holds for every piece in it (spec 0011 D4, D5, D6): the sketch puts `proposal` (and `source` and `view`) on the scope, so
|
|
5
|
+
* the review's sections (`<corn-proposal>`, `<corn-changes>`, `<corn-decision>`) and the map beside them follow one proposal. This is the same opening
|
|
6
|
+
* `corn-review` does in its one root (pieces/review.js `applyProposal`), on the scope's instance and with no piece of its own: it asks the engine
|
|
7
|
+
* (engine/proposal.js: `GET /proposals/<name>.json` through `credentialed`, so the session goes only to the server's own origin), and the pieces that
|
|
8
|
+
* are there draw what the instance says (`proposal:draw`, `proposal:bar`). It is a chunk of its own, loaded the first time a scope has a proposal:
|
|
9
|
+
* a scope or a map that never has one does not carry it.
|
|
10
|
+
*
|
|
11
|
+
* const held = holdProposal(inst, options) -> { update, sync, destroy }
|
|
12
|
+
*
|
|
13
|
+
* Options (and what `update(next)` takes, only the keys present):
|
|
14
|
+
* proposal a name (read from the server), the proposal object (shown for reading: a decision needs the name), or null: closes it. Held while
|
|
15
|
+
* there is no map with nodes to lay it over, and opened when there is (a map that comes later, or is put back: `map:ready`, `map:topology`)
|
|
16
|
+
* source which copy of it: `checkout`, `pull/31`, a worktree; none: the server answers with the first it lists
|
|
17
|
+
* view `before`, `diff` or `after`
|
|
18
|
+
* blocked the scope's `src` is not an address: a name is asked of nobody (the scope says so)
|
|
19
|
+
* pageUrl () => the page's address, for the sign-in's way back
|
|
20
|
+
* onNavigate ({ proposal, source, view, change }) the open proposal or its view changed: what cornfield's own page puts in its address bar (the host decides what
|
|
21
|
+
* to do with it); `change`: 'opened' | 'view' | 'closed'. Said once, whoever changed it: a host's property, a button on the bar, a way on from a bad link
|
|
22
|
+
* onDecision ({ outcome, proposal, source, open, review }) the server took a review; once, after its answer, whichever `<corn-decision>` was pressed
|
|
23
|
+
* onAuth ({ status, signIn, during }) a read or a press was refused for want of a sign-in (`during`: 'proposal', 'facts', 'review', 'send', 'landing')
|
|
24
|
+
* onError ({ kind: 'proposal', message }) the proposal asked for did not open
|
|
25
|
+
*
|
|
26
|
+
* What it does for the pieces besides opening: it answers `proposal:specs-list` (there is no list of specs to open in another app's page), and it hears a click on an edge of the map (engine/proposal.js
|
|
27
|
+
* `bindEdgePicking`, on the map's canvas) so that a marked edge opens in the node panel whether or not a `<corn-proposal>` is there. It reads no address and
|
|
28
|
+
* writes none.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import { openProposal, showProposal, closeProposal, setProposalView, rebuildProposalMap, bindEdgePicking, setMessage } from '../engine/proposal.js';
|
|
32
|
+
import { scopeOf } from '../engine/piece.js';
|
|
33
|
+
import { signInUrl } from '../engine/source-address.js';
|
|
34
|
+
import { PROPOSAL_VIEWS, isProposalName, notANameWords } from '../proposal-model.js';
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @param {ReturnType<typeof import('../instance.js').createInstance>} inst the scope's instance
|
|
38
|
+
* @param {object} [options] see the top of this file
|
|
39
|
+
*/
|
|
40
|
+
export function holdProposal(inst, options = {}) {
|
|
41
|
+
const { state } = inst;
|
|
42
|
+
const scope = scopeOf(inst);
|
|
43
|
+
let ended = false;
|
|
44
|
+
/** What the host asked for; `shown` is the key of the proposal this has opened (or is opening), so a repeat of the same ask opens nothing again */
|
|
45
|
+
const current = { proposal: null, source: null, view: null, shown: null };
|
|
46
|
+
const hasMap = () => !!inst.map && state.nodes.length > 0;
|
|
47
|
+
const blocked = !!options.blocked;
|
|
48
|
+
/** No server to ask (no `src`): a name is never asked of the page's own origin in its place, as the review's is not */
|
|
49
|
+
const serverless = () => !inst.base;
|
|
50
|
+
|
|
51
|
+
/** Opens, shows or closes what the host asked for, once there is a map to lay it over */
|
|
52
|
+
function sync() {
|
|
53
|
+
if (ended) return undefined;
|
|
54
|
+
const wanted = current.proposal;
|
|
55
|
+
if (wanted === null || wanted === undefined || wanted === '') {
|
|
56
|
+
current.shown = null;
|
|
57
|
+
if (state.proposal && inst.map) closeProposal(inst);
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
if (!hasMap()) return undefined; // a proposal is laid over a map: it opens when there is one
|
|
61
|
+
const view = current.view;
|
|
62
|
+
if (typeof wanted === 'string' && blocked) return undefined; // there is no server to ask (the scope says why)
|
|
63
|
+
if (typeof wanted === 'string' && serverless()) {
|
|
64
|
+
const key = `${wanted}\u0000${current.source || ''}`;
|
|
65
|
+
if (current.shown === key) return undefined;
|
|
66
|
+
current.shown = key;
|
|
67
|
+
const message = isProposalName(wanted) ? `${wanted} cannot be opened here: there is no cornfield server to read it from (the scope has no src).` : notANameWords(wanted);
|
|
68
|
+
setMessage(inst, message, true, []);
|
|
69
|
+
inst.emit('proposal:failed', { slug: wanted, source: current.source, status: 0, notFound: false, message });
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
if (typeof wanted === 'string') {
|
|
73
|
+
// The proposal that is open already, asked for again by its name (a host that heard `cornNavigate` and set what it said): nothing opens again
|
|
74
|
+
if (state.proposal && state.proposalSlug === wanted && (!current.source || current.source === state.proposalSource)) {
|
|
75
|
+
current.shown = `${wanted}\u0000${current.source || ''}`;
|
|
76
|
+
if (PROPOSAL_VIEWS.includes(view) && state.proposalView !== view) setProposalView(inst, view, { quiet: true });
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
const key = `${wanted}\u0000${current.source || ''}`;
|
|
80
|
+
if (current.shown === key) return undefined; // asked already: open, opening, or said why not
|
|
81
|
+
current.shown = key;
|
|
82
|
+
return openProposal(inst, wanted, current.source).then((ok) => {
|
|
83
|
+
if (ok && !ended && current.shown === key && PROPOSAL_VIEWS.includes(view) && state.proposalView !== view) setProposalView(inst, view, { quiet: true });
|
|
84
|
+
return ok;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
if (current.shown === wanted && state.proposal) return undefined;
|
|
88
|
+
current.shown = wanted;
|
|
89
|
+
const source = current.source || null;
|
|
90
|
+
showProposal(inst, wanted, { slug: null, source, pinSource: !!source, view: PROPOSAL_VIEWS.includes(view) ? view : 'diff', sha256: null });
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// -- what the pieces need of whoever holds the proposal -------------------------------------------------------------------------------
|
|
95
|
+
// (`map:set`, laying the proposal's nodes out beside the map's, is the scope's map's own answer: pieces/map.js)
|
|
96
|
+
scope.on('proposal:specs-list', () => false);
|
|
97
|
+
|
|
98
|
+
// -- the map comes, changes its data, or is put back ------------------------------------------------------------------------------------
|
|
99
|
+
let stopEdges = () => {};
|
|
100
|
+
const bindEdges = () => {
|
|
101
|
+
stopEdges();
|
|
102
|
+
stopEdges = inst.map && state.canvas ? bindEdgePicking(inst, (target, type, fn) => scope.listen(target, type, fn)) : () => {};
|
|
103
|
+
};
|
|
104
|
+
scope.own(() => stopEdges());
|
|
105
|
+
scope.on('map:ready', () => { bindEdges(); sync(); });
|
|
106
|
+
scope.on('map:canvas', bindEdges);
|
|
107
|
+
scope.on('map:gone', () => { stopEdges(); stopEdges = () => {}; });
|
|
108
|
+
scope.on('map:topology', () => {
|
|
109
|
+
// A new base map: an open proposal is laid over it again, as the review does; a proposal still waiting for a map opens
|
|
110
|
+
if (state.proposal && inst.map) rebuildProposalMap(inst, undefined, { fit: true });
|
|
111
|
+
sync();
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// -- what a host hears --------------------------------------------------------------------------------------------------------------------
|
|
115
|
+
scope.on('proposal', ({ change, slug, source, pinSource, view }) => {
|
|
116
|
+
// The reviewer's own act (the bar's Close or View, a way on from a bad link) is the host's property too: asked for again it opens nothing
|
|
117
|
+
if (change === 'closed') { current.proposal = null; current.shown = null; } else if (change === 'opened' && slug) {
|
|
118
|
+
current.proposal = slug;
|
|
119
|
+
if (pinSource) current.source = source;
|
|
120
|
+
current.shown = `${slug}\u0000${current.source || ''}`;
|
|
121
|
+
}
|
|
122
|
+
if (view) current.view = view;
|
|
123
|
+
if (options.onNavigate) options.onNavigate({ proposal: slug, source: pinSource ? source : null, view: change === 'closed' ? null : view, change });
|
|
124
|
+
});
|
|
125
|
+
const signInOf = () => (inst.base ? signInUrl(inst.base, typeof options.pageUrl === 'function' ? options.pageUrl() : '') : '');
|
|
126
|
+
/** The facts are read again every half minute: a sign-in that is still needed is said once, not every time (a press, or a decision taken, is said each time) */
|
|
127
|
+
let factsRefused = '';
|
|
128
|
+
scope.on('auth', ({ status, during }) => {
|
|
129
|
+
if (during === 'facts') { if (factsRefused === `${status}`) return; factsRefused = `${status}`; } else factsRefused = '';
|
|
130
|
+
if (options.onAuth) options.onAuth({ status, signIn: signInOf(), during });
|
|
131
|
+
});
|
|
132
|
+
scope.on('decision', ({ outcome, review, slug, source, open }) => {
|
|
133
|
+
factsRefused = '';
|
|
134
|
+
if (options.onDecision) options.onDecision({ outcome, proposal: slug, source, open, review });
|
|
135
|
+
});
|
|
136
|
+
scope.on('proposal:failed', ({ message }) => { if (options.onError) options.onError({ kind: 'proposal', message }); });
|
|
137
|
+
|
|
138
|
+
const held = {
|
|
139
|
+
/** Takes the keys that changed; returns a promise of whether the proposal opened, when a name was fetched */
|
|
140
|
+
update(next = {}) {
|
|
141
|
+
if (ended) return undefined;
|
|
142
|
+
let asked = false;
|
|
143
|
+
if ('source' in next && (next.source || null) !== current.source) { current.source = next.source || null; asked = true; }
|
|
144
|
+
if ('proposal' in next && (next.proposal ?? null) !== current.proposal) { current.proposal = next.proposal ?? null; current.shown = null; asked = true; }
|
|
145
|
+
if ('view' in next && PROPOSAL_VIEWS.includes(next.view) && next.view !== current.view) {
|
|
146
|
+
current.view = next.view;
|
|
147
|
+
if (state.proposal && !asked) setProposalView(inst, next.view, { quiet: true }); // a reviewer's own choice is the same value: nothing changes
|
|
148
|
+
}
|
|
149
|
+
return asked ? sync() : undefined;
|
|
150
|
+
},
|
|
151
|
+
sync,
|
|
152
|
+
destroy() { if (ended) return; ended = true; scope.destroy(); },
|
|
153
|
+
};
|
|
154
|
+
held.update({ proposal: options.proposal, source: options.source, view: options.view });
|
|
155
|
+
bindEdges();
|
|
156
|
+
sync();
|
|
157
|
+
return held;
|
|
158
|
+
}
|
package/explorer/pieces/scope.js
CHANGED
|
@@ -25,6 +25,12 @@
|
|
|
25
25
|
* A second map in a scope is refused (the engine holds one map per instance); when the map that has the scope leaves, the first refused map that
|
|
26
26
|
* is still in the page is told to ask again, and takes it.
|
|
27
27
|
*
|
|
28
|
+
* THE PROPOSAL. A scope with a `proposal` (a name, or the object) holds it for every piece in it, with `source` and `view` (pieces/scope-proposal.js, a chunk of its own,
|
|
29
|
+
* loaded the first time a scope has one): the map narrows to it, `<corn-proposal>`, `<corn-changes>` and `<corn-decision>` show and decide it. What the reviewer
|
|
30
|
+
* does (the bar's Close and Before, Diff or After, a way on from a bad link) is the instance's, and it is told to the host once as `onNavigate`; a decision as
|
|
31
|
+
* `onDecision`; a refused read or press as `onAuth` with `during`. The scope, not one of the sections, says them: the proposal is the scope's, whatever number of
|
|
32
|
+
* sections (none, or two) are in it, and it is the one place `cornAuth` and `cornError` already come from.
|
|
33
|
+
*
|
|
28
34
|
* It reads no `location`: the page's address is a function the shell passes in (`pageUrl`), used for the sign-in's way back and to name the
|
|
29
35
|
* origin a "not listed" message asks the server to list. It never navigates the window.
|
|
30
36
|
*/
|
|
@@ -32,6 +38,7 @@
|
|
|
32
38
|
import { createInstance } from '../instance.js';
|
|
33
39
|
import { adoptDefaultTokens } from './adopt-tokens.js';
|
|
34
40
|
import { parseSource } from '../engine/source.js';
|
|
41
|
+
import { signInUrl } from '../engine/source-address.js';
|
|
35
42
|
import { connectServer } from '../engine/server-load.js';
|
|
36
43
|
import { keepLayersIn } from '../engine/layers.js';
|
|
37
44
|
import { mount as mountStatus } from './status.js';
|
|
@@ -55,9 +62,15 @@ const THEMES = ['light', 'dark', 'auto'];
|
|
|
55
62
|
* @param {(detail: { status: number, signIn: string }) => void} [options.onAuth] the server wants a sign-in
|
|
56
63
|
* @param {(detail: { kind: 'not-listed' | 'offline' | 'server' | 'address' | 'version' | 'theme' | 'second-map', message?: string }) => void} [options.onError]
|
|
57
64
|
* @param {() => void} [options.onReady] the scope has its data (loaded, or handed in)
|
|
65
|
+
* @param {string | object | null} [options.proposal] @param {string | null} [options.source] @param {'before'|'diff'|'after'|null} [options.view] the proposal the scope holds
|
|
66
|
+
* @param {(detail: { proposal: string | null, source: string | null, view: 'before' | 'diff' | 'after' | null, change: 'opened' | 'view' | 'closed' }) => void} [options.onNavigate] the open proposal or its view changed
|
|
67
|
+
* @param {(detail: { outcome: 'approved' | 'notes', proposal: string | null, source: string | null, open: boolean, review: any }) => void} [options.onDecision] the server took a review
|
|
58
68
|
*/
|
|
59
69
|
export function mountScope(host, options = {}) {
|
|
60
|
-
const props = {
|
|
70
|
+
const props = {
|
|
71
|
+
src: options.src, theme: options.theme, useTheme: !!options.useTheme, topology: options.topology, config: options.config, strings: options.strings,
|
|
72
|
+
proposal: options.proposal ?? null, source: options.source ?? null, view: options.view ?? null,
|
|
73
|
+
};
|
|
61
74
|
const pageUrl = options.pageUrl || (() => '');
|
|
62
75
|
/** The pieces that took this scope's answer, by their element: what is told when the instance changes */
|
|
63
76
|
const handles = new Set();
|
|
@@ -68,6 +81,9 @@ export function mountScope(host, options = {}) {
|
|
|
68
81
|
let serverLink = null;
|
|
69
82
|
let readyFired = false;
|
|
70
83
|
let ended = false;
|
|
84
|
+
/** The proposal the instance holds (pieces/scope-proposal.js), once there is one to hold; null before that, and for an instance that has none */
|
|
85
|
+
let held = null;
|
|
86
|
+
let holdLoading = false;
|
|
71
87
|
|
|
72
88
|
// -- the answer to a piece ---------------------------------------------------------------------------------------------------------------
|
|
73
89
|
const answer = (event) => {
|
|
@@ -123,6 +139,7 @@ export function mountScope(host, options = {}) {
|
|
|
123
139
|
source = link.source;
|
|
124
140
|
info.source = source;
|
|
125
141
|
info.mountStatus = mountStatus;
|
|
142
|
+
info.signIn = () => (mine.base ? signInUrl(mine.base, pageUrl()) : ''); // the server's sign-in, back to this page: a section that is refused shows the card with it
|
|
126
143
|
readyFired = false;
|
|
127
144
|
// A second map waits: when the one that has the instance's root gives it back, the first that waits and is still in the page asks again
|
|
128
145
|
// (after the leaving map has finished ending, so the two never hold the instance's state at once)
|
|
@@ -143,6 +160,48 @@ export function mountScope(host, options = {}) {
|
|
|
143
160
|
if (parsed && !parsed.ok) source.say({ state: 'address', problem: parsed.problem });
|
|
144
161
|
source.provide({ topology: props.topology || undefined, config: props.config || undefined, strings: props.strings || undefined });
|
|
145
162
|
if (parsed && parsed.ok) source.load();
|
|
163
|
+
held = null;
|
|
164
|
+
holdLoading = false;
|
|
165
|
+
holdProposal();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* The proposal's keys a host changed, handed over together once its script has run: a host sets `source` and then `proposal` (or `proposal` and then `view`)
|
|
170
|
+
* one after the other, and each alone would open the wrong thing first (the old proposal under the new source: a read of a copy that does not exist, a
|
|
171
|
+
* `cornError` for it, and a line in the bar)
|
|
172
|
+
*/
|
|
173
|
+
let asking = null;
|
|
174
|
+
function askHeld(asked) {
|
|
175
|
+
if (asking) { Object.assign(asking, asked); return; }
|
|
176
|
+
asking = { ...asked };
|
|
177
|
+
queueMicrotask(() => {
|
|
178
|
+
const keys = asking;
|
|
179
|
+
asking = null;
|
|
180
|
+
if (ended) return;
|
|
181
|
+
if (held) held.update(keys); else holdProposal();
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Makes the instance hold the proposal when the scope has one (the first time: the chunk is loaded); a scope with none loads nothing */
|
|
186
|
+
function holdProposal() {
|
|
187
|
+
if (ended || held || holdLoading || props.proposal === null || props.proposal === undefined || props.proposal === '') return;
|
|
188
|
+
holdLoading = true;
|
|
189
|
+
const mine = inst;
|
|
190
|
+
const blocked = props.src !== undefined && props.src !== null && props.src !== '' && !parseSource(props.src).ok;
|
|
191
|
+
import('./scope-proposal.js').then(({ holdProposal: hold }) => {
|
|
192
|
+
holdLoading = false;
|
|
193
|
+
if (ended || inst !== mine || held) return;
|
|
194
|
+
held = hold(mine, {
|
|
195
|
+
proposal: props.proposal, source: props.source, view: props.view, blocked, pageUrl,
|
|
196
|
+
onNavigate: (detail) => { if (options.onNavigate) options.onNavigate(detail); },
|
|
197
|
+
onDecision: (detail) => { if (options.onDecision) options.onDecision(detail); },
|
|
198
|
+
onAuth: (detail) => { if (options.onAuth) options.onAuth(detail); },
|
|
199
|
+
onError: (detail) => { if (options.onError) options.onError(detail); },
|
|
200
|
+
});
|
|
201
|
+
}, (err) => {
|
|
202
|
+
holdLoading = false;
|
|
203
|
+
if (!ended && options.onError) options.onError({ kind: 'offline', message: `the scope's proposal loader did not load: ${err && err.message ? err.message : err}` });
|
|
204
|
+
});
|
|
146
205
|
}
|
|
147
206
|
|
|
148
207
|
function release() {
|
|
@@ -181,6 +240,10 @@ export function mountScope(host, options = {}) {
|
|
|
181
240
|
const hand = {};
|
|
182
241
|
for (const key of ['topology', 'config', 'strings']) if (key in next && next[key] !== props[key]) { props[key] = next[key]; hand[key] = next[key] === undefined ? null : next[key]; }
|
|
183
242
|
if (Object.keys(hand).length) source.provide(hand);
|
|
243
|
+
// The proposal: the keys that changed go to what holds it (loaded now, if this is the scope's first)
|
|
244
|
+
const asked = {};
|
|
245
|
+
for (const key of ['proposal', 'source', 'view']) if (key in next && (next[key] ?? null) !== props[key]) { props[key] = next[key] ?? null; asked[key] = props[key]; }
|
|
246
|
+
if (Object.keys(asked).length) askHeld(asked);
|
|
184
247
|
},
|
|
185
248
|
destroy() {
|
|
186
249
|
if (ended) return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cornfield",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.54.0",
|
|
4
4
|
"description": "A self-hostable dev dashboard with the topology map at its centre: proposals on the map, scenarios, outages and what-if edits, for any repo.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "popcorn245 (https://github.com/popcorn245)",
|
package/server/forge-forgejo.js
CHANGED
|
@@ -74,7 +74,7 @@ const isDraft = (p) => p.draft === true || /^\s*(\[WIP\]|WIP:|Draft:)/i.test(p.t
|
|
|
74
74
|
const toPull = (p) => ({
|
|
75
75
|
number: p.number, title: p.title, body: p.body ?? '', state: p.merged || p.merged_at ? 'merged' : p.state === 'closed' ? 'closed' : 'open', draft: isDraft(p),
|
|
76
76
|
author: author(p.user), labels: labelNames(p.labels), head: { ref: p.head?.ref ?? '', sha: p.head?.sha ?? '' }, base: { ref: p.base?.ref ?? '' },
|
|
77
|
-
url: p.html_url, createdAt: p.created_at, updatedAt: p.updated_at, mergedAt: p.merged_at ?? null,
|
|
77
|
+
url: p.html_url, createdAt: p.created_at, updatedAt: p.updated_at, mergedAt: p.merged_at ?? null, mergeSha: p.merged_at || p.merged ? p.merge_commit_sha ?? null : null, closedAt: p.closed_at ?? null,
|
|
78
78
|
});
|
|
79
79
|
|
|
80
80
|
const FILE_STATUS = { added: 'added', copied: 'added', deleted: 'removed', removed: 'removed', renamed: 'renamed', modified: 'modified', changed: 'modified', unchanged: 'modified' };
|
|
@@ -172,9 +172,10 @@ export function createForgejoForge(forge, { token = null, fetch, apiUrl, timeout
|
|
|
172
172
|
return LEVELS[body.permission] || 'none';
|
|
173
173
|
},
|
|
174
174
|
|
|
175
|
-
async issues({ state, labels, limit }) {
|
|
175
|
+
async issues({ state, labels, limit, since }) {
|
|
176
176
|
const q = new URLSearchParams({ state, type: 'issues', limit: String(PER_PAGE) });
|
|
177
177
|
if (labels.length) q.set('labels', labels.join(','));
|
|
178
|
+
if (since) q.set('since', since);
|
|
178
179
|
const all = await client.list(`repos/${repo}/issues?${q}`, { what: `the issues of ${forge.repo}`, limit, items: (b) => (Array.isArray(b) ? b.filter((i) => !i.pull_request) : b) });
|
|
179
180
|
return all.map(toIssue);
|
|
180
181
|
},
|
|
@@ -186,8 +187,9 @@ export function createForgejoForge(forge, { token = null, fetch, apiUrl, timeout
|
|
|
186
187
|
return (Array.isArray(body) ? body : []).filter((i) => !i.pull_request).map(toIssue);
|
|
187
188
|
},
|
|
188
189
|
|
|
189
|
-
async pulls({ state, limit }) {
|
|
190
|
-
|
|
190
|
+
async pulls({ state, limit, sort }) {
|
|
191
|
+
// Without `sort` the forge's own order, newest first; `recentupdate` is the most recently updated first
|
|
192
|
+
const q = new URLSearchParams({ state, ...(sort === 'updated' ? { sort: 'recentupdate' } : {}), limit: String(PER_PAGE) });
|
|
191
193
|
return (await client.list(`repos/${repo}/pulls?${q}`, { what: `the pull requests of ${forge.repo}`, limit })).map(toPull);
|
|
192
194
|
},
|
|
193
195
|
|
package/server/forge-github.js
CHANGED
|
@@ -63,7 +63,7 @@ const toIssue = (i) => ({
|
|
|
63
63
|
const toPull = (p) => ({
|
|
64
64
|
number: p.number, title: p.title, body: p.body ?? '', state: p.merged_at ? 'merged' : p.state === 'closed' ? 'closed' : 'open', draft: Boolean(p.draft),
|
|
65
65
|
author: author(p.user), labels: labelNames(p.labels), head: { ref: p.head?.ref ?? '', sha: p.head?.sha ?? '' }, base: { ref: p.base?.ref ?? '' },
|
|
66
|
-
url: p.html_url, createdAt: p.created_at, updatedAt: p.updated_at, mergedAt: p.merged_at ?? null,
|
|
66
|
+
url: p.html_url, createdAt: p.created_at, updatedAt: p.updated_at, mergedAt: p.merged_at ?? null, mergeSha: p.merged_at || p.merged ? p.merge_commit_sha ?? null : null, closedAt: p.closed_at ?? null,
|
|
67
67
|
});
|
|
68
68
|
|
|
69
69
|
/** @returns {import('./forge.js').PullCommit} */
|
|
@@ -171,8 +171,9 @@ export function createGitHubForge(forge, { token = null, fetch, apiUrl, timeoutM
|
|
|
171
171
|
return LEGACY[body.permission] || 'none';
|
|
172
172
|
},
|
|
173
173
|
|
|
174
|
-
async issues({ state, labels, limit }) {
|
|
174
|
+
async issues({ state, labels, limit, since }) {
|
|
175
175
|
const q = new URLSearchParams({ state, sort: 'created', direction: 'desc', per_page: String(PER_PAGE) });
|
|
176
|
+
if (since) q.set('since', since);
|
|
176
177
|
if (labels.length) q.set('labels', labels.join(','));
|
|
177
178
|
const all = await client.list(`repos/${repo}/issues?${q}`, { what: `the issues of ${forge.repo}`, limit, items: (b) => (Array.isArray(b) ? b.filter((i) => !i.pull_request) : b) });
|
|
178
179
|
return all.map(toIssue);
|
|
@@ -185,8 +186,8 @@ export function createGitHubForge(forge, { token = null, fetch, apiUrl, timeoutM
|
|
|
185
186
|
return (Array.isArray(body?.items) ? body.items : []).filter((i) => !i.pull_request).map(toIssue);
|
|
186
187
|
},
|
|
187
188
|
|
|
188
|
-
async pulls({ state, limit }) {
|
|
189
|
-
const q = new URLSearchParams({ state, sort
|
|
189
|
+
async pulls({ state, limit, sort = 'created' }) {
|
|
190
|
+
const q = new URLSearchParams({ state, sort, direction: 'desc', per_page: String(PER_PAGE) });
|
|
190
191
|
return (await client.list(`repos/${repo}/pulls?${q}`, { what: `the pull requests of ${forge.repo}`, limit })).map(toPull);
|
|
191
192
|
},
|
|
192
193
|
|
package/server/forge-routes.js
CHANGED
|
@@ -25,6 +25,8 @@
|
|
|
25
25
|
* GET /api/forge/threads/<n> one thread's messages, as written, to read; replying is on the forge
|
|
26
26
|
* POST /api/forge/threads { title, body }: a new idea, an issue with the label, as the maintainer (server/forge-actions.js `serveIdea`)
|
|
27
27
|
* GET /api/forge/work what the agents view groups: pull requests and issues (any state), branches, open spec PRs, and the config's `agents` rules
|
|
28
|
+
* GET /api/forge/work-graph the map of work (spec 0012): issues, PRs, proposals, threads, runs and deploys as nodes, their links to each other
|
|
29
|
+
* and to the map's code as edges, and `problems` for what could not be read (server/work-graph.js; not open to an embedding origin)
|
|
28
30
|
* GET /api/forge/deploys?limit=100 the latest workflow runs that are deploys, each with what the
|
|
29
31
|
* config says it restarted (server/deploys.js, docs/deploys.md)
|
|
30
32
|
* GET /api/forge/release-notes?since=<tag> the merged pull requests since a tag (the latest version tag unless
|
|
@@ -60,6 +62,7 @@ import { deploysOf } from './deploys.js';
|
|
|
60
62
|
import { readBody, sameOrigin } from './proposals.js';
|
|
61
63
|
import { releaseNotes } from './release-notes.js';
|
|
62
64
|
import { inside, readMap, readPlain } from './files.js';
|
|
65
|
+
import { workGraph } from './work-graph.js';
|
|
63
66
|
|
|
64
67
|
/** How long a kept answer is served without asking the forge again */
|
|
65
68
|
export const FRESH_MS = 60_000;
|
|
@@ -122,7 +125,7 @@ function notesInput(config, since) {
|
|
|
122
125
|
* The reads: the request's route, the forge call that answers it, and the key it is kept under.
|
|
123
126
|
* @returns {{ key: string, load: (forge: import('./forge.js').Forge) => Promise<object> } | null}
|
|
124
127
|
*/
|
|
125
|
-
function routeOf(reqPath, url, config, where, hooks = null) {
|
|
128
|
+
function routeOf(reqPath, url, config, where, hooks = null, extra = {}) {
|
|
126
129
|
if (reqPath === '/api/forge/release-notes') {
|
|
127
130
|
const since = sinceOf(url.searchParams.get('since'));
|
|
128
131
|
return { key: `release-notes?since=${since ?? ''}&label=${config.releaseNotes?.breakingLabel ?? ''}`, load: (forge) => releaseNotes(forge, notesInput(config, since)) };
|
|
@@ -164,6 +167,18 @@ function routeOf(reqPath, url, config, where, hooks = null) {
|
|
|
164
167
|
const n = Number(reqPath.split('/').pop());
|
|
165
168
|
return { key: `threads/${n}&label=${label}`, load: async (forge) => ({ thread: await readThread(forge, config, where || config, n) }) };
|
|
166
169
|
}
|
|
170
|
+
if (reqPath === '/api/forge/work-graph') {
|
|
171
|
+
// The config is in the key (what is a deploy, whether threads are on), so an answer kept before it changed is never served for the new one
|
|
172
|
+
const mapping = createHash('sha256').update(JSON.stringify([config.deploys || null, config.threads ?? null])).digest('hex').slice(0, 12);
|
|
173
|
+
return {
|
|
174
|
+
key: `work-graph?config=${mapping}`,
|
|
175
|
+
load: async (forge) => {
|
|
176
|
+
let map = null;
|
|
177
|
+
try { map = readMap(config); } catch { map = null; }
|
|
178
|
+
return workGraph(forge, config, map, { where: where || config, runs: extra.runs ?? null, now: extra.now });
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
}
|
|
167
182
|
if (reqPath === '/api/forge/work') {
|
|
168
183
|
return {
|
|
169
184
|
key: 'work',
|
|
@@ -258,7 +273,7 @@ async function servePlan(req, res, act, url, ctx) {
|
|
|
258
273
|
* @param {import('node:http').ServerResponse} res
|
|
259
274
|
* @param {string} reqPath the decoded path
|
|
260
275
|
* @param {URL} url
|
|
261
|
-
* @param {{ config: object, where?: { proposals: string }, hooks?: import('./hooks.js').Hooks | null, lander?: import('./lander.js').Lander | null, session: { userId: string, login: string } | null, publicHost?: string | null, publicOrigin?: string | null, auth: { store: null | (() => Promise<import('node:sqlite').DatabaseSync>), forgeFor: Function }, now?: () => number }} ctx
|
|
276
|
+
* @param {{ config: object, where?: { proposals: string }, runs?: import('./agent-runs.js').Runs | null, hooks?: import('./hooks.js').Hooks | null, lander?: import('./lander.js').Lander | null, session: { userId: string, login: string } | null, publicHost?: string | null, publicOrigin?: string | null, auth: { store: null | (() => Promise<import('node:sqlite').DatabaseSync>), forgeFor: Function }, now?: () => number }} ctx
|
|
262
277
|
* `session` is the signed-in maintainer's (null without sign-in)
|
|
263
278
|
* @returns {Promise<boolean>}
|
|
264
279
|
*/
|
|
@@ -319,7 +334,7 @@ export async function serveForge(req, res, reqPath, url, ctx) {
|
|
|
319
334
|
return true;
|
|
320
335
|
}
|
|
321
336
|
try {
|
|
322
|
-
const route = routeOf(reqPath, url, config, ctx.where, ctx.hooks);
|
|
337
|
+
const route = routeOf(reqPath, url, config, ctx.where, ctx.hooks, { runs: ctx.runs, now });
|
|
323
338
|
if (!route) {
|
|
324
339
|
send(req, res, 404, { ok: false, error: `${reqPath} is not a forge route.`, code: 'not-found' });
|
|
325
340
|
return true;
|
package/server/forge.js
CHANGED
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
* @typedef {{ id: string, login: string, name: string | null, url: string | null, avatarUrl: string | null }} User
|
|
58
58
|
* @typedef {{ login: string, url: string | null, bot?: true }} Author
|
|
59
59
|
* @typedef {{ number: number, title: string, state: 'open' | 'closed', author: Author | null, labels: string[], body: string, comments: number, url: string, createdAt: string, updatedAt: string, closedAt: string | null }} Issue
|
|
60
|
-
* @typedef {{ number: number, title: string, body: string, state: 'open' | 'closed' | 'merged', draft: boolean, author: Author | null, labels: string[], head: { ref: string, sha: string }, base: { ref: string }, url: string, createdAt: string, updatedAt: string, mergedAt: string | null }} Pull
|
|
60
|
+
* @typedef {{ number: number, title: string, body: string, state: 'open' | 'closed' | 'merged', draft: boolean, author: Author | null, labels: string[], head: { ref: string, sha: string }, base: { ref: string }, url: string, createdAt: string, updatedAt: string, mergedAt: string | null, mergeSha: string | null, closedAt: string | null }} Pull
|
|
61
61
|
* @typedef {{ path: string, status: 'added' | 'modified' | 'removed' | 'renamed', previousPath: string | null, additions: number, deletions: number }} PullFile
|
|
62
62
|
* @typedef {{ id: string, author: Author | null, body: string, url: string, createdAt: string, updatedAt: string }} Comment
|
|
63
63
|
* @typedef {{ sha: string, message: string, date: string | null }} PullCommit `date`: when it was committed (the committer's date, else the author's), or null when the forge gave none
|
|
@@ -71,8 +71,8 @@
|
|
|
71
71
|
* @typedef {{ name: string, sha: string, date: string }} TagInfo
|
|
72
72
|
* @typedef {{ tag: string, name: string, body: string }} ReleaseDraftInput
|
|
73
73
|
* @typedef {{ id: string, url: string, draft: true }} ReleaseDraft
|
|
74
|
-
* @typedef {{ state?: 'open' | 'closed' | 'all', labels?: string[], limit?: number }} IssueQuery
|
|
75
|
-
* @typedef {{ state?: 'open' | 'closed' | 'all', limit?: number }} PullQuery
|
|
74
|
+
* @typedef {{ state?: 'open' | 'closed' | 'all', labels?: string[], limit?: number, since?: string }} IssueQuery `since`: only the issues updated at or after it
|
|
75
|
+
* @typedef {{ state?: 'open' | 'closed' | 'all', limit?: number, sort?: 'created' | 'updated' }} PullQuery `sort`: newest first by when it was opened (the default) or last updated
|
|
76
76
|
* @typedef {{ limit?: number }} RunQuery
|
|
77
77
|
* @typedef {{ since: string, limit?: number }} ChangedQuery
|
|
78
78
|
* @typedef {{ number: number, pull: boolean, labels: string[], updatedAt: string }} Changed
|
|
@@ -240,15 +240,20 @@ function inRepo(ref, path) {
|
|
|
240
240
|
if (path.startsWith('/') || path.split('/').some((p) => p === '..' || p === '.' || p === '')) throw invalid(`${JSON.stringify(path)} is not a path inside the repo.`);
|
|
241
241
|
}
|
|
242
242
|
|
|
243
|
-
/** A listing's query with the defaults: open, at most `DEFAULT_LIMIT`, any label */
|
|
243
|
+
/** A listing's query with the defaults: open, at most `DEFAULT_LIMIT`, any label; an issue listing's `since` and a pull request listing's `sort` only when asked */
|
|
244
244
|
function query(q, withLabels) {
|
|
245
245
|
if (q !== undefined && (q === null || typeof q !== 'object' || Array.isArray(q))) throw invalid('A query is an object.');
|
|
246
|
-
const { state = 'open', limit = DEFAULT_LIMIT, labels = [] } = q || {};
|
|
246
|
+
const { state = 'open', limit = DEFAULT_LIMIT, labels = [], since, sort } = q || {};
|
|
247
247
|
if (!STATES.includes(state)) throw invalid(`The state is one of ${STATES.join(', ')}.`);
|
|
248
248
|
if (!Number.isSafeInteger(limit) || limit < 1) throw invalid('The limit is a whole number above 0.');
|
|
249
|
-
if (!withLabels)
|
|
249
|
+
if (!withLabels) {
|
|
250
|
+
if (sort !== undefined && sort !== 'created' && sort !== 'updated') throw invalid('The sort is created or updated.');
|
|
251
|
+
return sort === 'updated' ? { state, limit, sort } : { state, limit };
|
|
252
|
+
}
|
|
250
253
|
if (!Array.isArray(labels) || labels.some((l) => typeof l !== 'string' || l === '' || l.includes(','))) throw invalid('The labels are a list of names.');
|
|
251
|
-
return { state, limit, labels };
|
|
254
|
+
if (since === undefined) return { state, limit, labels };
|
|
255
|
+
if (typeof since !== 'string' || !ISO_TIME.test(since) || Number.isNaN(Date.parse(since))) throw invalid('since is a time like 2026-11-05T09:00:00Z.');
|
|
256
|
+
return { state, limit, labels, since: new Date(since).toISOString() };
|
|
252
257
|
}
|
|
253
258
|
|
|
254
259
|
/**
|